test(mcp): build the JWT-shaped test value instead of writing it (#202)

The refused Authorization values of the route test held a literal in three
base64url parts starting with `eyJ`: a made-up value, but one a secret scanner
reads as a token. It is now built by the test. No assertion changes.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
le king fu 2026-11-15 08:19:07 -05:00
commit 22a0981fe0

View file

@ -458,6 +458,10 @@ afterAll(() => pilot(initialPilot));
describe('authentication', () => {
const WELL_FORMED = `slmcp_${'A'.repeat(43)}`;
// Three base64url parts, built here so that the file holds no token-shaped literal.
const JWT_SHAPED = [JSON.stringify({ alg: 'none' }), JSON.stringify({ sub: 'nobody' }), 'signature']
.map((part) => Buffer.from(part, 'utf8').toString('base64url'))
.join('.');
it.each([
['no Authorization header', null],
@ -470,7 +474,7 @@ describe('authentication', () => {
['a token under a lowercase scheme', `bearer ${WELL_FORMED}`],
['a well-formed token that was never issued', `Bearer ${WELL_FORMED}`],
['a Logto access token', 'Bearer logto-access-token-of-the-test'],
['a token that looks like a JWT', 'Bearer eyJhbGciOiJFUzM4NCJ9.eyJzdWIiOiJ4In0.c2lnbmF0dXJl'],
['a token that looks like a JWT', `Bearer ${JWT_SHAPED}`],
])('answers 401 to %s, with a Bearer challenge and no redirect', async (_label, authorization) => {
const outbound = vi.spyOn(globalThis, 'fetch');
for (const era of ERAS) {