Cover duplicate-token unauthorized non-eviction behavior

Co-authored-by: Theo Browne <[email protected]>
This commit is contained in:
Cursor AgentandTheo Browne committed 2026-02-10 05:15:25 +00:00
1 parent e6b40ac013
commit 8edbf85b54
1 file changed
+40
+40
View File
@@ -1076,6 +1076,46 @@ describe("runtimeApiServer", () => {
expect([1000, 1005]).toContain(closed.code);
});
it("does not evict authorized client when duplicate-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 duplicateTokenClient = new WebSocket(
`${authorizedUrl.origin}${authorizedUrl.pathname}?token=secret-token&token=wrong-token`,
);
const duplicateTokenClose = await withTimeout(
new Promise<{ code: number }>((resolve, reject) => {
duplicateTokenClient.once("close", (code) => resolve({ code }));
duplicateTokenClient.once("error", (error) => reject(error));
}),
);
expect(duplicateTokenClose.code).toBe(4001);
const response = await sendRequest(
authorizedClient.socket,
authorizedClient.nextMessage,
"todos-auth-duplicate-token-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 = "";