|
| 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