Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 927a281

Browse filesBrowse files
jasnellMylesBorins
authored andcommitted
test: fixup test-http2-create-client-secure-session
General improvements to test and verify that a secureConnect handler is present PR-URL: #17328 Fixes: #15303 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Sebastiaan Deckers <sebdeckers83@gmail.com>
1 parent 31cdbd6 commit 927a281
Copy full SHA for 927a281

File tree

Expand file treeCollapse file tree

1 file changed

+24
-30
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+24
-30
lines changed
Open diff view settings
Collapse file

‎test/parallel/test-http2-create-client-secure-session.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-http2-create-client-secure-session.js
+24-30Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ function loadKey(keyname) {
2020
function onStream(stream, headers) {
2121
const socket = stream.session[kSocket];
2222
assert(headers[':authority'].startsWith(socket.servername));
23-
stream.respond({
24-
'content-type': 'text/html',
25-
':status': 200
26-
});
23+
stream.respond({ 'content-type': 'application/json' });
2724
stream.end(JSON.stringify({
2825
servername: socket.servername,
2926
alpnProtocol: socket.alpnProtocol
@@ -33,35 +30,32 @@ function onStream(stream, headers) {
3330
function verifySecureSession(key, cert, ca, opts) {
3431
const server = h2.createSecureServer({ cert, key });
3532
server.on('stream', common.mustCall(onStream));
36-
server.listen(0);
37-
server.on('listening', common.mustCall(function() {
38-
const headers = { ':path': '/' };
39-
if (!opts) {
40-
opts = {};
41-
}
33+
server.listen(0, common.mustCall(() => {
34+
opts = opts || { };
4235
opts.secureContext = tls.createSecureContext({ ca });
43-
const client = h2.connect(`https://localhost:${this.address().port}`, opts, function() {
44-
const req = client.request(headers);
36+
const client = h2.connect(`https://localhost:${server.address().port}`,
37+
opts);
38+
// Verify that a 'secureConnect' listener is attached
39+
assert.strictEqual(client.socket.listenerCount('secureConnect'), 1);
40+
const req = client.request();
4541

46-
req.on('response', common.mustCall(function(headers) {
47-
assert.strictEqual(headers[':status'], 200, 'status code is set');
48-
assert.strictEqual(headers['content-type'], 'text/html',
49-
'content type is set');
50-
assert(headers['date'], 'there is a date');
51-
}));
42+
req.on('response', common.mustCall((headers) => {
43+
assert.strictEqual(headers[':status'], 200);
44+
assert.strictEqual(headers['content-type'], 'application/json');
45+
assert(headers['date']);
46+
}));
5247

53-
let data = '';
54-
req.setEncoding('utf8');
55-
req.on('data', (d) => data += d);
56-
req.on('end', common.mustCall(() => {
57-
const jsonData = JSON.parse(data);
58-
assert.strictEqual(jsonData.servername, opts.servername || 'localhost');
59-
assert.strictEqual(jsonData.alpnProtocol, 'h2');
60-
server.close();
61-
client[kSocket].destroy();
62-
}));
63-
req.end();
64-
});
48+
let data = '';
49+
req.setEncoding('utf8');
50+
req.on('data', (d) => data += d);
51+
req.on('end', common.mustCall(() => {
52+
const jsonData = JSON.parse(data);
53+
assert.strictEqual(jsonData.servername,
54+
opts.servername || 'localhost');
55+
assert.strictEqual(jsonData.alpnProtocol, 'h2');
56+
server.close();
57+
client[kSocket].destroy();
58+
}));
6559
}));
6660
}
6761

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.