GeezerVison is showing github.com — tls: use `validateFunction` for `options.SNICallback` · nodejs/node@d905c61
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/_tls_wrap.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -909,7 +909,7 @@ TLSSocket.prototype._init = function(socket, wrap) { |
909 | 909 | options.SNICallback && |
910 | 910 | (options.SNICallback !== SNICallback || |
911 | 911 | (options.server && options.server._contexts.length))) { |
912 | | - assert(typeof options.SNICallback === 'function'); |
| 912 | + validateFunction(options.SNICallback, 'options.SNICallback'); |
913 | 913 | this._SNICallback = options.SNICallback; |
914 | 914 | ssl.enableCertCb(); |
915 | 915 | } |
|
Collapse file
Copy file name to clipboardExpand all lines: test/parallel/test-tls-snicallback-error.js +16-6Lines changed: 16 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -4,11 +4,21 @@ if (!common.hasCrypto) |
4 | 4 | common.skip('missing crypto'); |
5 | 5 |
|
6 | 6 | const assert = require('assert'); |
| 7 | +const net = require('net'); |
7 | 8 | const tls = require('tls'); |
8 | 9 |
|
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 | +} |