From 4ba80ce0e508840a4e4e6436363a39ac90944b0b Mon Sep 17 00:00:00 2001 From: davidmarkclements Date: Thu, 12 Apr 2018 22:55:51 +0200 Subject: [PATCH 1/2] errors: alter and test ERR_TLS_REQUIRED_SERVER_NAME changes the base instance for ERR_TLS_REQUIRED_SERVER_NAME from Error to TypeError as a more accurate representation of the error and adds a unit test for missing servername input that triggers this error in Server.prototype.addContext --- lib/internal/errors.js | 4 +--- test/parallel/test-tls-sni-server-client.js | 7 +++++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/internal/errors.js b/lib/internal/errors.js index 5fec67d6c721af..c1879d3f93d9e8 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -864,10 +864,8 @@ E('ERR_TLS_HANDSHAKE_TIMEOUT', 'TLS handshake timeout', Error); E('ERR_TLS_RENEGOTIATE', 'Attempt to renegotiate TLS session failed', Error); E('ERR_TLS_RENEGOTIATION_DISABLED', 'TLS session renegotiation disabled for this socket', Error); - -// This should probably be a `TypeError`. E('ERR_TLS_REQUIRED_SERVER_NAME', - '"servername" is required parameter for Server.addContext', Error); + '"servername" is a required parameter', TypeError); E('ERR_TLS_SESSION_ATTACK', 'TLS session renegotiation attack detected', Error); E('ERR_TLS_SNI_FROM_SERVER', 'Cannot issue SNI from a TLS server-side socket', Error); diff --git a/test/parallel/test-tls-sni-server-client.js b/test/parallel/test-tls-sni-server-client.js index 073e95988a3a08..bc5f7fca75281c 100644 --- a/test/parallel/test-tls-sni-server-client.js +++ b/test/parallel/test-tls-sni-server-client.js @@ -84,6 +84,13 @@ const clientsOptions = [{ const serverResults = []; const clientResults = []; +// check for throwing case where servername is not supplied +common.expectsError(tls.createServer(serverOptions, () => {}).addContext, { + type: TypeError, + code: 'ERR_TLS_REQUIRED_SERVER_NAME', + message: '"servername" is a required parameter' +}); + const server = tls.createServer(serverOptions, function(c) { serverResults.push(c.servername); }); From 4f4d2faea3f336aa4b93bf048359118557e893e3 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Tue, 13 Nov 2018 21:50:39 -0800 Subject: [PATCH 2/2] test: remove ERR_TLS_REQUIRED_SERVER_NAME Replace ERR_TLS_REQUIRED_SERVER_NAME with ERR_MISSING_ARGS. Update tls.md documentation so that argument name in documentation reflects the argument name in code. --- doc/api/errors.md | 15 +++++++++------ doc/api/tls.md | 6 +++--- lib/_tls_wrap.js | 4 ++-- test/parallel/test-tls-sni-server-client.js | 4 ++-- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/doc/api/errors.md b/doc/api/errors.md index 500fb7801b61fd..56032ca3ad3359 100644 --- a/doc/api/errors.md +++ b/doc/api/errors.md @@ -1665,12 +1665,6 @@ An attempt to renegotiate the TLS session failed. An attempt was made to renegotiate TLS on a socket instance with TLS disabled. - -### ERR_TLS_REQUIRED_SERVER_NAME - -While using TLS, the `server.addContext()` method was called without providing -a hostname in the first parameter. - ### ERR_TLS_SESSION_ATTACK @@ -2030,6 +2024,15 @@ removed: v10.0.0 Used when a TLS renegotiation request has failed in a non-specific way. + +### ERR_TLS_REQUIRED_SERVER_NAME + + +While using TLS, the `server.addContext()` method was called without providing +a hostname in the first parameter. + ### ERR_UNKNOWN_BUILTIN_MODULE -* `hostname` {string} A SNI hostname or wildcard (e.g. `'*'`) +* `servername` {string} A SNI hostname or wildcard (e.g. `'*'`) * `context` {Object} An object containing any of the possible properties from the [`tls.createSecureContext()`][] `options` arguments (e.g. `key`, `cert`, `ca`, etc). The `server.addContext()` method adds a secure context that will be used if -the client request's SNI name matches the supplied `hostname` (or wildcard). +the client request's SNI name matches the supplied `severname` (or wildcard). ### server.address()