-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
errors: alter and test ERR_TLS_REQUIRED_SERVER_NAME #19988
Conversation
// check for throwing case where servername is not supplied | ||
common.expectsError(tls.createServer(serverOptions, () => {}).addContext, { | ||
type: TypeError, | ||
code: 'ERR_TLS_REQUIRED_SERVER_NAME', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not ERR_MISSING_ARGS
?
common.expectsError(tls.createServer(serverOptions, () => {}).addContext, { | ||
type: TypeError, | ||
code: 'ERR_TLS_REQUIRED_SERVER_NAME', | ||
message: '"servername" is a required parameter' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The argument is called hostname
in the docs, not sure what to use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normally the variable name in the source code. I see the point here about using the documentation name though...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If docs and source code disagree, one or the other should be changed so they are in agreement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be great to actually use ERR_MISSING_ARGS
instead.
Ping @davidmarkclements |
Anyone interested in fixing this up and getting it landed? Or should this be closed? |
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
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.
I think I've made the necessary changes such that this can land. @BridgeAR PTAL |
E('ERR_TLS_REQUIRED_SERVER_NAME', | ||
'"servername" is required parameter for Server.addContext', Error); | ||
'"servername" is a required parameter', TypeError); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is now unused and should be removed.
@Trott with the code removed it's LGTM. |
<!-- YAML | ||
added: v0.5.3 | ||
--> | ||
|
||
* `hostname` {string} A SNI hostname or wildcard (e.g. `'*'`) | ||
* `servername` {string} A SNI hostname or wildcard (e.g. `'*'`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"hostname" --> "server name", consistent with https://github.com/nodejs/node/blob/master/doc/api/tls.md#event-secureconnection
a string containing the server name requested via SNI.
* `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). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"severname" -> "servername" (typo)
@@ -84,6 +84,13 @@ const clientsOptions = [{ | |||
const serverResults = []; | |||
const clientResults = []; | |||
|
|||
// check for throwing case where servername is not supplied |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Puncutate the comment, please (leading capital, trailing period).
@@ -2030,6 +2024,15 @@ removed: v10.0.0 | |||
|
|||
Used when a TLS renegotiation request has failed in a non-specific way. | |||
|
|||
<a id="ERR_TLS_REQUIRED_SERVER_NAME"></a> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be removed now, as its no longer used.
@@ -1051,7 +1051,7 @@ Server.prototype.setOptions = util.deprecate(function(options) { | |||
// SNI Contexts High-Level API | |||
Server.prototype.addContext = function(servername, context) { | |||
if (!servername) { | |||
throw new ERR_TLS_REQUIRED_SERVER_NAME(); | |||
throw new ERR_MISSING_ARGS('servername'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the convention here would be:
if (typeof servername !== 'string')
throw new ERR_INVALID_ARG_TYPE('servername', 'string', arg);
to test both the presence of the arg, but also its type. If it's not a string it will throw anyway now just below on the call to .replace()
, but throwing a more descriptive error makes it look less like a node.js bug.
Closing due to long inactivity. @davidmarkclements please open a new PR in case you would like to continue working on this. |
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
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes