1'use strict'; 2const common = require('../common'); 3if (!common.hasCrypto) 4 common.skip('missing crypto'); 5 6const assert = require('assert'); 7const crypto = require('crypto'); 8const https = require('https'); 9const fixtures = require('../common/fixtures'); 10 11const options = { 12 key: fixtures.readKey('agent1-key.pem'), 13 cert: fixtures.readKey('agent1-cert.pem'), 14 ca: fixtures.readKey('ca1-cert.pem'), 15 minVersion: 'TLSv1.1', 16}; 17 18const server = https.Server(options, (req, res) => { 19 res.writeHead(200); 20 res.end('hello world\n'); 21}); 22 23function getBaseOptions(port) { 24 return { 25 path: '/', 26 port: port, 27 ca: options.ca, 28 rejectUnauthorized: true, 29 servername: 'agent1', 30 }; 31} 32 33const updatedValues = new Map([ 34 ['dhparam', fixtures.readKey('dh2048.pem')], 35 ['ecdhCurve', 'secp384r1'], 36 ['honorCipherOrder', true], 37 ['minVersion', 'TLSv1.1'], 38 ['maxVersion', 'TLSv1.3'], 39 ['secureOptions', crypto.constants.SSL_OP_CIPHER_SERVER_PREFERENCE], 40 ['secureProtocol', 'TLSv1_1_method'], 41 ['sessionIdContext', 'sessionIdContext'], 42]); 43 44let value; 45function variations(iter, port, cb) { 46 return common.mustCall((res) => { 47 res.resume(); 48 https.globalAgent.once('free', common.mustCall(() => { 49 // Verify that the most recent connection is in the freeSockets pool. 50 const keys = Object.keys(https.globalAgent.freeSockets); 51 if (value) { 52 assert.ok( 53 keys.some((val) => val.startsWith(value.toString() + ':') || 54 val.endsWith(':' + value.toString()) || 55 val.includes(':' + value.toString() + ':')), 56 `missing value: ${value.toString()} in ${keys}` 57 ); 58 } 59 const next = iter.next(); 60 61 if (next.done) { 62 https.globalAgent.destroy(); 63 server.close(); 64 } else { 65 // Save `value` for check the next time. 66 const [key, val] = next.value; 67 value = val; 68 https.get({ ...getBaseOptions(port), [key]: val }, 69 variations(iter, port, cb)); 70 } 71 })); 72 }); 73} 74 75server.listen(0, common.mustCall(() => { 76 const port = server.address().port; 77 https.globalAgent.keepAlive = true; 78 https.get(getBaseOptions(port), variations(updatedValues.entries(), port)); 79})); 80