Skip to content

Commit 92b13e4

Browse files
papandreouMylesBorins
authored andcommitted
https: Use secureProtocol in Agent#getName
Refs: #9324 PR-URL: #9452 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 1bd6962 commit 92b13e4

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
@@ -146,6 +146,10 @@ Agent.prototype.getName = function(options) {
146146
if (options.servername && options.servername !== options.host)
147147
name += options.servername;
148148

149+
name += ':';
150+
if (options.secureProtocol)
151+
name += options.secureProtocol;
152+
149153
return name;
150154
};
151155

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const agent = new https.Agent();
99
// empty options
1010
assert.strictEqual(
1111
agent.getName({}),
12-
'localhost:::::::::'
12+
'localhost::::::::::'
1313
);
1414

1515
// pass all options arguments
@@ -28,5 +28,5 @@ const options = {
2828

2929
assert.strictEqual(
3030
agent.getName(options),
31-
'0.0.0.0:443:192.168.1.1:ca:cert:ciphers:key:pfx:false:localhost'
31+
'0.0.0.0:443:192.168.1.1:ca:cert:ciphers:key:pfx:false:localhost:'
3232
);
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)