From ef5ab3686229bdd78f8d4c371592945e13666133 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 10 Feb 2026 08:01:41 +0000 Subject: [PATCH] Cover wrong-token-key unauthorized non-eviction behavior Co-authored-by: Theo Browne --- apps/t3/scripts/smoke-test.mjs | 8 ++++++ apps/t3/src/runtimeApiServer.test.ts | 43 ++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/apps/t3/scripts/smoke-test.mjs b/apps/t3/scripts/smoke-test.mjs index 786b75cf70..68174a8032 100644 --- a/apps/t3/scripts/smoke-test.mjs +++ b/apps/t3/scripts/smoke-test.mjs @@ -2189,6 +2189,14 @@ async function main() { "extra-param-while-connected", ); + const wrongTokenKeyWhileConnectedWs = new WebSocket( + `${parsedWsUrl.origin}${parsedWsUrl.pathname}?Token=${runtimeAuthTokenParam}`, + ); + await waitForUnauthorizedCloseWithoutMessages( + wrongTokenKeyWhileConnectedWs, + "wrong-token-key-while-connected", + ); + await new Promise((resolve, reject) => { const timer = setTimeout( () => reject(new Error("Smoke test failed: post-unauthorized websocket health request timed out.")), diff --git a/apps/t3/src/runtimeApiServer.test.ts b/apps/t3/src/runtimeApiServer.test.ts index d64395ce03..cf1bc8da1c 100644 --- a/apps/t3/src/runtimeApiServer.test.ts +++ b/apps/t3/src/runtimeApiServer.test.ts @@ -1428,6 +1428,49 @@ describe("runtimeApiServer", () => { expect([1000, 1005]).toContain(closed.code); }); + it("does not evict authorized client when wrong-token-key client connects", async () => { + const server = await startRuntimeApiServer({ + port: 0, + launchCwd: process.cwd(), + authToken: "secret-token", + }); + servers.push(server); + + const authorizedClient = await connectClient(server.wsUrl); + await authorizedClient.nextMessage(); + + const authorizedClose = new Promise<{ code: number }>((resolve) => { + authorizedClient.socket.once("close", (code) => resolve({ code })); + }); + + const authorizedUrl = new URL(server.wsUrl); + const wrongTokenKeyClient = new WebSocket( + `${authorizedUrl.origin}${authorizedUrl.pathname}?Token=secret-token`, + ); + const wrongTokenKeyClose = await withTimeout( + new Promise<{ code: number; reason: string }>((resolve, reject) => { + wrongTokenKeyClient.once("close", (code, reason) => + resolve({ code, reason: reason.toString() }), + ); + wrongTokenKeyClient.once("error", (error) => reject(error)); + }), + ); + expect(wrongTokenKeyClose.code).toBe(WS_CLOSE_CODES.unauthorized); + expect(wrongTokenKeyClose.reason).toBe(WS_CLOSE_REASONS.unauthorized); + + const response = await sendRequest( + authorizedClient.socket, + authorizedClient.nextMessage, + "todos-auth-wrong-token-key-1", + "todos.list", + ); + expect(response.ok).toBe(true); + + authorizedClient.socket.close(); + const closed = await withTimeout(authorizedClose); + expect([1000, 1005]).toContain(closed.code); + }); + it("returns a bootstrap payload even when codex cannot initialize", async () => { const originalPath = process.env.PATH; process.env.PATH = "";