Skip to content

Commit d905c61

Browse files
deokjinkimUlisesGascon
authored andcommitted
tls: use validateFunction for options.SNICallback
If user uses invalid type for `options.SNICallback` in TLSSocket(), it's not internal issue of Node.js. So validateFunction() is more proper than assert(). PR-URL: #50530 Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 3844af2 commit d905c61

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

lib/_tls_wrap.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,7 @@ TLSSocket.prototype._init = function(socket, wrap) {
909909
options.SNICallback &&
910910
(options.SNICallback !== SNICallback ||
911911
(options.server && options.server._contexts.length))) {
912-
assert(typeof options.SNICallback === 'function');
912+
validateFunction(options.SNICallback, 'options.SNICallback');
913913
this._SNICallback = options.SNICallback;
914914
ssl.enableCertCb();
915915
}

test/parallel/test-tls-snicallback-error.js

+16-6
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,21 @@ if (!common.hasCrypto)
44
common.skip('missing crypto');
55

66
const assert = require('assert');
7+
const net = require('net');
78
const tls = require('tls');
89

9-
['fhqwhgads', 42, {}, []].forEach((testValue) => {
10-
assert.throws(
11-
() => { tls.createServer({ SNICallback: testValue }); },
12-
{ code: 'ERR_INVALID_ARG_TYPE', message: /\boptions\.SNICallback\b/ }
13-
);
14-
});
10+
for (const SNICallback of ['fhqwhgads', 42, {}, []]) {
11+
assert.throws(() => {
12+
tls.createServer({ SNICallback });
13+
}, {
14+
code: 'ERR_INVALID_ARG_TYPE',
15+
name: 'TypeError',
16+
});
17+
18+
assert.throws(() => {
19+
new tls.TLSSocket(new net.Socket(), { isServer: true, SNICallback });
20+
}, {
21+
code: 'ERR_INVALID_ARG_TYPE',
22+
name: 'TypeError',
23+
});
24+
}

0 commit comments

Comments
 (0)