summaryrefslogtreecommitdiff
path: root/test/parallel/test-https-agent-disable-session-reuse.js
blob: dc9878d4a1c1ed06331f335d97be5433c577c148 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
'use strict';
const common = require('../common');
const assert = require('assert');

if (!common.hasCrypto) {
  common.skip('missing crypto');
  return;
}

const TOTAL_REQS = 2;

const https = require('https');

const fs = require('fs');

const options = {
  key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'),
  cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem')
};

const clientSessions = [];
var serverRequests = 0;

const agent = new https.Agent({
  maxCachedSessions: 0
});

const server = https.createServer(options, function(req, res) {
  serverRequests++;
  res.end('ok');
}).listen(0, function() {
  var waiting = TOTAL_REQS;
  function request() {
    const options = {
      agent: agent,
      port: server.address().port,
      rejectUnauthorized: false
    };

    https.request(options, function(res) {
      clientSessions.push(res.socket.getSession());

      res.resume();
      res.on('end', function() {
        if (--waiting !== 0)
          return request();
        server.close();
      });
    }).end();
  }
  request();
});

process.on('exit', function() {
  assert.equal(serverRequests, TOTAL_REQS);
  assert.equal(clientSessions.length, TOTAL_REQS);
  assert.notEqual(clientSessions[0].toString('hex'),
                  clientSessions[1].toString('hex'));
});