From 3db1ffe8a96075e8f1811a5287a5c2f4d5bc61df Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 10 Feb 2026 00:22:43 +0000 Subject: [PATCH] Assert unauthorized clients receive no websocket messages Co-authored-by: Theo Browne --- apps/t3/src/runtimeApiServer.test.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/apps/t3/src/runtimeApiServer.test.ts b/apps/t3/src/runtimeApiServer.test.ts index 143cdf9a8c..bef82b7725 100644 --- a/apps/t3/src/runtimeApiServer.test.ts +++ b/apps/t3/src/runtimeApiServer.test.ts @@ -528,6 +528,10 @@ describe("runtimeApiServer", () => { expect(authorizedUrl.searchParams.get("token")).toBe("secret-token"); const unauthorizedUrl = `${authorizedUrl.origin}${authorizedUrl.pathname}`; const unauthorizedClient = new WebSocket(unauthorizedUrl); + let unauthorizedMessageCount = 0; + unauthorizedClient.on("message", () => { + unauthorizedMessageCount += 1; + }); const unauthorizedClose = await withTimeout( new Promise<{ code: number }>((resolve, reject) => { unauthorizedClient.once("close", (code) => resolve({ code })); @@ -535,9 +539,14 @@ describe("runtimeApiServer", () => { }), ); expect(unauthorizedClose.code).toBe(4001); + expect(unauthorizedMessageCount).toBe(0); const wrongTokenUrl = `${authorizedUrl.origin}${authorizedUrl.pathname}?token=wrong-token`; const wrongTokenClient = new WebSocket(wrongTokenUrl); + let wrongTokenMessageCount = 0; + wrongTokenClient.on("message", () => { + wrongTokenMessageCount += 1; + }); const wrongTokenClose = await withTimeout( new Promise<{ code: number }>((resolve, reject) => { wrongTokenClient.once("close", (code) => resolve({ code })); @@ -545,6 +554,7 @@ describe("runtimeApiServer", () => { }), ); expect(wrongTokenClose.code).toBe(4001); + expect(wrongTokenMessageCount).toBe(0); const authorizedClient = await connectClient(server.wsUrl); const hello = await authorizedClient.nextMessage();