mirror of
https://github.com/streamwall/streamwall.git
synced 2025-12-06 01:45:37 -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 () => {
|
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 badWs = new WebSocket(`ws://localhost:${port}/ws`, [], {
|
const connectPromise = new Promise((resolve, reject) => {
|
||||||
origin: 'http://evilsite.com', // not the expectedOrigin
|
const badWs = new WebSocket(`ws://localhost:${port}/ws`, [], {
|
||||||
})
|
origin: 'http://evilsite.com',
|
||||||
const closePromise = once(badWs, 'close')
|
});
|
||||||
const [code] = await closePromise
|
|
||||||
expect(code).toBe(401)
|
badWs.on('open', () => {
|
||||||
// or just expect the server forcibly closed the connection
|
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', () => {
|
describe('admin role', () => {
|
||||||
it('can view tokens', async () => {
|
it('can view tokens', async () => {
|
||||||
await auth.createToken({
|
await auth.createToken({
|
||||||
|
|||||||
Reference in New Issue
Block a user