-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
1 parent
1bd6962
commit 92b13e4
Showing
3 changed files
with
66 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
})); | ||
})); | ||
})); | ||
})); | ||
})); |