From 995fceaa6c22883879d476e90cd454419dc5e9b5 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 10 Feb 2026 07:48:02 +0000 Subject: [PATCH] Cover non-eviction for duplicate identical token auth attempts Co-authored-by: Theo Browne --- apps/t3/src/runtimeApiServer.test.ts | 43 ++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/apps/t3/src/runtimeApiServer.test.ts b/apps/t3/src/runtimeApiServer.test.ts index 12c2131835..7441f69f1d 100644 --- a/apps/t3/src/runtimeApiServer.test.ts +++ b/apps/t3/src/runtimeApiServer.test.ts @@ -1306,6 +1306,49 @@ describe("runtimeApiServer", () => { expect([1000, 1005]).toContain(closed.code); }); + it("does not evict authorized client when duplicate-identical-token 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 duplicateIdenticalTokenClient = new WebSocket( + `${authorizedUrl.origin}${authorizedUrl.pathname}?token=secret-token&token=secret-token`, + ); + const duplicateIdenticalTokenClose = await withTimeout( + new Promise<{ code: number; reason: string }>((resolve, reject) => { + duplicateIdenticalTokenClient.once("close", (code, reason) => + resolve({ code, reason: reason.toString() }), + ); + duplicateIdenticalTokenClient.once("error", (error) => reject(error)); + }), + ); + expect(duplicateIdenticalTokenClose.code).toBe(WS_CLOSE_CODES.unauthorized); + expect(duplicateIdenticalTokenClose.reason).toBe(WS_CLOSE_REASONS.unauthorized); + + const response = await sendRequest( + authorizedClient.socket, + authorizedClient.nextMessage, + "todos-auth-duplicate-identical-token-1", + "todos.list", + ); + expect(response.ok).toBe(true); + + authorizedClient.socket.close(); + const closed = await withTimeout(authorizedClose); + expect([1000, 1005]).toContain(closed.code); + }); + it("does not evict authorized client when extra-query client connects", async () => { const server = await startRuntimeApiServer({ port: 0,