summaryrefslogtreecommitdiff
path: root/test/parallel/test-tls-options-boolean-check.js
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2017-09-01 16:14:56 +0200
committerMichael Dawson <michael_dawson@ca.ibm.com>2017-09-05 16:47:55 -0400
commit1403d28e7ded280e7582daa6e999164588d2234e (patch)
tree2987731226da0e733c1ccbaf8041e5d5badff1b8 /test/parallel/test-tls-options-boolean-check.js
parentdc7f03c897b408c3ac521c491c245a93449f968a (diff)
downloadandroid-node-v8-1403d28e7ded280e7582daa6e999164588d2234e.tar.gz
android-node-v8-1403d28e7ded280e7582daa6e999164588d2234e.tar.bz2
android-node-v8-1403d28e7ded280e7582daa6e999164588d2234e.zip
tls: re-allow falsey option values
5723c4c5f06f138 was an unintentional breaking change in that it changed the behaviour of `tls.createSecureContext()` to throw on false-y input rather than ignoring it. This breaks real-world applications like `npm`. This restores the previous behaviour. PR-URL: https://github.com/nodejs/node/pull/15131 Ref: https://github.com/nodejs/node/pull/15053 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com> Reviewed-By: MichaƫZasso <targos@protonmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
Diffstat (limited to 'test/parallel/test-tls-options-boolean-check.js')
-rw-r--r--test/parallel/test-tls-options-boolean-check.js64
1 files changed, 41 insertions, 23 deletions
diff --git a/test/parallel/test-tls-options-boolean-check.js b/test/parallel/test-tls-options-boolean-check.js
index 4cc0aaf377..e866f5a069 100644
--- a/test/parallel/test-tls-options-boolean-check.js
+++ b/test/parallel/test-tls-options-boolean-check.js
@@ -64,12 +64,9 @@ const invalidCertRE = /^The "cert" argument must be one of type string, Buffer,
[false, [certStr, certStr2]],
[[{ pem: keyBuff }], false],
[[{ pem: keyBuff }, { pem: keyBuff }], false]
-].map((params) => {
+].map(([key, cert]) => {
assert.doesNotThrow(() => {
- tls.createServer({
- key: params[0],
- cert: params[1]
- });
+ tls.createServer({ key, cert });
});
});
@@ -100,16 +97,13 @@ const invalidCertRE = /^The "cert" argument must be one of type string, Buffer,
[[keyStr, keyStr2], [true, false], invalidCertRE],
[[keyStr, keyStr2], true, invalidCertRE],
[true, [certBuff, certBuff2], invalidKeyRE]
-].map((params) => {
+].map(([key, cert, message]) => {
assert.throws(() => {
- tls.createServer({
- key: params[0],
- cert: params[1]
- });
+ tls.createServer({ key, cert });
}, common.expectsError({
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: params[2]
+ message
}));
});
@@ -123,13 +117,9 @@ const invalidCertRE = /^The "cert" argument must be one of type string, Buffer,
[keyBuff, certBuff, caArrBuff],
[keyBuff, certBuff, caArrDataView],
[keyBuff, certBuff, false],
-].map((params) => {
+].map(([key, cert, ca]) => {
assert.doesNotThrow(() => {
- tls.createServer({
- key: params[0],
- cert: params[1],
- ca: params[2]
- });
+ tls.createServer({ key, cert, ca });
});
});
@@ -141,16 +131,44 @@ const invalidCertRE = /^The "cert" argument must be one of type string, Buffer,
[keyBuff, certBuff, 1],
[keyBuff, certBuff, true],
[keyBuff, certBuff, [caCert, true]]
-].map((params) => {
+].map(([key, cert, ca]) => {
assert.throws(() => {
- tls.createServer({
- key: params[0],
- cert: params[1],
- ca: params[2]
- });
+ tls.createServer({ key, cert, ca });
}, common.expectsError({
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: /^The "ca" argument must be one of type string, Buffer, TypedArray, or DataView$/
}));
});
+
+// Checks to ensure tls.createServer throws an error for CA assignment
+// Format ['key', 'cert', 'ca']
+[
+ [keyBuff, certBuff, true],
+ [keyBuff, certBuff, {}],
+ [keyBuff, certBuff, 1],
+ [keyBuff, certBuff, true],
+ [keyBuff, certBuff, [caCert, true]]
+].map(([key, cert, ca]) => {
+ assert.throws(() => {
+ tls.createServer({ key, cert, ca });
+ }, common.expectsError({
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError,
+ message: /^The "ca" argument must be one of type string, Buffer, TypedArray, or DataView$/
+ }));
+});
+
+// Checks to ensure tls.createSecureContext works with false-y input
+// Format ['key', 'cert', 'ca']
+[
+ [null, null, null],
+ [false, false, false],
+ [undefined, undefined, undefined],
+ ['', '', ''],
+ [0, 0, 0]
+].map(([key, cert, ca]) => {
+ assert.doesNotThrow(() => {
+ tls.createSecureContext({ key, cert, ca });
+ });
+});