Skip to content
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

Closed
wants to merge 2 commits into from
Closed

errors: alter and test ERR_TLS_REQUIRED_SERVER_NAME #19988

wants to merge 2 commits into from

Conversation

davidmarkclements
Copy link
Member

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), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines

@nodejs-github-bot nodejs-github-bot added the errors Issues and PRs related to JavaScript errors originated in Node.js core. label Apr 12, 2018
@BridgeAR BridgeAR added the semver-major PRs that contain breaking changes and should be released in the next major version. label Apr 13, 2018
@BridgeAR BridgeAR requested a review from a team April 13, 2018 19:15
@BridgeAR
Copy link
Member

@BridgeAR BridgeAR added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Apr 13, 2018
// check for throwing case where servername is not supplied
common.expectsError(tls.createServer(serverOptions, () => {}).addContext, {
type: TypeError,
code: 'ERR_TLS_REQUIRED_SERVER_NAME',
Copy link
Member

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'
Copy link
Member

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.

Copy link
Member

@BridgeAR BridgeAR Apr 15, 2018

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...

Copy link
Member

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.

Copy link
Member

@BridgeAR BridgeAR left a 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.

@BridgeAR BridgeAR removed the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Apr 15, 2018
@BridgeAR
Copy link
Member

Ping @davidmarkclements

@jasnell jasnell added the stalled Issues and PRs that are stalled. label Sep 10, 2018
@Trott
Copy link
Member

Trott commented Nov 14, 2018

Anyone interested in fixing this up and getting it landed? Or should this be closed?

davidmarkclements and others added 2 commits November 13, 2018 21:42
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.
@Trott
Copy link
Member

Trott commented Nov 14, 2018

I think I've made the necessary changes such that this can land. @BridgeAR PTAL

@Trott
Copy link
Member

Trott commented Nov 14, 2018

E('ERR_TLS_REQUIRED_SERVER_NAME',
'"servername" is required parameter for Server.addContext', Error);
'"servername" is a required parameter', TypeError);
Copy link
Member

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.

@BridgeAR
Copy link
Member

@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. `'*'`)
Copy link
Contributor

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).
Copy link
Contributor

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
Copy link
Contributor

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>
Copy link
Contributor

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');
Copy link
Contributor

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.

@BridgeAR
Copy link
Member

Closing due to long inactivity. @davidmarkclements please open a new PR in case you would like to continue working on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
errors Issues and PRs related to JavaScript errors originated in Node.js core. semver-major PRs that contain breaking changes and should be released in the next major version. stalled Issues and PRs that are stalled.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants