Skip to content

Commit a30d021

Browse files
TrottBethGriggs
authored andcommitted
test: add test for WebSocket secret verification in debugger
PR-URL: #39357 Refs: nodejs/node-inspect#93 Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 95db544 commit a30d021

File tree

1 file changed

+54
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)