-
Notifications
You must be signed in to change notification settings - Fork 887
test: add full OIDC fake IDP #9317
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
Conversation
Begin work on unit testing refactor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really nice work @Emyrk ! I think this will really help us improve our confidence in our OIDC flows.
Some comments, see below:
"access_token": f.newToken(email), | ||
"refresh_token": refreshToken, | ||
"token_type": "Bearer", | ||
"expires_in": int64((time.Minute * 5).Seconds()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Follow-up: this could be a useful config knob down the line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. We can add more knobs as we make more unit tests. At the moment, the time stuff can be a bit tricky, so instead I just made that ExpireOauthToken
which just changes the expiry to the past.
It was easier than trying to sync some clock manipulation in the various places we need.
What this does
This adds the new fake OIDC provider and refactors existing tests, however we should still write more tests!
This creates a realistic IDP for OIDC testing. It handles all the endpoints expected of an IDP, and enforces the codes/states/tokens it returns. This was implemented because our OIDC logic is growing in complexity, and we need a proper IDP to run tests against. The existing mock was very relaxed, and did not support some features like refreshing.
Our old fake was lacking a few areas:
oauth2.HTTPClient
context value for proper auth in some cases (PKI)The new fake is essentially an IDP that we can continue to expand to cover more cases and more regressions.
Existing unit tests
All existing OIDC unit tests were moved to the new fake.
Future Work
More tests
We should write more tests around our oauth httpmw handler and api key extract. We can probably do it without starting a full Coderd and getting much faster tests.
I think our current tests do not test all of the possible edge cases and combinations.
Quicker Tests
The new IDP supports a complete in memory HTTP client that never makes HTTP calls. This makes things quicker and easier to debug. Unfortunately making
coderdtest.New
use this HTTP client was non-trivial without refactoring that. To avoid touching more things, I am using theoidctest.WithServing()
to spin up ahttptest.Server
which handles real network requests.Make refresh tokens sync settings
I discovered in doing this that our group and role syncs do not happen on oauth refresh tokens. This should be remedied. Unit tests that check this have been skipped.