tls: use validateFunction for options.checkServerIdentity
If user uses invalid type for `options.checkServerIdentity` in tls.connect(), it's not internal issue of Node.js. So validateFunction() is more proper than assert(). Fixes: https://github.com/nodejs/node/issues/49839 PR-URL: https://github.com/nodejs/node/pull/49896 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
This commit is contained in:
parent
e6e320ecc7
commit
092fb9f541
@ -1738,7 +1738,7 @@ exports.connect = function connect(...args) {
|
|||||||
if (!options.keepAlive)
|
if (!options.keepAlive)
|
||||||
options.singleUse = true;
|
options.singleUse = true;
|
||||||
|
|
||||||
assert(typeof options.checkServerIdentity === 'function');
|
validateFunction(options.checkServerIdentity, 'options.checkServerIdentity');
|
||||||
assert(typeof options.minDHSize === 'number',
|
assert(typeof options.minDHSize === 'number',
|
||||||
'options.minDHSize is not a number: ' + options.minDHSize);
|
'options.minDHSize is not a number: ' + options.minDHSize);
|
||||||
assert(options.minDHSize > 0,
|
assert(options.minDHSize > 0,
|
||||||
|
@ -135,3 +135,12 @@ assert.throws(() => { tls.createSecureContext({ maxVersion: 'fhqwhgads' }); },
|
|||||||
code: 'ERR_TLS_INVALID_PROTOCOL_VERSION',
|
code: 'ERR_TLS_INVALID_PROTOCOL_VERSION',
|
||||||
name: 'TypeError'
|
name: 'TypeError'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
for (const checkServerIdentity of [undefined, null, 1, true]) {
|
||||||
|
assert.throws(() => {
|
||||||
|
tls.connect({ checkServerIdentity });
|
||||||
|
}, {
|
||||||
|
code: 'ERR_INVALID_ARG_TYPE',
|
||||||
|
name: 'TypeError',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user