-
Notifications
You must be signed in to change notification settings - Fork 576
backend: auth: Extract RefreshAndSetToken from headlamp.go #4230
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
base: main
Are you sure you want to change the base?
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: skoeva The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
7e34534 to
c928a61
Compare
joaquimrocha
left a comment
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.
Is there a chance (honest question) we could have the tests being done for the same logic, before the extraction commit. This way we could verify that everything keeps working whereas right now we are testing for the new changes already.
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.
Pull request overview
This PR extracts the OIDC token refresh-and-cookie-setting logic from HeadlampConfig into the shared auth package and adds focused tests around it. It supports the ongoing effort in #3482 to progressively move and test OIDC-related auth functionality.
Changes:
- Introduces
auth.RefreshAndSetTokenParamsandauth.RefreshAndSetToken, encapsulating token refresh, cookie update, and telemetry recording in theauthpackage. - Replaces the old
(*HeadlampConfig).refreshAndSetTokenmethod with a call to the newauth.RefreshAndSetTokenwithinOIDCTokenRefreshMiddleware. - Adds comprehensive tests in
auth_test.goforRefreshAndSetToken, including default ID token behavior, access token mode, and error handling (no cookie set on failure).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
backend/pkg/auth/auth.go |
Adds RefreshAndSetTokenParams and RefreshAndSetToken, wiring together token refresh, cookie setting, and telemetry with configurable token type and issuer URL. |
backend/pkg/auth/auth_test.go |
Adds helpers and three tests validating that RefreshAndSetToken picks the correct token (ID vs access), sets the expected cookie, and avoids setting cookies on refresh errors. |
backend/cmd/headlamp.go |
Removes the HeadlampConfig.refreshAndSetToken method and switches OIDCTokenRefreshMiddleware to use the new auth.RefreshAndSetToken API while passing the existing config and telemetry fields. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
There aren't any changes in the function logic so coupling the tests with the extracted code should be fine |
This change extracts the RefreshAndSetToken function from headlamp.go into the auth package.
Part of:
Updates
auth_test.goTesting