Skip to content

Commit 67965c9

Browse files
committed
https: Use secureProtocol in Agent#getName
As suggested by @bnoordhuis in #9324
1 parent 7537718 commit 67965c9

File tree

3 files changed

+66
-2
lines changed

3 files changed

+66
-2
lines changed

lib/https.js

+4
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ Agent.prototype.getName = function(options) {
143143
if (options.servername && options.servername !== options.host)
144144
name += options.servername;
145145

146+
name += ':';
147+
if (options.secureProtocol)
148+
name += options.secureProtocol;
149+
146150
return name;
147151
};
148152

test/parallel/test-https-agent-getname.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const agent = new https.Agent();
1414
// empty options
1515
assert.strictEqual(
1616
agent.getName({}),
17-
'localhost:::::::::'
17+
'localhost::::::::::'
1818
);
1919

2020
// pass all options arguments
@@ -33,5 +33,5 @@ const options = {
3333

3434
assert.strictEqual(
3535
agent.getName(options),
36-
'0.0.0.0:443:192.168.1.1:ca:cert:ciphers:key:pfx:false:localhost'
36+
'0.0.0.0:443:192.168.1.1:ca:cert:ciphers:key:pfx:false:localhost:'
3737
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
'use strict';
2+
const assert = require('assert');
3+
const common = require('../common');
4+
5+
if (!common.hasCrypto) {
6+
common.skip('missing crypto');
7+
return;
8+
}
9+
10+
const https = require('https');
11+
const fs = require('fs');
12+
13+
const options = {
14+
key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'),
15+
cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem'),
16+
ca: fs.readFileSync(common.fixturesDir + '/keys/ca1-cert.pem')
17+
};
18+
19+
const server = https.Server(options, function(req, res) {
20+
res.writeHead(200);
21+
res.end('hello world\n');
22+
});
23+
24+
server.listen(0, common.mustCall(function() {
25+
const port = this.address().port;
26+
const globalAgent = https.globalAgent;
27+
globalAgent.keepAlive = true;
28+
https.get({
29+
path: '/',
30+
port: port,
31+
ca: options.ca,
32+
rejectUnauthorized: true,
33+
servername: 'agent1',
34+
secureProtocol: 'SSLv23_method'
35+
}, common.mustCall(function(res) {
36+
res.resume();
37+
globalAgent.once('free', common.mustCall(function() {
38+
https.get({
39+
path: '/',
40+
port: port,
41+
ca: options.ca,
42+
rejectUnauthorized: true,
43+
servername: 'agent1',
44+
secureProtocol: 'TLSv1_method'
45+
}, common.mustCall(function(res) {
46+
res.resume();
47+
globalAgent.once('free', common.mustCall(function() {
48+
// Verify that two keep-alived connections are created
49+
// due to the different secureProtocol settings:
50+
const keys = Object.keys(globalAgent.freeSockets);
51+
assert.strictEqual(keys.length, 2);
52+
assert.ok(keys[0].includes(':SSLv23_method'));
53+
assert.ok(keys[1].includes(':TLSv1_method'));
54+
globalAgent.destroy();
55+
server.close();
56+
}));
57+
}));
58+
}));
59+
}));
60+
}));

0 commit comments

Comments
 (0)