Assert unauthorized websocket rejection in smoke test

Co-authored-by: Theo Browne <[email protected]>
This commit is contained in:
Cursor AgentandTheo Browne committed 2026-02-09 23:10:16 +00:00
1 parent f5e2112bf5
commit 133b0abd56
1 file changed
+25
+25
View File
@@ -53,6 +53,22 @@ async function terminateProcess(processRef, timeoutMs = 5_000) {
await waitForProcessExit(processRef);
}
function waitForSocketCloseCode(socket, timeoutMs = 10_000) {
return new Promise((resolve, reject) => {
const timer = setTimeout(() => {
reject(new Error("Smoke test failed: websocket close event timed out."));
}, timeoutMs);
socket.addEventListener("close", (event) => {
clearTimeout(timer);
resolve(event.code);
});
socket.addEventListener("error", () => {
clearTimeout(timer);
reject(new Error("Smoke test failed: websocket client error before close."));
});
});
}
function waitForStartupUrl(readOutput, processRef, timeoutMs = 20_000) {
return new Promise((resolve, reject) => {
const finish = (callback, value) => {
@@ -143,6 +159,15 @@ async function main() {
throw new Error("Smoke test failed: websocket URL is missing runtime auth token.");
}
const unauthorizedWsUrl = `${parsedWsUrl.origin}${parsedWsUrl.pathname}`;
const unauthorizedWs = new WebSocket(unauthorizedWsUrl);
const unauthorizedCode = await waitForSocketCloseCode(unauthorizedWs);
if (unauthorizedCode !== 4001) {
throw new Error(
`Smoke test failed: expected unauthorized close code 4001, received ${unauthorizedCode}.`,
);
}
const ws = new WebSocket(wsUrl);
await new Promise((resolve, reject) => {
const timer = setTimeout(