Skip to content

Commit

Permalink
https: Use secureProtocol in Agent#getName
Browse files Browse the repository at this point in the history
Refs: #9324
PR-URL: #9452
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
  • Loading branch information
papandreou authored and italoacasas committed Jan 27, 2017
1 parent 160d038 commit c012dd7
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lib/https.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ Agent.prototype.getName = function getName(options) {
if (options.servername && options.servername !== options.host)
name += options.servername;

name += ':';
if (options.secureProtocol)
name += options.secureProtocol;

return name;
};

Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-https-agent-getname.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const agent = new https.Agent();
// empty options
assert.strictEqual(
agent.getName({}),
'localhost:::::::::'
'localhost::::::::::'
);

// pass all options arguments
Expand All @@ -33,5 +33,5 @@ const options = {

assert.strictEqual(
agent.getName(options),
'0.0.0.0:443:192.168.1.1:ca:cert:ciphers:key:pfx:false:localhost'
'0.0.0.0:443:192.168.1.1:ca:cert:ciphers:key:pfx:false:localhost:'
);
60 changes: 60 additions & 0 deletions test/parallel/test-https-agent-secure-protocol.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
'use strict';
const assert = require('assert');
const common = require('../common');

if (!common.hasCrypto) {
common.skip('missing crypto');
return;
}

const https = require('https');
const fs = require('fs');

const options = {
key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'),
cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem'),
ca: fs.readFileSync(common.fixturesDir + '/keys/ca1-cert.pem')
};

const server = https.Server(options, function(req, res) {
res.writeHead(200);
res.end('hello world\n');
});

server.listen(0, common.mustCall(function() {
const port = this.address().port;
const globalAgent = https.globalAgent;
globalAgent.keepAlive = true;
https.get({
path: '/',
port: port,
ca: options.ca,
rejectUnauthorized: true,
servername: 'agent1',
secureProtocol: 'SSLv23_method'
}, common.mustCall(function(res) {
res.resume();
globalAgent.once('free', common.mustCall(function() {
https.get({
path: '/',
port: port,
ca: options.ca,
rejectUnauthorized: true,
servername: 'agent1',
secureProtocol: 'TLSv1_method'
}, common.mustCall(function(res) {
res.resume();
globalAgent.once('free', common.mustCall(function() {
// Verify that two keep-alived connections are created
// due to the different secureProtocol settings:
const keys = Object.keys(globalAgent.freeSockets);
assert.strictEqual(keys.length, 2);
assert.ok(keys[0].includes(':SSLv23_method'));
assert.ok(keys[1].includes(':TLSv1_method'));
globalAgent.destroy();
server.close();
}));
}));
}));
}));
}));

0 comments on commit c012dd7

Please sign in to comment.