11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ciif (!common.hasCrypto) 41cb0ef41Sopenharmony_ci common.skip('missing crypto'); 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ciconst assert = require('assert'); 71cb0ef41Sopenharmony_ciconst crypto = require('crypto'); 81cb0ef41Sopenharmony_ciconst https = require('https'); 91cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures'); 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ciconst options = { 121cb0ef41Sopenharmony_ci key: fixtures.readKey('agent1-key.pem'), 131cb0ef41Sopenharmony_ci cert: fixtures.readKey('agent1-cert.pem'), 141cb0ef41Sopenharmony_ci ca: fixtures.readKey('ca1-cert.pem'), 151cb0ef41Sopenharmony_ci minVersion: 'TLSv1.1', 161cb0ef41Sopenharmony_ci ciphers: 'ALL@SECLEVEL=0' 171cb0ef41Sopenharmony_ci}; 181cb0ef41Sopenharmony_ci 191cb0ef41Sopenharmony_ciconst server = https.Server(options, (req, res) => { 201cb0ef41Sopenharmony_ci res.writeHead(200); 211cb0ef41Sopenharmony_ci res.end('hello world\n'); 221cb0ef41Sopenharmony_ci}); 231cb0ef41Sopenharmony_ci 241cb0ef41Sopenharmony_cifunction getBaseOptions(port) { 251cb0ef41Sopenharmony_ci return { 261cb0ef41Sopenharmony_ci path: '/', 271cb0ef41Sopenharmony_ci port: port, 281cb0ef41Sopenharmony_ci ca: options.ca, 291cb0ef41Sopenharmony_ci rejectUnauthorized: true, 301cb0ef41Sopenharmony_ci servername: 'agent1', 311cb0ef41Sopenharmony_ci ciphers: 'ALL@SECLEVEL=0' 321cb0ef41Sopenharmony_ci }; 331cb0ef41Sopenharmony_ci} 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_ciconst updatedValues = new Map([ 361cb0ef41Sopenharmony_ci ['dhparam', fixtures.readKey('dh2048.pem')], 371cb0ef41Sopenharmony_ci ['ecdhCurve', 'secp384r1'], 381cb0ef41Sopenharmony_ci ['honorCipherOrder', true], 391cb0ef41Sopenharmony_ci ['minVersion', 'TLSv1.1'], 401cb0ef41Sopenharmony_ci ['maxVersion', 'TLSv1.3'], 411cb0ef41Sopenharmony_ci ['secureOptions', crypto.constants.SSL_OP_CIPHER_SERVER_PREFERENCE], 421cb0ef41Sopenharmony_ci ['secureProtocol', 'TLSv1_1_method'], 431cb0ef41Sopenharmony_ci ['sessionIdContext', 'sessionIdContext'], 441cb0ef41Sopenharmony_ci]); 451cb0ef41Sopenharmony_ci 461cb0ef41Sopenharmony_cilet value; 471cb0ef41Sopenharmony_cifunction variations(iter, port, cb) { 481cb0ef41Sopenharmony_ci return common.mustCall((res) => { 491cb0ef41Sopenharmony_ci res.resume(); 501cb0ef41Sopenharmony_ci https.globalAgent.once('free', common.mustCall(() => { 511cb0ef41Sopenharmony_ci // Verify that the most recent connection is in the freeSockets pool. 521cb0ef41Sopenharmony_ci const keys = Object.keys(https.globalAgent.freeSockets); 531cb0ef41Sopenharmony_ci if (value) { 541cb0ef41Sopenharmony_ci assert.ok( 551cb0ef41Sopenharmony_ci keys.some((val) => val.startsWith(value.toString() + ':') || 561cb0ef41Sopenharmony_ci val.endsWith(':' + value.toString()) || 571cb0ef41Sopenharmony_ci val.includes(':' + value.toString() + ':')), 581cb0ef41Sopenharmony_ci `missing value: ${value.toString()} in ${keys}` 591cb0ef41Sopenharmony_ci ); 601cb0ef41Sopenharmony_ci } 611cb0ef41Sopenharmony_ci const next = iter.next(); 621cb0ef41Sopenharmony_ci 631cb0ef41Sopenharmony_ci if (next.done) { 641cb0ef41Sopenharmony_ci https.globalAgent.destroy(); 651cb0ef41Sopenharmony_ci server.close(); 661cb0ef41Sopenharmony_ci } else { 671cb0ef41Sopenharmony_ci // Save `value` for check the next time. 681cb0ef41Sopenharmony_ci const [key, val] = next.value; 691cb0ef41Sopenharmony_ci value = val; 701cb0ef41Sopenharmony_ci https.get({ ...getBaseOptions(port), [key]: val }, 711cb0ef41Sopenharmony_ci variations(iter, port, cb)); 721cb0ef41Sopenharmony_ci } 731cb0ef41Sopenharmony_ci })); 741cb0ef41Sopenharmony_ci }); 751cb0ef41Sopenharmony_ci} 761cb0ef41Sopenharmony_ci 771cb0ef41Sopenharmony_ciserver.listen(0, common.mustCall(() => { 781cb0ef41Sopenharmony_ci const port = server.address().port; 791cb0ef41Sopenharmony_ci https.globalAgent.keepAlive = true; 801cb0ef41Sopenharmony_ci https.get(getBaseOptions(port), variations(updatedValues.entries(), port)); 811cb0ef41Sopenharmony_ci})); 82