Skip to content

Commit

Permalink
tls: deprecate Server.prototype.setOptions()
Browse files Browse the repository at this point in the history
This function was undocumented and only used in one place
throughout the codebase, plus a test.

PR-URL: #23820
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information
cjihrig committed Oct 25, 2018
1 parent d8924a0 commit 246a6fc
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
14 changes: 14 additions & 0 deletions doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -2279,6 +2279,20 @@ and `cluster` modules on Windows. The function is not generally useful and
is being removed. See discussion here:
https://github.com/nodejs/node/issues/18391
<a id="DEP0122"></a>
### DEP0122: tls Server.prototype.setOptions()
<!-- YAML
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/23820
description: Runtime deprecation.
-->
Type: Runtime
Please use `Server.prototype.setSecureContext()` instead.
[`--pending-deprecation`]: cli.html#cli_pending_deprecation
[`Buffer.allocUnsafeSlow(size)`]: buffer.html#buffer_class_method_buffer_allocunsafeslow_size
[`Buffer.from(array)`]: buffer.html#buffer_class_method_buffer_from_array
Expand Down
21 changes: 12 additions & 9 deletions lib/_tls_wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -827,16 +827,19 @@ function Server(options, listener) {
throw new ERR_INVALID_ARG_TYPE('options', 'Object', options);
}


this._contexts = [];
this.requestCert = options.requestCert === true;
this.rejectUnauthorized = options.rejectUnauthorized !== false;

// Handle option defaults:
this.setOptions(options);
if (options.sessionTimeout)
this.sessionTimeout = options.sessionTimeout;

if (options.ticketKeys)
this.ticketKeys = options.ticketKeys;

if (options.ALPNProtocols)
tls.convertALPNProtocols(options.ALPNProtocols, this);

// setSecureContext() overlaps with setOptions() quite a bit. setOptions()
// is an undocumented API that was probably never intended to be exposed
// publicly. Unfortunately, it would be a breaking change to just remove it,
// and there is at least one test that depends on it.
this.setSecureContext(options);

this[kHandshakeTimeout] = options.handshakeTimeout || (120 * 1000);
Expand Down Expand Up @@ -998,7 +1001,7 @@ Server.prototype.setTicketKeys = function setTicketKeys(keys) {
};


Server.prototype.setOptions = function(options) {
Server.prototype.setOptions = util.deprecate(function(options) {
this.requestCert = options.requestCert === true;
this.rejectUnauthorized = options.rejectUnauthorized !== false;

Expand Down Expand Up @@ -1033,7 +1036,7 @@ Server.prototype.setOptions = function(options) {
.digest('hex')
.slice(0, 32);
}
};
}, 'Server.prototype.setOptions() is deprecated', 'DEP0122');

// SNI Contexts High-Level API
Server.prototype.addContext = function(servername, context) {
Expand Down
3 changes: 3 additions & 0 deletions test/parallel/test-tls-server-setoptions-clientcertengine.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ const tls = require('tls');
{
const server = tls.createServer();
assert.strictEqual(server.clientCertEngine, undefined);
common.expectWarning('DeprecationWarning',
'Server.prototype.setOptions() is deprecated',
'DEP0122');
server.setOptions({ clientCertEngine: 'Cannonmouth' });
assert.strictEqual(server.clientCertEngine, 'Cannonmouth');
}

0 comments on commit 246a6fc

Please sign in to comment.