Cover wrong-token-key unauthorized non-eviction behavior
Co-authored-by: Theo Browne <[email protected]>
This commit is contained in:
1 parent
be8fccb92d
commit
ef5ab36862
2 files changed
+51
No files matched your search
@@ -2189,6 +2189,14 @@ async function main() {
|
||||
"extra-param-while-connected",
|
||||
);
|
||||
|
||||
const wrongTokenKeyWhileConnectedWs = new WebSocket(
|
||||
`${parsedWsUrl.origin}${parsedWsUrl.pathname}?Token=${runtimeAuthTokenParam}`,
|
||||
);
|
||||
await waitForUnauthorizedCloseWithoutMessages(
|
||||
wrongTokenKeyWhileConnectedWs,
|
||||
"wrong-token-key-while-connected",
|
||||
);
|
||||
|
||||
await new Promise((resolve, reject) => {
|
||||
const timer = setTimeout(
|
||||
() => reject(new Error("Smoke test failed: post-unauthorized websocket health request timed out.")),
|
||||
|
||||
@@ -1428,6 +1428,49 @@ describe("runtimeApiServer", () => {
|
||||
expect([1000, 1005]).toContain(closed.code);
|
||||
});
|
||||
|
||||
it("does not evict authorized client when wrong-token-key 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 wrongTokenKeyClient = new WebSocket(
|
||||
`${authorizedUrl.origin}${authorizedUrl.pathname}?Token=secret-token`,
|
||||
);
|
||||
const wrongTokenKeyClose = await withTimeout(
|
||||
new Promise<{ code: number; reason: string }>((resolve, reject) => {
|
||||
wrongTokenKeyClient.once("close", (code, reason) =>
|
||||
resolve({ code, reason: reason.toString() }),
|
||||
);
|
||||
wrongTokenKeyClient.once("error", (error) => reject(error));
|
||||
}),
|
||||
);
|
||||
expect(wrongTokenKeyClose.code).toBe(WS_CLOSE_CODES.unauthorized);
|
||||
expect(wrongTokenKeyClose.reason).toBe(WS_CLOSE_REASONS.unauthorized);
|
||||
|
||||
const response = await sendRequest(
|
||||
authorizedClient.socket,
|
||||
authorizedClient.nextMessage,
|
||||
"todos-auth-wrong-token-key-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 = "";
|
||||
|
||||
Reference in new issue
Block a user