This commit is contained in:
sayhiben
2025-01-20 00:24:02 -08:00
parent 3c48c2c6ca
commit 6db0360ad6

View File

@@ -213,15 +213,29 @@ describe('streamwall server', () => {
}) })
it('rejects websocket upgrade if origin is invalid', async () => { it('rejects websocket upgrade if origin is invalid', async () => {
// Make a raw WebSocket connection with a bogus origin // Create a promise that will reject if the connection succeeds
const connectPromise = new Promise((resolve, reject) => {
const badWs = new WebSocket(`ws://localhost:${port}/ws`, [], { const badWs = new WebSocket(`ws://localhost:${port}/ws`, [], {
origin: 'http://evilsite.com', // not the expectedOrigin origin: 'http://evilsite.com',
}) });
const closePromise = once(badWs, 'close')
const [code] = await closePromise badWs.on('open', () => {
expect(code).toBe(401) badWs.close();
// or just expect the server forcibly closed the connection reject(new Error('WebSocket connection should not succeed'));
}) });
badWs.on('error', (err) => {
// We expect this to fail with a 401
if (err.message.includes('401')) {
resolve();
} else {
reject(err);
}
});
});
await connectPromise;
});
describe('admin role', () => { describe('admin role', () => {
it('can view tokens', async () => { it('can view tokens', async () => {