Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PAM service tests #22

Merged
merged 3 commits into from
Sep 5, 2023
Merged

PAM service tests #22

merged 3 commits into from
Sep 5, 2023

Conversation

denisonbarbosa
Copy link
Member

@denisonbarbosa denisonbarbosa commented Aug 22, 2023

Package tests for internal/services/pam.

UDENG-1172

@denisonbarbosa denisonbarbosa requested a review from a team as a code owner August 22, 2023 10:34
Copy link
Contributor

@GabrielNagy GabrielNagy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noticed some irregularities related to the pesky golden files, otherwise my comments are all minor :).

Very nice work and thanks for separating into individual commits!

internal/brokers/manager.go Outdated Show resolved Hide resolved
internal/brokers/broker_test.go Outdated Show resolved Hide resolved
internal/brokers/broker_test.go Outdated Show resolved Hide resolved
internal/services/pam/pam_test.go Outdated Show resolved Hide resolved
internal/services/pam/pam_test.go Outdated Show resolved Hide resolved
internal/services/pam/pam_test.go Outdated Show resolved Hide resolved
internal/services/pam/pam_test.go Outdated Show resolved Hide resolved
internal/services/pam/pam_test.go Outdated Show resolved Hide resolved
internal/services/pam/pam_test.go Outdated Show resolved Hide resolved
Copy link
Member

@didrocks didrocks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Congrats on the amount of tests and being able to still run them in parallel! This will be really helpful in the long run.
I think you can even easily aim for 100% coverage by covering the last 2 lines with a single test: passing an invalid layout capability as a request (missing "type")!

I think there is still some work to be done, in addition to quite some comments to enhance readability and maintainability. Here are three global remarks (which is repeated quite some times in this PR):

  • we are using some conventions across multiple projects (fixtures directory, "-" to signify empty string in tests, no cmd/ import in internal/). Let’s stick with those please and don’t diverge from them. This helps then having consistency and familiarity across our work.
  • my biggest issue is the cmd/ vs internal/ import. One consequence is that you then rely on the daemon to be created, with everything (manager, socket activation, and so on). You are basically building some integration tests here! The only thing you should import is internal/services/pam + everything that this one needs to be setup (apart from testutils, which is our test new requirements). This will avoid future potential loop imports and abstraction breakage.
  • Similarly, some configuration in the fixtures are too specific. From this package, as long as the configuration is invalid, it’s invalid. We don’t want to be too much into details about missing this or that field. This is the problem of the brokers package which defines what is valid or invalid. If we change the validity rules later in the brokers package, it would force us to modify a lot of fixtures here. So, you should abstrarct to a higher level to avoid those future changes.

Finally, I think this is the right place to have two more complex tests to ensure we multiplex successfully:

  • have at least 2 brokers
  • select for user1 one broker
  • select for user2 another broker
  • give each one different layout capabilities
  • ensure that each broker returns a different broker authentication mode
  • calling is Authorized and ensure that both are acting independently.

I think this test can be for each broker in its own goroutine and only synchronize in the end that both are done.
This will allow, in particular with the race detector, to ensure we don’t have anything racy.

Then, rince and repeat in a second test with this time, two different users but with the same broker!

cmd/authd/daemon/daemon.go Outdated Show resolved Hide resolved
internal/brokers/broker_test.go Outdated Show resolved Hide resolved
internal/brokers/manager.go Outdated Show resolved Hide resolved
internal/services/pam/pam_test.go Outdated Show resolved Hide resolved
internal/services/pam/pam_test.go Outdated Show resolved Hide resolved
internal/services/pam/pam_test.go Outdated Show resolved Hide resolved
internal/services/pam/pam_test.go Outdated Show resolved Hide resolved
internal/services/pam/pam_test.go Show resolved Hide resolved
internal/services/pam/pam_test.go Show resolved Hide resolved
internal/services/pam/pam_test.go Show resolved Hide resolved
@3v1n0
Copy link
Collaborator

3v1n0 commented Aug 29, 2023

Since you're making various config paths to be tunable at code level, could you also please introduce arguments (or env variables) to define them when running authd manually (ideally supporting XDG or standard env variables when possible)?

i.e. for development purposes is convenient to have the ability to define temporary paths and use them to run the daemon as user instead of having to install it. Being also an exercise for special setups :)

denisonbarbosa added a commit that referenced this pull request Sep 4, 2023
When writing the PAM service tests, some changes had to be made to
improve consistency and naming across the board. Also, since we intended
to run a single broker for the PAM tests, we also had to update the mock
creation to stop relying on testing.T.

This PR is mainly an extraction of the changes in the brokers that were
made in #22.
@denisonbarbosa denisonbarbosa force-pushed the internal-pam-tests branch 2 times, most recently from fd6b07e to 9f0af2b Compare September 4, 2023 13:22
@denisonbarbosa denisonbarbosa changed the title PAM service tests and mock + daemon updates PAM service tests Sep 4, 2023
Copy link
Member

@didrocks didrocks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is way better than the first proposal: way more readable and more inline with what we do regularly.

I have some nitpicks and a few enhancements proposal, nothing drastic and the core logic is here! Nice work :)

internal/services/pam/pam_test.go Outdated Show resolved Hide resolved
internal/services/pam/pam_test.go Outdated Show resolved Hide resolved
internal/services/pam/pam_test.go Outdated Show resolved Hide resolved
internal/services/pam/pam_test.go Outdated Show resolved Hide resolved
internal/services/pam/pam_test.go Show resolved Hide resolved
internal/services/pam/pam_test.go Outdated Show resolved Hide resolved
internal/services/pam/pam_test.go Show resolved Hide resolved
internal/services/pam/pam_test.go Outdated Show resolved Hide resolved
internal/services/pam/pam_test.go Show resolved Hide resolved
internal/services/pam/pam_test.go Show resolved Hide resolved
Copy link
Member

@didrocks didrocks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still some changes needed, but getting close.

internal/services/pam/pam_test.go Outdated Show resolved Hide resolved
internal/services/pam/pam_test.go Outdated Show resolved Hide resolved
internal/services/pam/pam_test.go Show resolved Hide resolved
internal/services/pam/pam_test.go Outdated Show resolved Hide resolved
Copy link
Member

@didrocks didrocks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the changes! Good for merging

Improved the naming on the separator const to better indicate its
purpose.
Adjusted the way we parse the sessionID to support multiple prefixes in
order to better differentiate between uses.
@denisonbarbosa denisonbarbosa merged commit 729fb0c into main Sep 5, 2023
3 checks passed
@denisonbarbosa denisonbarbosa deleted the internal-pam-tests branch September 5, 2023 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants