11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ci 41cb0ef41Sopenharmony_ciif (!common.hasCrypto) 51cb0ef41Sopenharmony_ci common.skip('missing crypto'); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures'); 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ciconst assert = require('assert'); 101cb0ef41Sopenharmony_ciconst https = require('https'); 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ciconst TOTAL_REQS = 2; 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_ciconst options = { 151cb0ef41Sopenharmony_ci key: fixtures.readKey('agent1-key.pem'), 161cb0ef41Sopenharmony_ci cert: fixtures.readKey('agent1-cert.pem') 171cb0ef41Sopenharmony_ci}; 181cb0ef41Sopenharmony_ci 191cb0ef41Sopenharmony_ciconst clientSessions = []; 201cb0ef41Sopenharmony_cilet serverRequests = 0; 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ciconst agent = new https.Agent({ 231cb0ef41Sopenharmony_ci maxCachedSessions: 0 241cb0ef41Sopenharmony_ci}); 251cb0ef41Sopenharmony_ci 261cb0ef41Sopenharmony_ciconst server = https.createServer(options, function(req, res) { 271cb0ef41Sopenharmony_ci serverRequests++; 281cb0ef41Sopenharmony_ci res.end('ok'); 291cb0ef41Sopenharmony_ci}).listen(0, function() { 301cb0ef41Sopenharmony_ci let waiting = TOTAL_REQS; 311cb0ef41Sopenharmony_ci function request() { 321cb0ef41Sopenharmony_ci const options = { 331cb0ef41Sopenharmony_ci agent: agent, 341cb0ef41Sopenharmony_ci port: server.address().port, 351cb0ef41Sopenharmony_ci rejectUnauthorized: false 361cb0ef41Sopenharmony_ci }; 371cb0ef41Sopenharmony_ci 381cb0ef41Sopenharmony_ci https.request(options, function(res) { 391cb0ef41Sopenharmony_ci clientSessions.push(res.socket.getSession()); 401cb0ef41Sopenharmony_ci 411cb0ef41Sopenharmony_ci res.resume(); 421cb0ef41Sopenharmony_ci res.on('end', function() { 431cb0ef41Sopenharmony_ci if (--waiting !== 0) 441cb0ef41Sopenharmony_ci return request(); 451cb0ef41Sopenharmony_ci server.close(); 461cb0ef41Sopenharmony_ci }); 471cb0ef41Sopenharmony_ci }).end(); 481cb0ef41Sopenharmony_ci } 491cb0ef41Sopenharmony_ci request(); 501cb0ef41Sopenharmony_ci}); 511cb0ef41Sopenharmony_ci 521cb0ef41Sopenharmony_ciprocess.on('exit', function() { 531cb0ef41Sopenharmony_ci assert.strictEqual(serverRequests, TOTAL_REQS); 541cb0ef41Sopenharmony_ci assert.strictEqual(clientSessions.length, TOTAL_REQS); 551cb0ef41Sopenharmony_ci assert.notStrictEqual(clientSessions[0].toString('hex'), 561cb0ef41Sopenharmony_ci clientSessions[1].toString('hex')); 571cb0ef41Sopenharmony_ci}); 58