backend: auth: Extract RefreshAndSetToken from headlamp.go#4230
backend: auth: Extract RefreshAndSetToken from headlamp.go#4230skoeva wants to merge 1 commit intokubernetes-sigs:mainfrom
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.
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.
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 |
|
PR needs rebase. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
illume
left a comment
There was a problem hiding this comment.
Unfortunately this has a merge conflict now.
I read through this the other week, and looks good to me. Thanks for the improvement.
This change extracts the RefreshAndSetToken function from headlamp.go into the auth package.
Part of:
Updates
auth_test.goTesting