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 c012dd7

Browse filesBrowse files
papandreouItalo A. Casas
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 160d038 commit c012dd7
Copy full SHA for c012dd7

File tree

Expand file treeCollapse file tree

3 files changed

+66
-2
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+66
-2
lines changed
Open diff view settings
Collapse file

‎lib/https.js‎

Copy file name to clipboardExpand all lines: lib/https.js
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ Agent.prototype.getName = function getName(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

Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-https-agent-getname.js
+2-2Lines changed: 2 additions & 2 deletions
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
);
Collapse file
+60Lines changed: 60 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.