Skip to content

Commit 5ca7d0a

Browse files
kjgbotclaude
andcommitted
phase 121: update server's HS256 rejection test for new dual-verify semantics
assertPhase0LegacyHs256Algorithm used to assume the SDK verifier would reject any HS256 token as an unsupported algorithm. With dual-verify (this PR), HS256 is accepted by default, so the old assertion now sees 'jwks_fetch_failed' (the verifier looks for a matching HS256 JWK that the test harness doesn't publish) instead of 'invalid_token'. Fix: set RELAYAUTH_VERIFIER_ACCEPT_HS256=false around the verify call so the test asserts the post-sunset posture that phase 122 flips in production. Test intent ("spec-compliant verifier rejects legacy HS256") is preserved; the fixture just scopes to the correct flag state. Env var is restored in a finally block to avoid cross-test leakage. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 1fa679c commit 5ca7d0a

1 file changed

Lines changed: 29 additions & 15 deletions

File tree

packages/server/src/__tests__/tokens-route.test.ts

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -259,21 +259,35 @@ async function assertPhase0LegacyHs256Algorithm(token: string, audience: string[
259259
kid: "dev-key",
260260
});
261261

262-
const verifier = new TokenVerifier({
263-
jwksUrl: "https://relayauth.test/.well-known/jwks.json",
264-
issuer: "https://relayauth.dev",
265-
audience,
266-
});
267-
268-
await assert.rejects(
269-
() => verifier.verify(token),
270-
(error: unknown) => {
271-
assert.ok(error instanceof RelayAuthError);
272-
assert.equal(error.code, "invalid_token");
273-
return true;
274-
},
275-
"spec-compliant verifiers should reject legacy HS256 tokens until RS256 lands",
276-
);
262+
// Phase 121 added dual-verify to @relayauth/sdk: HS256 is accepted by default
263+
// during the migration window. This assertion is checking the *post-sunset*
264+
// posture — that a verifier with HS256 acceptance disabled rejects these
265+
// legacy tokens. That matches what phase 122 flips in production.
266+
const previousFlag = process.env.RELAYAUTH_VERIFIER_ACCEPT_HS256;
267+
process.env.RELAYAUTH_VERIFIER_ACCEPT_HS256 = "false";
268+
try {
269+
const verifier = new TokenVerifier({
270+
jwksUrl: "https://relayauth.test/.well-known/jwks.json",
271+
issuer: "https://relayauth.dev",
272+
audience,
273+
});
274+
275+
await assert.rejects(
276+
() => verifier.verify(token),
277+
(error: unknown) => {
278+
assert.ok(error instanceof RelayAuthError);
279+
assert.equal(error.code, "invalid_token");
280+
return true;
281+
},
282+
"spec-compliant verifiers (HS256 acceptance disabled) should reject legacy HS256 tokens",
283+
);
284+
} finally {
285+
if (previousFlag === undefined) {
286+
delete process.env.RELAYAUTH_VERIFIER_ACCEPT_HS256;
287+
} else {
288+
process.env.RELAYAUTH_VERIFIER_ACCEPT_HS256 = previousFlag;
289+
}
290+
}
277291
}
278292

279293
async function createHarness({

0 commit comments

Comments
 (0)