fix(statusserver): improve bearer token parsing and add helper tests#3405
fix(statusserver): improve bearer token parsing and add helper tests#3405suchirkolli wants to merge 1 commit intokubeflow:masterfrom
Conversation
Signed-off-by: Skolli <tanusuch@gmail.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 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 |
There was a problem hiding this comment.
Pull request overview
This PR adds focused unit tests for helper functions in the status server package and improves the robustness of bearer token parsing. The changes include new table-driven tests for extractRawToken, TokenAudience, and StatusUrl functions. The extractRawToken function is enhanced to handle extra whitespace using strings.Fields() and to accept case-insensitive Bearer prefix using strings.EqualFold(), making the authentication header parsing more resilient to common variations in formatting.
Changes:
- Add comprehensive table-driven tests for
extractRawTokenwith 8 test cases covering valid tokens, empty headers, missing tokens, wrong schemes, multiple spaces, and case variations - Add table-driven tests for
TokenAudiencefunction with multiple namespace and job name combinations - Add table-driven tests for
StatusUrlfunction with multiple namespace and job name combinations - Improve
extractRawTokento handle repeated whitespace and case-insensitiveBearerprefix
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pkg/statusserver/auth.go | Updated extractRawToken to use strings.Fields() and strings.EqualFold() for more robust bearer token parsing |
| pkg/statusserver/auth_test.go | New comprehensive table-driven tests for extractRawToken covering valid tokens, edge cases, and new behavior |
| pkg/statusserver/utils_test.go | New table-driven tests for TokenAudience and StatusUrl helper functions |
|
Hi, I’m applying to GSoC and started contributing to Kubeflow Trainer with this change. I’d appreciate any feedback when you have time. |
Summary
This PR adds focused unit tests for helper functions in
pkg/statusserver:extractRawTokenTokenAudienceStatusUrlIt also makes bearer token parsing in
extractRawTokenmore robust by:strings.FieldsBearerwithstrings.EqualFoldWhy
These helpers are small but important for status server auth and path generation. Adding direct unit test coverage makes the behavior clearer and improves reliability for future changes.
Changes
extractRawTokenTokenAudienceStatusUrlextractRawTokento handle extra whitespace and lowercasebearerFixes #3404