Skip to content

Commit 047bac2

Browse 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: #17328Fixes: #15303 Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Sebastiaan Deckers <[email protected]>
1 parent 67abc1e commit 047bac2

File tree

1 file changed

+24
-30
lines changed

1 file changed

+24
-30
lines changed

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

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ function loadKey(keyname){
2020
functiononStream(stream,headers){
2121
constsocket=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
functionverifySecureSession(key,cert,ca,opts){
3431
constserver=h2.createSecureServer({ cert, key });
3532
server.on('stream',common.mustCall(onStream));
36-
server.listen(0);
37-
server.on('listening',common.mustCall(function(){
38-
constheaders={':path': '/'};
39-
if(!opts){
40-
opts={};
41-
}
33+
server.listen(0,common.mustCall(()=>{
34+
opts=opts||{};
4235
opts.secureContext=tls.createSecureContext({ ca });
43-
constclient=h2.connect(`https://localhost:${this.address().port}`,opts,function(){
44-
constreq=client.request(headers);
36+
constclient=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+
constreq=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-
letdata='';
54-
req.setEncoding('utf8');
55-
req.on('data',(d)=>data+=d);
56-
req.on('end',common.mustCall(()=>{
57-
constjsonData=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+
letdata='';
49+
req.setEncoding('utf8');
50+
req.on('data',(d)=>data+=d);
51+
req.on('end',common.mustCall(()=>{
52+
constjsonData=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)