Skip to content

Commit 73cd279

Browse files
danbevMylesBorins
authored andcommitted
tls: specify options.name in validateKeyCert
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 <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent cc09d7e commit 73cd279

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

lib/_tls_common.js

+8-9
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,10 @@ function SecureContext(secureProtocol, secureOptions, context) {
5656
if (secureOptions) this.context.setOptions(secureOptions);
5757
}
5858

59-
function validateKeyCert(value, type) {
59+
function validateKeyCert(name, value) {
6060
if (typeof value !== 'string' && !isArrayBufferView(value)) {
6161
throw new ERR_INVALID_ARG_TYPE(
62-
// TODO(BridgeAR): Change this to `options.${type}`
63-
type,
62+
`options.${name}`,
6463
['string', 'Buffer', 'TypedArray', 'DataView'],
6564
value
6665
);
@@ -100,11 +99,11 @@ exports.createSecureContext = function createSecureContext(options, context) {
10099
if (Array.isArray(ca)) {
101100
for (i = 0; i < ca.length; ++i) {
102101
val = ca[i];
103-
validateKeyCert(val, 'ca');
102+
validateKeyCert('ca', val);
104103
c.context.addCACert(val);
105104
}
106105
} else {
107-
validateKeyCert(ca, 'ca');
106+
validateKeyCert('ca', ca);
108107
c.context.addCACert(ca);
109108
}
110109
} else {
@@ -116,11 +115,11 @@ exports.createSecureContext = function createSecureContext(options, context) {
116115
if (Array.isArray(cert)) {
117116
for (i = 0; i < cert.length; ++i) {
118117
val = cert[i];
119-
validateKeyCert(val, 'cert');
118+
validateKeyCert('cert', val);
120119
c.context.setCert(val);
121120
}
122121
} else {
123-
validateKeyCert(cert, 'cert');
122+
validateKeyCert('cert', cert);
124123
c.context.setCert(cert);
125124
}
126125
}
@@ -137,11 +136,11 @@ exports.createSecureContext = function createSecureContext(options, context) {
137136
val = key[i];
138137
// eslint-disable-next-line eqeqeq
139138
const pem = (val != undefined && val.pem !== undefined ? val.pem : val);
140-
validateKeyCert(pem, 'key');
139+
validateKeyCert('key', pem);
141140
c.context.setKey(pem, val.passphrase || passphrase);
142141
}
143142
} else {
144-
validateKeyCert(key, 'key');
143+
validateKeyCert('key', key);
145144
c.context.setKey(key, passphrase);
146145
}
147146
}

test/parallel/test-https-options-boolean-check.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ const caArrDataView = toDataView(caCert);
8888
}, {
8989
code: 'ERR_INVALID_ARG_TYPE',
9090
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
91-
message: 'The "key" argument must be one of type string, Buffer, ' +
91+
message: 'The "options.key" property must be one of type string, Buffer, ' +
9292
`TypedArray, or DataView. Received type ${type}`
9393
});
9494
});
@@ -113,8 +113,8 @@ const caArrDataView = toDataView(caCert);
113113
}, {
114114
code: 'ERR_INVALID_ARG_TYPE',
115115
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
116-
message: 'The "cert" argument must be one of type string, Buffer, ' +
117-
`TypedArray, or DataView. Received type ${type}`
116+
message: 'The "options.cert" property must be one of type string, Buffer,' +
117+
` TypedArray, or DataView. Received type ${type}`
118118
});
119119
});
120120

@@ -147,7 +147,7 @@ const caArrDataView = toDataView(caCert);
147147
}, {
148148
code: 'ERR_INVALID_ARG_TYPE',
149149
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
150-
message: 'The "ca" argument must be one of type string, Buffer, ' +
150+
message: 'The "options.ca" property must be one of type string, Buffer, ' +
151151
`TypedArray, or DataView. Received type ${type}`
152152
});
153153
});

test/parallel/test-tls-options-boolean-check.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ const caArrDataView = toDataView(caCert);
8686
}, {
8787
code: 'ERR_INVALID_ARG_TYPE',
8888
type: TypeError,
89-
message: 'The "key" argument must be one of type string, Buffer, ' +
89+
message: 'The "options.key" property must be one of type string, Buffer, ' +
9090
`TypedArray, or DataView. Received type ${type}`
9191
});
9292
});
@@ -111,8 +111,8 @@ const caArrDataView = toDataView(caCert);
111111
}, {
112112
code: 'ERR_INVALID_ARG_TYPE',
113113
type: TypeError,
114-
message: 'The "cert" argument must be one of type string, Buffer, ' +
115-
`TypedArray, or DataView. Received type ${type}`
114+
message: 'The "options.cert" property must be one of type string, Buffer,' +
115+
` TypedArray, or DataView. Received type ${type}`
116116
});
117117
});
118118

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

0 commit comments

Comments
 (0)