fix(coderd/coderdtest/oidctest): scope IDP NotFound errors to IDP paths#25876
Draft
mafredri wants to merge 1 commit into
Draft
fix(coderd/coderdtest/oidctest): scope IDP NotFound errors to IDP paths#25876mafredri wants to merge 1 commit into
mafredri wants to merge 1 commit into
Conversation
The FakeIDP mux.NotFound handler called t.Errorf for any unrecognized HTTP request path. When the IDP runs as a real HTTP server (WithServing), OS port reuse can route stale connections from other test processes (provisionerd reconnects, DERP) to the IDP port. The t.Errorf then fails the IDP owning test for a request that did not originate from it. Check whether the request path starts with a known IDP route prefix (/oauth2/, /.well-known/, /login/, /external-auth-validate/). IDP paths still get t.Errorf and logger.Error (real protocol violations). Non-IDP paths get t.Logf and logger.Warn (cross-test contamination, visible in logs but does not fail the test). Add a regression test that uses provisionerd.New with codersdk.Client.ServeProvisionerDaemon as the dialer to reproduce the port-reuse mechanism through real production code paths.
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.
Problem
TestUserOIDC/FullNameFromClaimsflakes in CI (test-go-pg-17) when the full test suite runs in parallel. The test itself passes (OIDC flow completes, user created correctly), but the FakeIDP'smux.NotFoundhandler callst.Errorfwhen it receives a request at a non-IDP path like/api/v2/organizations/{uuid}/provisionerdaemons/serve.The same class of bug caused #13788 (
/derppath) and coder/internal#280 (/derppath).Root Cause
The
mux.NotFoundhandler inidp.gocallst.Errorfunconditionally for any unrecognized path. When the IDP runs as a real HTTP server (WithServing()), OS port reuse can route stale connections from other test processes to the IDP's port. Thet.Errorfthen fails the IDP's owning test for a request that did not originate from it.Coverage confirms the handler body is cov0 during correct test execution (never reached by any legitimate IDP request):
37 tests use
WithServing(), all vulnerable.Fix
Check whether the request path starts with a known IDP route prefix (
/oauth2/,/.well-known/,/login/,/external-auth-validate/). These match all routes registered inhttpHandler.t.Errorf+logger.Error(preserves real protocol violation detection)t.Logf+logger.Warn(visible in output but does not fail the test)This also addresses the
slogtestfailure vector (line 1417logger.Errordowngraded toWarnfor non-IDP paths), fixing the class seen in #13788 and coder/internal#280 whereWithLogging(t, nil)caused additional test failures.Debugger evidence
Two-breakpoint dlv session (BP1 at
provisionerd.go:237, BP2 atidp.go:1418) on the regression test:Stop 1 (provisionerd retry loop):
Stop 2 (IDP NotFound handler):
Same port (41629), same org UUID (0b75b936), proving the causal chain: provisionerd retry -> IDP port -> chi no-match -> NotFound ->
t.Errorf.