Ensure unauthorized websocket clients cannot evict active session

Co-authored-by: Theo Browne <[email protected]>
This commit is contained in:
Cursor AgentandTheo Browne committed 2026-02-09 23:12:40 +00:00
1 parent cfe32a9623
commit a73b95ae73
1 file changed
+39
+39
View File
@@ -221,6 +221,45 @@ describe("runtimeApiServer", () => {
authorizedClient.socket.close();
});
it("does not evict authorized client when unauthorized 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 unauthorizedUrl = `${authorizedUrl.origin}${authorizedUrl.pathname}`;
const unauthorizedClient = new WebSocket(unauthorizedUrl);
const unauthorizedClose = await withTimeout(
new Promise<{ code: number }>((resolve, reject) => {
unauthorizedClient.once("close", (code) => resolve({ code }));
unauthorizedClient.once("error", (error) => reject(error));
}),
);
expect(unauthorizedClose.code).toBe(4001);
const response = await sendRequest(
authorizedClient.socket,
authorizedClient.nextMessage,
"todos-auth-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 = "";