11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ciif (!common.hasCrypto) 41cb0ef41Sopenharmony_ci common.skip('missing crypto'); 51cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures'); 61cb0ef41Sopenharmony_ciconst assert = require('assert'); 71cb0ef41Sopenharmony_ciconst https = require('https'); 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ci// Disable strict server certificate validation by the client 101cb0ef41Sopenharmony_ciprocess.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ciconst options = { 131cb0ef41Sopenharmony_ci key: fixtures.readKey('agent1-key.pem'), 141cb0ef41Sopenharmony_ci cert: fixtures.readKey('agent1-cert.pem') 151cb0ef41Sopenharmony_ci}; 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ciconst server = https.Server(options, common.mustCall((req, res) => { 181cb0ef41Sopenharmony_ci res.writeHead(200); 191cb0ef41Sopenharmony_ci res.end('Hello, World!'); 201cb0ef41Sopenharmony_ci})); 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ciserver.listen(0, common.mustCall(() => { 231cb0ef41Sopenharmony_ci const agent = new https.Agent(); 241cb0ef41Sopenharmony_ci const name = agent.getName({ port: server.address().port }); 251cb0ef41Sopenharmony_ci https.globalAgent = agent; 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ci makeRequest(); 281cb0ef41Sopenharmony_ci assert(name in agent.sockets); // Agent has indeed been used 291cb0ef41Sopenharmony_ci})); 301cb0ef41Sopenharmony_ci 311cb0ef41Sopenharmony_cifunction makeRequest() { 321cb0ef41Sopenharmony_ci const req = https.get({ 331cb0ef41Sopenharmony_ci port: server.address().port 341cb0ef41Sopenharmony_ci }); 351cb0ef41Sopenharmony_ci req.on('close', () => 361cb0ef41Sopenharmony_ci server.close()); 371cb0ef41Sopenharmony_ci} 38