Skip to content

Commit dfa5c74

Browse files
committed
test: add test for websocket secret verification in debugger
1 parent 9835508 commit dfa5c74

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
5+
const assert = require('assert');
6+
const childProcess = require('child_process');
7+
const http = require('http');
8+
9+
let port;
10+
11+
const server = http.createServer(common.mustCall((req, res) => {
12+
if (req.url.startsWith('/json')) {
13+
res.writeHead(200);
14+
res.end(`[ {
15+
"description": "",
16+
"devtoolsFrontendUrl": "/devtools/inspector.html?ws=localhost:${port}/devtools/page/DAB7FB6187B554E10B0BD18821265734",
17+
"cid": "DAB7FB6187B554E10B0BD18821265734",
18+
"title": "Fhqwhgads",
19+
"type": "page",
20+
"url": "https://www.example.com/",
21+
"webSocketDebuggerUrl": "ws://localhost:${port}/devtools/page/DAB7FB6187B554E10B0BD18821265734"
22+
} ]`);
23+
} else {
24+
res.setHeader('Upgrade', 'websocket');
25+
res.setHeader('Connection', 'Upgrade');
26+
res.setHeader('Sec-WebSocket-Accept', 'fhqwhgads');
27+
res.setHeader('Sec-WebSocket-Protocol', 'chat');
28+
res.writeHead(101);
29+
res.end();
30+
}
31+
}, 2)).listen(0, common.mustCall(() => {
32+
port = server.address().port;
33+
const proc =
34+
childProcess.spawn(process.execPath, ['inspect', `localhost:${port}`]);
35+
36+
let stdout = '';
37+
proc.stdout.on('data', (data) => {
38+
stdout += data.toString();
39+
assert.doesNotMatch(stdout, /\bok\b/);
40+
});
41+
42+
let stderr = '';
43+
proc.stderr.on('data', (data) => {
44+
stderr += data.toString();
45+
});
46+
47+
proc.on('exit', common.mustCall((code, signal) => {
48+
assert.match(stderr, /\bWebsocket secret mismatch\b/);
49+
assert.notStrictEqual(code, 0);
50+
assert.strictEqual(signal, null);
51+
server.close();
52+
}));
53+
}));

0 commit comments

Comments
 (0)