Skip to content

fix(statusserver): improve bearer token parsing and add helper tests#3405

Open
suchirkolli wants to merge 1 commit intokubeflow:masterfrom
suchirkolli:test-statusserver-helpers
Open

fix(statusserver): improve bearer token parsing and add helper tests#3405
suchirkolli wants to merge 1 commit intokubeflow:masterfrom
suchirkolli:test-statusserver-helpers

Conversation

@suchirkolli
Copy link
Copy Markdown

Summary

This PR adds focused unit tests for helper functions in pkg/statusserver:

  • extractRawToken
  • TokenAudience
  • StatusUrl

It also makes bearer token parsing in extractRawToken more robust by:

  • handling repeated whitespace with strings.Fields
  • accepting case-insensitive Bearer with strings.EqualFold

Why

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

  • add table-driven tests for extractRawToken
  • add table-driven tests for TokenAudience
  • add table-driven tests for StatusUrl
  • update extractRawToken to handle extra whitespace and lowercase bearer

Fixes #3404

Copilot AI review requested due to automatic review settings March 31, 2026 17:35
@google-oss-prow
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign astefanutti for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link
Copy Markdown
Contributor

Copilot AI left a 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 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 extractRawToken with 8 test cases covering valid tokens, empty headers, missing tokens, wrong schemes, multiple spaces, and case variations
  • Add table-driven tests for TokenAudience function with multiple namespace and job name combinations
  • Add table-driven tests for StatusUrl function with multiple namespace and job name combinations
  • Improve extractRawToken to handle repeated whitespace and case-insensitive Bearer prefix

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

@suchirkolli
Copy link
Copy Markdown
Author

Hi, I’m applying to GSoC and started contributing to Kubeflow Trainer with this change. I’d appreciate any feedback when you have time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test(statusserver): add unit tests for token parsing and status URL helpers

2 participants