Repository navigation
test(oidc): make the Kubernetes token-rotation check deterministic - #2436
Merged
Merged
Conversation
The test asserted that the last Authorization header seen on /keys was the rotated token. toolhive-core registers the JWKS URL with an asynchronous first fetch alongside its synchronous one, so that background request can land after Ready with the pre-rotation token and overwrite the record. Assert on Ready's own result instead: once /keys accepts only the rotated token, Ready fails before the token file is rewritten and succeeds after, which holds however background fetches interleave. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merged
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
TestKubernetesValidatorDerivesIssuerAndAuthenticatesEndpointsfailed in CI withReady sent "***" after rotation, want the rotated token(Test (non-race draft) on #2435, which doesn't touchauthn/). It passed 200 race-enabled runs locally.The test checked the last Authorization header the fixture saw on
/keys. toolhive-core v0.0.51 registers the JWKS URL withWithWaitReady(false), which queues an asynchronous first fetch, and also runs a synchronousRefresh. That background request can arrive afterReady, still carrying the pre-rotation token, and overwrite the record. This is a race in what the test observes, not a product bug: every request re-reads the token file when it is sent.What
/keysaccept only one bearer and answer 401 to any other./keysaccept onlyBearer rotated, then asserts thatReadyfails before the token file is rewritten and succeeds after. That provesReadyre-reads the file, whenever background fetches land. A background fetch that gets the 401 is harmless.Testing
go test -race -count=300of the test atGOMAXPROCS=1and atGOMAXPROCS=2, plusgo test -race ./...inauthn/oidc.Ready after rotation: ... status 401.GOOS=linux task lint.🤖 Generated with Claude Code