Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

ThomasK33
Copy link
Member

@ThomasK33 ThomasK33 commented Sep 12, 2025

Trim whitespace from API tokens in Authorization headers and query parameters

This PR enhances the API token extraction logic by trimming whitespace from tokens obtained via:

  1. Authorization: Bearer headers
  2. access_token query parameters

The change ensures consistent token handling when tokens contain leading or trailing whitespace, improving authentication reliability.

The PR also removes unnecessary t.Parallel() calls from OAuth2 bearer token tests to prevent potential race conditions during test execution.

Fixes: coder/internal#967

Copy link
Member Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

Fixes flake where subtests used t.Parallel() while sharing a DB from dbtestutil.NewDB(t). On Windows, the parent test’s t.Cleanup closed the DB before parallel subtests finished, yielding intermittent 401 Unauthorized instead of 200. Serializing the subtests keeps the DB alive for each case and removes the flake.
Also trims whitespace from Authorization: Bearer and access_token token extraction for robustness; no change to precedence or overall behavior.

Change-Id: Ifa9ad5bb297dc96612dbfb9ef8bb0e16d8ce5778
Signed-off-by: Thomas Kosiewski <[email protected]>
@ThomasK33 ThomasK33 force-pushed the thomask33/09-12-test_httpmw_deflake_rfc6750_bearer_token_tests_on_windows_fixes_flake_where_subtests_used_t.parallel_while_sharing_a_db_from_dbtestutil.newdb_t_._on_windows_the_parent_test_s_t.cleanup_closed_the_db_before_parallel_sub branch from 0f522e5 to 1188e6c Compare September 12, 2025 12:56
@ThomasK33 ThomasK33 requested review from Emyrk and johnstcn and removed request for Emyrk September 12, 2025 21:19
@ThomasK33 ThomasK33 marked this pull request as ready for review September 12, 2025 21:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

flake: TestOAuth2BearerTokenPrecedence and TestRFC6750BearerTokenAuthentication
1 participant