• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3if (!common.hasCrypto)
4  common.skip('missing crypto');
5
6const assert = require('assert');
7const crypto = require('crypto');
8const https = require('https');
9const fixtures = require('../common/fixtures');
10
11const options = {
12  key: fixtures.readKey('agent1-key.pem'),
13  cert: fixtures.readKey('agent1-cert.pem'),
14  ca: fixtures.readKey('ca1-cert.pem'),
15  minVersion: 'TLSv1.1',
16};
17
18const server = https.Server(options, (req, res) => {
19  res.writeHead(200);
20  res.end('hello world\n');
21});
22
23function getBaseOptions(port) {
24  return {
25    path: '/',
26    port: port,
27    ca: options.ca,
28    rejectUnauthorized: true,
29    servername: 'agent1',
30  };
31}
32
33const updatedValues = new Map([
34  ['dhparam', fixtures.readKey('dh2048.pem')],
35  ['ecdhCurve', 'secp384r1'],
36  ['honorCipherOrder', true],
37  ['secureOptions', crypto.constants.SSL_OP_CIPHER_SERVER_PREFERENCE],
38  ['secureProtocol', 'TLSv1_1_method'],
39  ['sessionIdContext', 'sessionIdContext'],
40]);
41
42let value;
43function variations(iter, port, cb) {
44  return common.mustCall((res) => {
45    res.resume();
46    https.globalAgent.once('free', common.mustCall(() => {
47      // Verify that the most recent connection is in the freeSockets pool.
48      const keys = Object.keys(https.globalAgent.freeSockets);
49      if (value) {
50        assert.ok(
51          keys.some((val) => val.startsWith(value.toString() + ':') ||
52                            val.endsWith(':' + value.toString()) ||
53                            val.includes(':' + value.toString() + ':')),
54          `missing value: ${value.toString()} in ${keys}`
55        );
56      }
57      const next = iter.next();
58
59      if (next.done) {
60        https.globalAgent.destroy();
61        server.close();
62      } else {
63        // Save `value` for check the next time.
64        value = next.value.val;
65        const [key, val] = next.value;
66        https.get({ ...getBaseOptions(port), [key]: val },
67                  variations(iter, port, cb));
68      }
69    }));
70  });
71}
72
73server.listen(0, common.mustCall(() => {
74  const port = server.address().port;
75  https.globalAgent.keepAlive = true;
76  https.get(getBaseOptions(port), variations(updatedValues.entries(), port));
77}));
78