diff --git a/lib/_tls_wrap.js b/lib/_tls_wrap.js index 9cf3fc41485080..e022ed874d5610 100644 --- a/lib/_tls_wrap.js +++ b/lib/_tls_wrap.js @@ -909,7 +909,7 @@ TLSSocket.prototype._init = function(socket, wrap) { options.SNICallback && (options.SNICallback !== SNICallback || (options.server && options.server._contexts.length))) { - assert(typeof options.SNICallback === 'function'); + validateFunction(options.SNICallback, 'options.SNICallback'); this._SNICallback = options.SNICallback; ssl.enableCertCb(); } diff --git a/test/parallel/test-tls-snicallback-error.js b/test/parallel/test-tls-snicallback-error.js index 1e1c82225309b4..aac7cb9f96704a 100644 --- a/test/parallel/test-tls-snicallback-error.js +++ b/test/parallel/test-tls-snicallback-error.js @@ -4,11 +4,21 @@ if (!common.hasCrypto) common.skip('missing crypto'); const assert = require('assert'); +const net = require('net'); const tls = require('tls'); -['fhqwhgads', 42, {}, []].forEach((testValue) => { - assert.throws( - () => { tls.createServer({ SNICallback: testValue }); }, - { code: 'ERR_INVALID_ARG_TYPE', message: /\boptions\.SNICallback\b/ } - ); -}); +for (const SNICallback of ['fhqwhgads', 42, {}, []]) { + assert.throws(() => { + tls.createServer({ SNICallback }); + }, { + code: 'ERR_INVALID_ARG_TYPE', + name: 'TypeError', + }); + + assert.throws(() => { + new tls.TLSSocket(new net.Socket(), { isServer: true, SNICallback }); + }, { + code: 'ERR_INVALID_ARG_TYPE', + name: 'TypeError', + }); +}