Skip to content

Commit

Permalink
[test] Increase code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
lpinca committed Jan 26, 2021
1 parent d1a8af4 commit 2079ca5
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions test/websocket-server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ describe('WebSocketServer', () => {
const wss = new WebSocket.Server({ noServer: true, path: '/foo' });

assert.strictEqual(wss.shouldHandle({ url: '/foo' }), true);
assert.strictEqual(wss.shouldHandle({ url: '/foo?bar=baz' }), true);
});

it("returns false when the path doesn't match", () => {
Expand Down Expand Up @@ -546,6 +547,41 @@ describe('WebSocketServer', () => {
});
});

it('handles unsupported extensions', (done) => {
const wss = new WebSocket.Server(
{
perMessageDeflate: true,
port: 0
},
() => {
const req = http.get({
port: wss.address().port,
headers: {
Connection: 'Upgrade',
Upgrade: 'websocket',
'Sec-WebSocket-Key': 'dGhlIHNhbXBsZSBub25jZQ==',
'Sec-WebSocket-Version': 13,
'Sec-WebSocket-Extensions': 'foo; bar'
}
});

req.on('upgrade', (res, socket, head) => {
if (head.length) socket.unshift(head);

socket.once('data', (chunk) => {
assert.strictEqual(chunk[0], 0x88);
wss.close(done);
});
});
}
);

wss.on('connection', (ws) => {
assert.strictEqual(ws.extensions, '');
ws.close();
});
});

describe('`verifyClient`', () => {
it('can reject client synchronously', (done) => {
const wss = new WebSocket.Server(
Expand Down

0 comments on commit 2079ca5

Please sign in to comment.