Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions lib/https.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ const {
ArrayPrototypeSplice,
ArrayPrototypeUnshift,
FunctionPrototypeCall,
JSONStringify,
NumberParseInt,
ObjectAssign,
ObjectSetPrototypeOf,
Expand Down Expand Up @@ -606,7 +605,7 @@ Agent.prototype.getName = function getName(options = kEmptyObject) {

name += ':';
if (options.ciphers)
name += options.ciphers;
name += getTlsOptionKey(options.ciphers);

name += ':';
if (options.key) {
Expand All @@ -622,51 +621,51 @@ Agent.prototype.getName = function getName(options = kEmptyObject) {

name += ':';
if (options.rejectUnauthorized !== undefined)
name += options.rejectUnauthorized;
name += getTlsOptionKey(options.rejectUnauthorized);

name += ':';
if (options.servername && options.servername !== options.host)
name += options.servername;
name += getTlsOptionKey(options.servername);

name += ':';
if (options.minVersion)
name += options.minVersion;
name += getTlsOptionKey(options.minVersion);

name += ':';
if (options.maxVersion)
name += options.maxVersion;
name += getTlsOptionKey(options.maxVersion);

name += ':';
if (options.secureProtocol)
name += options.secureProtocol;
name += getTlsOptionKey(options.secureProtocol);

name += ':';
if (options.crl)
name += getTlsOptionKey(options.crl);

name += ':';
if (options.honorCipherOrder !== undefined)
name += options.honorCipherOrder;
name += getTlsOptionKey(options.honorCipherOrder);

name += ':';
if (options.ecdhCurve)
name += options.ecdhCurve;
name += getTlsOptionKey(options.ecdhCurve);

name += ':';
if (options.dhparam)
name += options.dhparam;
name += getTlsOptionKey(options.dhparam);

name += ':';
if (options.secureOptions !== undefined)
name += options.secureOptions;
name += getTlsOptionKey(options.secureOptions);

name += ':';
if (options.sessionIdContext)
name += options.sessionIdContext;
name += getTlsOptionKey(options.sessionIdContext);

name += ':';
if (options.sigalgs)
name += JSONStringify(options.sigalgs);
name += getTlsOptionKey(options.sigalgs);

name += ':';
if (options.secureContext)
Expand Down
27 changes: 14 additions & 13 deletions test/parallel/test-https-agent-additional-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,30 +56,29 @@ const updatedValues = new Map([
['sessionIdContext', 'sessionIdContext'],
]);

let value;
// Every variation must be pooled under its own name, and repeating a
// variation must reuse the name it had.
const requested = new Set();
let expectedNames = 1;
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.
// Verify that the connections are in the freeSockets pool, one name for
// each distinct set of options.
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}`
);
}
assert.strictEqual(keys.length, expectedNames, `unexpected ${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;
if (!requested.has(key)) {
requested.add(key);
expectedNames++;
}
https.get({ ...getBaseOptions(port), [key]: val },
variations(iter, port, cb));
}
Expand All @@ -90,5 +89,7 @@ function 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));
const all = [...updatedValues.entries()];
const entries = [...all, all[0]];
https.get(getBaseOptions(port), variations(entries.values(), port));
}));
47 changes: 43 additions & 4 deletions test/parallel/test-https-agent-getname.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ const options = {

assert.strictEqual(
agent.getName(options),
'0.0.0.0:443:192.168.1.1:s2:ca:s4:cert:ciphers:s3:key::' +
's3:pfx::false:localhost:::secureProtocol:' +
'a3:7:v1:Yw==:7:v1:cg==:7:v1:bA==:false:ecdhCurve:dhparam:0:' +
'sessionIdContext:"sigalgs":::::::::'
'0.0.0.0:443:192.168.1.1:s2:ca:s4:cert:s7:ciphers:s3:key::' +
's3:pfx::b5:false:s9:localhost:::s14:secureProtocol:' +
'a3:7:v1:Yw==:7:v1:cg==:7:v1:bA==:b5:false:s9:ecdhCurve:s7:dhparam:' +
'n1:0:s16:sessionIdContext:s7:sigalgs:::::::::'
);

{
Expand Down Expand Up @@ -156,4 +156,43 @@ assert.strictEqual(
agent.getName({ ...baseOptions, session: Buffer.from('one') }),
agent.getName({ ...baseOptions, session: Buffer.from('two') })
);

// Values containing the field delimiter must not shift across fields.
const collisions = [
[{ servername: 'a:b' }, { servername: 'a', minVersion: 'b:' }],
[{ minVersion: 'a:b' }, { minVersion: 'a', maxVersion: 'b:' }],
[{ maxVersion: 'a:b' }, { maxVersion: 'a', secureProtocol: 'b:' }],
[{ rejectUnauthorized: 'false:a' },
{ rejectUnauthorized: 'false', servername: 'a:' }],
[{ honorCipherOrder: 'a:b' }, { honorCipherOrder: 'a', ecdhCurve: 'b:' }],
[{ ecdhCurve: 'a:b' }, { ecdhCurve: 'a', dhparam: 'b:' }],
[{ dhparam: 'a:b' }, { dhparam: 'a', secureOptions: 'b:' }],
[{ secureOptions: '1:a' }, { secureOptions: 1, sessionIdContext: 'a:' }],
[{ sessionIdContext: 'a:b' }, { sessionIdContext: 'a', sigalgs: 'b:' }],
[{ sigalgs: ['a:b'] }, { sigalgs: ['a', 'b'] }],
[{ servername: 'a', rejectUnauthorized: false, ecdhCurve: 'P-256:P-384' },
{ rejectUnauthorized: 'false:a', honorCipherOrder: 'P-256',
ecdhCurve: 'P-384' }],
];
for (const [first, second] of collisions) {
assert.notStrictEqual(
agent.getName({ ...baseOptions, ...first }),
agent.getName({ ...baseOptions, ...second }),
`${JSON.stringify(first)} collides with ${JSON.stringify(second)}`
);
}

// The type of a value is part of its key.
assert.notStrictEqual(
agent.getName({ ...baseOptions, rejectUnauthorized: false }),
agent.getName({ ...baseOptions, rejectUnauthorized: 'false' })
);

assert.notStrictEqual(
agent.getName({ ...baseOptions, dhparam: new DataView(new ArrayBuffer(2)) }),
agent.getName({
...baseOptions,
dhparam: new DataView(new Uint8Array([1, 2]).buffer),
})
);
}
Loading