diff --git a/apps/t3/scripts/smoke-test.mjs b/apps/t3/scripts/smoke-test.mjs index 90a9dc42b8..1e7e106e6d 100644 --- a/apps/t3/scripts/smoke-test.mjs +++ b/apps/t3/scripts/smoke-test.mjs @@ -168,6 +168,16 @@ async function main() { ); } + const wrongTokenWs = new WebSocket( + `${parsedWsUrl.origin}${parsedWsUrl.pathname}?token=wrong-token`, + ); + const wrongTokenCode = await waitForSocketCloseCode(wrongTokenWs); + if (wrongTokenCode !== 4001) { + throw new Error( + `Smoke test failed: expected wrong-token close code 4001, received ${wrongTokenCode}.`, + ); + } + const ws = new WebSocket(wsUrl); await new Promise((resolve, reject) => { const timer = setTimeout( diff --git a/apps/t3/src/runtimeApiServer.test.ts b/apps/t3/src/runtimeApiServer.test.ts index 60a7a3a589..66fd33b68b 100644 --- a/apps/t3/src/runtimeApiServer.test.ts +++ b/apps/t3/src/runtimeApiServer.test.ts @@ -259,6 +259,16 @@ describe("runtimeApiServer", () => { ); expect(unauthorizedClose.code).toBe(4001); + const wrongTokenUrl = `${authorizedUrl.origin}${authorizedUrl.pathname}?token=wrong-token`; + const wrongTokenClient = new WebSocket(wrongTokenUrl); + const wrongTokenClose = await withTimeout( + new Promise<{ code: number }>((resolve, reject) => { + wrongTokenClient.once("close", (code) => resolve({ code })); + wrongTokenClient.once("error", (error) => reject(error)); + }), + ); + expect(wrongTokenClose.code).toBe(4001); + const authorizedClient = await connectClient(server.wsUrl); const hello = await authorizedClient.nextMessage(); expect(hello.type).toBe("hello");