mirror of
https://github.com/streamwall/streamwall.git
synced 2025-12-05 17:35:36 -05:00
Fix test
This commit is contained in:
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user