connect: make the corrupted-token case always corrupt
TestNativeExchangeRefusesTheWrongAssertion replaced the token's last two characters with "AA", leaving it unchanged about 1 run in 256 (it failed hub CI on feat/oficina-id-native-a). corrupt() now changes one middle signature character to a different one. Test-only; 300 consecutive passes; make test green. Reviewed by the lander (one-file test change); hub CI passed at c0757e0. Squashed from fix/native-exchange-flaky-corruption into main.
1 file changed,
+13
−1
connect/native_test.go+13 −1
CI passed — run details
landed from fix/native-exchange-flaky-corruption
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) |