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

View File

@@ -213,16 +213,30 @@ describe('streamwall server', () => {
})
it('rejects websocket upgrade if origin is invalid', async () => {
// Make a raw WebSocket connection with a bogus origin
const badWs = new WebSocket(`ws://localhost:${port}/ws`, [], {
origin: 'http://evilsite.com', // not the expectedOrigin
})
const closePromise = once(badWs, 'close')
const [code] = await closePromise
expect(code).toBe(401)
// or just expect the server forcibly closed the connection
})
// Create a promise that will reject if the connection succeeds
const connectPromise = new Promise((resolve, reject) => {
const badWs = new WebSocket(`ws://localhost:${port}/ws`, [], {
origin: 'http://evilsite.com',
});
badWs.on('open', () => {
badWs.close();
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', () => {
it('can view tokens', async () => {
await auth.createToken({