-
Notifications
You must be signed in to change notification settings - Fork 29.7k
/
test-https-agent-additional-options.js
81 lines (73 loc) · 2.26 KB
/
test-https-agent-additional-options.js
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const crypto = require('crypto');
const https = require('https');
const fixtures = require('../common/fixtures');
const options = {
key: fixtures.readKey('agent1-key.pem'),
cert: fixtures.readKey('agent1-cert.pem'),
ca: fixtures.readKey('ca1-cert.pem'),
minVersion: 'TLSv1.1',
ciphers: 'ALL@SECLEVEL=0'
};
const server = https.Server(options, (req, res) => {
res.writeHead(200);
res.end('hello world\n');
});
function getBaseOptions(port) {
return {
path: '/',
port: port,
ca: options.ca,
rejectUnauthorized: true,
servername: 'agent1',
ciphers: 'ALL@SECLEVEL=0'
};
}
const updatedValues = new Map([
['dhparam', fixtures.readKey('dh2048.pem')],
['ecdhCurve', 'secp384r1'],
['honorCipherOrder', true],
['minVersion', 'TLSv1.1'],
['maxVersion', 'TLSv1.3'],
['secureOptions', crypto.constants.SSL_OP_CIPHER_SERVER_PREFERENCE],
['secureProtocol', 'TLSv1_1_method'],
['sessionIdContext', 'sessionIdContext'],
]);
let value;
function variations(iter, port, cb) {
return common.mustCall((res) => {
res.resume();
https.globalAgent.once('free', common.mustCall(() => {
// Verify that the most recent connection is in the freeSockets pool.
const keys = Object.keys(https.globalAgent.freeSockets);
if (value) {
assert.ok(
keys.some((val) => val.startsWith(value.toString() + ':') ||
val.endsWith(':' + value.toString()) ||
val.includes(':' + value.toString() + ':')),
`missing value: ${value.toString()} in ${keys}`
);
}
const next = iter.next();
if (next.done) {
https.globalAgent.destroy();
server.close();
} else {
// Save `value` for check the next time.
const [key, val] = next.value;
value = val;
https.get({ ...getBaseOptions(port), [key]: val },
variations(iter, port, cb));
}
}));
});
}
server.listen(0, common.mustCall(() => {
const port = server.address().port;
https.globalAgent.keepAlive = true;
https.get(getBaseOptions(port), variations(updatedValues.entries(), port));
}));