|
| 1 | +'use strict'; |
| 2 | +const common = require('../common'); |
| 3 | +const assert = require('assert'); |
| 4 | + |
| 5 | +if (!common.hasCrypto) { |
| 6 | + console.log('1..0 # Skipped: missing crypto'); |
| 7 | + return; |
| 8 | +} |
| 9 | + |
| 10 | +const TOTAL_REQS = 2; |
| 11 | + |
| 12 | +const https = require('https'); |
| 13 | +const crypto = require('crypto'); |
| 14 | + |
| 15 | +const fs = require('fs'); |
| 16 | + |
| 17 | +const options = { |
| 18 | + key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), |
| 19 | + cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') |
| 20 | +}; |
| 21 | + |
| 22 | +const clientSessions = []; |
| 23 | +var serverRequests = 0; |
| 24 | + |
| 25 | +const agent = new https.Agent({ |
| 26 | + maxCachedSessions: 0 |
| 27 | +}); |
| 28 | + |
| 29 | +const server = https.createServer(options, function(req, res) { |
| 30 | + serverRequests++; |
| 31 | + res.end('ok'); |
| 32 | +}).listen(common.PORT, function() { |
| 33 | + var waiting = TOTAL_REQS; |
| 34 | + function request() { |
| 35 | + const options = { |
| 36 | + agent: agent, |
| 37 | + port: common.PORT, |
| 38 | + rejectUnauthorized: false |
| 39 | + }; |
| 40 | + |
| 41 | + https.request(options, function(res) { |
| 42 | + clientSessions.push(res.socket.getSession()); |
| 43 | + |
| 44 | + res.resume(); |
| 45 | + res.on('end', function() { |
| 46 | + if (--waiting !== 0) |
| 47 | + return request(); |
| 48 | + server.close(); |
| 49 | + }); |
| 50 | + }).end(); |
| 51 | + } |
| 52 | + request(); |
| 53 | +}); |
| 54 | + |
| 55 | +process.on('exit', function() { |
| 56 | + assert.equal(serverRequests, TOTAL_REQS); |
| 57 | + assert.equal(clientSessions.length, TOTAL_REQS); |
| 58 | + assert.notEqual(clientSessions[0].toString('hex'), |
| 59 | + clientSessions[1].toString('hex')); |
| 60 | +}); |
0 commit comments