tls: check arg types of renegotiate() · nodejs/node@6b7c402 (original) (raw)

2 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -39,6 +39,7 @@ const { owner_symbol } = require('internal/async_hooks').symbols;
39 39 const { SecureContext: NativeSecureContext } = internalBinding('crypto');
40 40 const {
41 41 ERR_INVALID_ARG_TYPE,
42 +ERR_INVALID_CALLBACK,
42 43 ERR_MULTIPLE_CALLBACK,
43 44 ERR_SOCKET_CLOSED,
44 45 ERR_TLS_DH_PARAM_SIZE,
@@ -581,6 +582,11 @@ TLSSocket.prototype._init = function(socket, wrap) {
581 582 };
582 583
583 584 TLSSocket.prototype.renegotiate = function(options, callback) {
585 +if (options === null |
586 +throw new ERR_INVALID_ARG_TYPE('options', 'Object', options);
587 +if (callback != null && typeof callback !== 'function')
588 +throw new ERR_INVALID_CALLBACK();
589 +
584 590 if (this.destroyed)
585 591 return;
586 592
Original file line number Diff line number Diff line change
@@ -47,6 +47,22 @@ server.listen(0, common.mustCall(() => {
47 47 };
48 48 const client = tls.connect(options, common.mustCall(() => {
49 49 client.write('');
50 +
51 +common.expectsError(() => client.renegotiate(), {
52 +code: 'ERR_INVALID_ARG_TYPE',
53 +type: TypeError,
54 +});
55 +
56 +common.expectsError(() => client.renegotiate(common.mustNotCall()), {
57 +code: 'ERR_INVALID_ARG_TYPE',
58 +type: TypeError,
59 +});
60 +
61 +common.expectsError(() => client.renegotiate({}, false), {
62 +code: 'ERR_INVALID_CALLBACK',
63 +type: TypeError,
64 +});
65 +
50 66 // Negotiation is still permitted for this first
51 67 // attempt. This should succeed.
52 68 let ok = client.renegotiate(options, common.mustCall((err) => {