Cover auth-mode missing-token extra-query websocket rejection
Co-authored-by: Theo Browne <[email protected]>
This commit is contained in:
1 parent
995fceaa6c
commit
b1c96a56e6
2 files changed
+26
No files matched your search
@@ -1547,6 +1547,14 @@ async function main() {
|
||||
const unauthorizedWs = new WebSocket(unauthorizedWsUrl);
|
||||
await waitForUnauthorizedCloseWithoutMessages(unauthorizedWs, "missing-token");
|
||||
|
||||
const missingTokenWithExtraQueryWs = new WebSocket(
|
||||
`${parsedWsUrl.origin}${parsedWsUrl.pathname}?debug=1`,
|
||||
);
|
||||
await waitForUnauthorizedCloseWithoutMessages(
|
||||
missingTokenWithExtraQueryWs,
|
||||
"missing-token-with-extra-query",
|
||||
);
|
||||
|
||||
const wrongTokenWs = new WebSocket(
|
||||
`${parsedWsUrl.origin}${parsedWsUrl.pathname}?token=wrong-token`,
|
||||
);
|
||||
|
||||
@@ -986,6 +986,24 @@ describe("runtimeApiServer", () => {
|
||||
expect(unauthorizedClose.reason).toBe(WS_CLOSE_REASONS.unauthorized);
|
||||
expect(unauthorizedMessageCount).toBe(0);
|
||||
|
||||
const missingTokenWithExtraQueryUrl = `${authorizedUrl.origin}${authorizedUrl.pathname}?debug=1`;
|
||||
const missingTokenWithExtraQueryClient = new WebSocket(missingTokenWithExtraQueryUrl);
|
||||
let missingTokenWithExtraQueryMessageCount = 0;
|
||||
missingTokenWithExtraQueryClient.on("message", () => {
|
||||
missingTokenWithExtraQueryMessageCount += 1;
|
||||
});
|
||||
const missingTokenWithExtraQueryClose = await withTimeout(
|
||||
new Promise<{ code: number; reason: string }>((resolve, reject) => {
|
||||
missingTokenWithExtraQueryClient.once("close", (code, reason) =>
|
||||
resolve({ code, reason: reason.toString() }),
|
||||
);
|
||||
missingTokenWithExtraQueryClient.once("error", (error) => reject(error));
|
||||
}),
|
||||
);
|
||||
expect(missingTokenWithExtraQueryClose.code).toBe(WS_CLOSE_CODES.unauthorized);
|
||||
expect(missingTokenWithExtraQueryClose.reason).toBe(WS_CLOSE_REASONS.unauthorized);
|
||||
expect(missingTokenWithExtraQueryMessageCount).toBe(0);
|
||||
|
||||
const wrongTokenUrl = `${authorizedUrl.origin}${authorizedUrl.pathname}?token=wrong-token`;
|
||||
const wrongTokenClient = new WebSocket(wrongTokenUrl);
|
||||
let wrongTokenMessageCount = 0;
|
||||
|
||||
Reference in new issue
Block a user