Skip to content

Commit

Permalink
tls: specify options.name in validateKeyCert
Browse files Browse the repository at this point in the history
This commit addresses a TODO added by Ruben Bridgewater in commit
c6b6c92 ("lib: always show
ERR_INVALID_ARG_TYPE received part") which was to prefix the name of
the invalid argument with 'options.'.

This commit also switches the order of the parameters to validateKeyCert
to be consistent with other validators.

PR-URL: #20284
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
danbev authored and MylesBorins committed May 4, 2018
1 parent cc09d7e commit 73cd279
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
17 changes: 8 additions & 9 deletions lib/_tls_common.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,10 @@ function SecureContext(secureProtocol, secureOptions, context) {
if (secureOptions) this.context.setOptions(secureOptions);
}

function validateKeyCert(value, type) {
function validateKeyCert(name, value) {
if (typeof value !== 'string' && !isArrayBufferView(value)) {
throw new ERR_INVALID_ARG_TYPE(
// TODO(BridgeAR): Change this to `options.${type}`
type,
`options.${name}`,
['string', 'Buffer', 'TypedArray', 'DataView'],
value
);
Expand Down Expand Up @@ -100,11 +99,11 @@ exports.createSecureContext = function createSecureContext(options, context) {
if (Array.isArray(ca)) {
for (i = 0; i < ca.length; ++i) {
val = ca[i];
validateKeyCert(val, 'ca');
validateKeyCert('ca', val);
c.context.addCACert(val);
}
} else {
validateKeyCert(ca, 'ca');
validateKeyCert('ca', ca);
c.context.addCACert(ca);
}
} else {
Expand All @@ -116,11 +115,11 @@ exports.createSecureContext = function createSecureContext(options, context) {
if (Array.isArray(cert)) {
for (i = 0; i < cert.length; ++i) {
val = cert[i];
validateKeyCert(val, 'cert');
validateKeyCert('cert', val);
c.context.setCert(val);
}
} else {
validateKeyCert(cert, 'cert');
validateKeyCert('cert', cert);
c.context.setCert(cert);
}
}
Expand All @@ -137,11 +136,11 @@ exports.createSecureContext = function createSecureContext(options, context) {
val = key[i];
// eslint-disable-next-line eqeqeq
const pem = (val != undefined && val.pem !== undefined ? val.pem : val);
validateKeyCert(pem, 'key');
validateKeyCert('key', pem);
c.context.setKey(pem, val.passphrase || passphrase);
}
} else {
validateKeyCert(key, 'key');
validateKeyCert('key', key);
c.context.setKey(key, passphrase);
}
}
Expand Down
8 changes: 4 additions & 4 deletions test/parallel/test-https-options-boolean-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const caArrDataView = toDataView(caCert);
}, {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
message: 'The "key" argument must be one of type string, Buffer, ' +
message: 'The "options.key" property must be one of type string, Buffer, ' +
`TypedArray, or DataView. Received type ${type}`
});
});
Expand All @@ -113,8 +113,8 @@ const caArrDataView = toDataView(caCert);
}, {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
message: 'The "cert" argument must be one of type string, Buffer, ' +
`TypedArray, or DataView. Received type ${type}`
message: 'The "options.cert" property must be one of type string, Buffer,' +
` TypedArray, or DataView. Received type ${type}`
});
});

Expand Down Expand Up @@ -147,7 +147,7 @@ const caArrDataView = toDataView(caCert);
}, {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
message: 'The "ca" argument must be one of type string, Buffer, ' +
message: 'The "options.ca" property must be one of type string, Buffer, ' +
`TypedArray, or DataView. Received type ${type}`
});
});
8 changes: 4 additions & 4 deletions test/parallel/test-tls-options-boolean-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const caArrDataView = toDataView(caCert);
}, {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "key" argument must be one of type string, Buffer, ' +
message: 'The "options.key" property must be one of type string, Buffer, ' +
`TypedArray, or DataView. Received type ${type}`
});
});
Expand All @@ -111,8 +111,8 @@ const caArrDataView = toDataView(caCert);
}, {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "cert" argument must be one of type string, Buffer, ' +
`TypedArray, or DataView. Received type ${type}`
message: 'The "options.cert" property must be one of type string, Buffer,' +
` TypedArray, or DataView. Received type ${type}`
});
});

Expand Down Expand Up @@ -145,7 +145,7 @@ const caArrDataView = toDataView(caCert);
}, {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "ca" argument must be one of type string, Buffer, ' +
message: 'The "options.ca" property must be one of type string, Buffer, ' +
`TypedArray, or DataView. Received type ${type}`
});
});
Expand Down

0 comments on commit 73cd279

Please sign in to comment.