connect: the corrupted-token case always changes the token
Human
Prompt
Coordinator: fix the flaky corrupted-token case on a new Home branch from fresh main; make test; push; describe; don't merge.
From this commit's own message. The prompt ledger has no entries for it — which is what a squashed, rebased or amended commit looks like, and what every commit looks like in a repo without a ledger.
Summary
TestNativeExchangeRefusesTheWrongAssertion replaced a valid token's last two characters with "AA", which left it unchanged about 1 run in 256 and failed hub CI elsewhere. It now flips one middle character of the signature to a different character, so the decoded signature always differs. Stressed with -count=300.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+13
−1
connect/native_test.go+13 −1
CI passed — run details
diff --git a/connect/native_test.go b/connect/native_test.go| index a6bd4a6..6b3f3b1 100644 |
| --- a/connect/native_test.go |
| +++ b/connect/native_test.go |
| @@ -271,7 +271,7 @@ func TestNativeExchangeRefusesTheWrongAssertion(t *testing.T) { |
| "another verifier": {"assertion": good, "verifier": newVerifier(t)}, |
| "a browser nonce": {"assertion": f.signed(t, "pr_linked", webNonce, bridgeOrigin), "verifier": verifier}, |
| "another audience": {"assertion": f.nativeAssertionFor(t, "pr_linked", verifier, "https://red.docs.oficina.works"), "verifier": verifier}, |
| - "a corrupted token": {"assertion": good[:len(good)-2] + "AA", "verifier": verifier}, |
| + "a corrupted token": {"assertion": corrupt(good), "verifier": verifier}, |
| "a stranger's token": {"assertion": strings.Repeat("x", 200), "verifier": verifier}, |
| } { |
| t.Run(name, func(t *testing.T) { wantState(t, f.exchange(t, nativeRequestFor(t, body)), 401, "failed") }) |
| @@ -284,6 +284,18 @@ func TestNativeExchangeRefusesTheWrongAssertion(t *testing.T) { |
| wantState(t, f.exchange(t, nativeRequestFor(t, ok)), 401, "failed") |
| } |
| +// corrupt changes one character inside the token's signature, always to a |
| +// different one: a middle character carries six full bits, so the decoded |
| +// signature differs whatever the original was. |
| +func corrupt(token string) string { |
| + i := len(token) - 10 |
| + c := byte('A') |
| + if token[i] == 'A' { |
| + c = 'B' |
| + } |
| + return token[:i] + string(c) + token[i+1:] |
| +} |
| + |
| func (f *bridgeFixture) nativeAssertionFor(t *testing.T, subject, verifier, audience string) string { |
| t.Helper() |
| challenge, _ := handoff.NativeChallenge(verifier) |