| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent dc7f03c commit 1403d28
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -80,7 +80,7 @@ exports.createSecureContext = function createSecureContext(options, context) { | |||
| 80 | 80 | // NOTE: It's important to add CA before the cert to be able to load | |
| 81 | 81 | // cert's issuer in C++ code. | |
| 82 | 82 | var ca = options.ca; | |
| 83 | - if (ca !== undefined) { | ||
| 83 | + if (ca) { | ||
| 84 | 84 | if (Array.isArray(ca)) { | |
| 85 | 85 | for (i = 0; i < ca.length; ++i) { | |
| 86 | 86 | val = ca[i]; | |
@@ -96,7 +96,7 @@ exports.createSecureContext = function createSecureContext(options, context) { | |||
| 96 | 96 | } | |
| 97 | 97 | ||
| 98 | 98 | var cert = options.cert; | |
| 99 | - if (cert !== undefined) { | ||
| 99 | + if (cert) { | ||
| 100 | 100 | if (Array.isArray(cert)) { | |
| 101 | 101 | for (i = 0; i < cert.length; ++i) { | |
| 102 | 102 | val = cert[i]; | |
@@ -115,7 +115,7 @@ exports.createSecureContext = function createSecureContext(options, context) { | |||
| 115 | 115 | // which leads to the crash later on. | |
| 116 | 116 | var key = options.key; | |
| 117 | 117 | var passphrase = options.passphrase; | |
| 118 | - if (key !== undefined) { | ||
| 118 | + if (key) { | ||
| 119 | 119 | if (Array.isArray(key)) { | |
| 120 | 120 | for (i = 0; i < key.length; ++i) { | |
| 121 | 121 | val = key[i]; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -64,12 +64,9 @@ const invalidCertRE = /^The "cert" argument must be one of type string, Buffer, | |||
| 64 | 64 | [false, [certStr, certStr2]], | |
| 65 | 65 | [[{ pem: keyBuff }], false], | |
| 66 | 66 | [[{ pem: keyBuff }, { pem: keyBuff }], false] | |
| 67 | - ].map((params) => { | ||
| 67 | + ].map(([key, cert]) => { | ||
| 68 | 68 | assert.doesNotThrow(() => { | |
| 69 | - tls.createServer({ | ||
| 70 | - key: params[0], | ||
| 71 | - cert: params[1] | ||
| 72 | - }); | ||
| 69 | + tls.createServer({ key, cert }); | ||
| 73 | 70 | }); | |
| 74 | 71 | }); | |
| 75 | 72 | ||
@@ -100,16 +97,13 @@ const invalidCertRE = /^The "cert" argument must be one of type string, Buffer, | |||
| 100 | 97 | [[keyStr, keyStr2], [true, false], invalidCertRE], | |
| 101 | 98 | [[keyStr, keyStr2], true, invalidCertRE], | |
| 102 | 99 | [true, [certBuff, certBuff2], invalidKeyRE] | |
| 103 | - ].map((params) => { | ||
| 100 | + ].map(([key, cert, message]) => { | ||
| 104 | 101 | assert.throws(() => { | |
| 105 | - tls.createServer({ | ||
| 106 | - key: params[0], | ||
| 107 | - cert: params[1] | ||
| 108 | - }); | ||
| 102 | + tls.createServer({ key, cert }); | ||
| 109 | 103 | }, common.expectsError({ | |
| 110 | 104 | code: 'ERR_INVALID_ARG_TYPE', | |
| 111 | 105 | type: TypeError, | |
| 112 | - message: params[2] | ||
| 106 | + message | ||
| 113 | 107 | })); | |
| 114 | 108 | }); | |
| 115 | 109 | ||
@@ -123,13 +117,9 @@ const invalidCertRE = /^The "cert" argument must be one of type string, Buffer, | |||
| 123 | 117 | [keyBuff, certBuff, caArrBuff], | |
| 124 | 118 | [keyBuff, certBuff, caArrDataView], | |
| 125 | 119 | [keyBuff, certBuff, false], | |
| 126 | - ].map((params) => { | ||
| 120 | + ].map(([key, cert, ca]) => { | ||
| 127 | 121 | assert.doesNotThrow(() => { | |
| 128 | - tls.createServer({ | ||
| 129 | - key: params[0], | ||
| 130 | - cert: params[1], | ||
| 131 | - ca: params[2] | ||
| 132 | - }); | ||
| 122 | + tls.createServer({ key, cert, ca }); | ||
| 133 | 123 | }); | |
| 134 | 124 | }); | |
| 135 | 125 | ||
@@ -141,16 +131,44 @@ const invalidCertRE = /^The "cert" argument must be one of type string, Buffer, | |||
| 141 | 131 | [keyBuff, certBuff, 1], | |
| 142 | 132 | [keyBuff, certBuff, true], | |
| 143 | 133 | [keyBuff, certBuff, [caCert, true]] | |
| 144 | - ].map((params) => { | ||
| 134 | + ].map(([key, cert, ca]) => { | ||
| 145 | 135 | assert.throws(() => { | |
| 146 | - tls.createServer({ | ||
| 147 | - key: params[0], | ||
| 148 | - cert: params[1], | ||
| 149 | - ca: params[2] | ||
| 150 | - }); | ||
| 136 | + tls.createServer({ key, cert, ca }); | ||
| 151 | 137 | }, common.expectsError({ | |
| 152 | 138 | code: 'ERR_INVALID_ARG_TYPE', | |
| 153 | 139 | type: TypeError, | |
| 154 | 140 | message: /^The "ca" argument must be one of type string, Buffer, TypedArray, or DataView$/ | |
| 155 | 141 | })); | |
| 156 | 142 | }); | |
| 143 | + | ||
| 144 | + // Checks to ensure tls.createServer throws an error for CA assignment | ||
| 145 | + // Format ['key', 'cert', 'ca'] | ||
| 146 | + [ | ||
| 147 | + [keyBuff, certBuff, true], | ||
| 148 | + [keyBuff, certBuff, {}], | ||
| 149 | + [keyBuff, certBuff, 1], | ||
| 150 | + [keyBuff, certBuff, true], | ||
| 151 | + [keyBuff, certBuff, [caCert, true]] | ||
| 152 | + ].map(([key, cert, ca]) => { | ||
| 153 | + assert.throws(() => { | ||
| 154 | + tls.createServer({ key, cert, ca }); | ||
| 155 | + }, common.expectsError({ | ||
| 156 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 157 | + type: TypeError, | ||
| 158 | + message: /^The "ca" argument must be one of type string, Buffer, TypedArray, or DataView$/ | ||
| 159 | + })); | ||
| 160 | + }); | ||
| 161 | + | ||
| 162 | + // Checks to ensure tls.createSecureContext works with false-y input | ||
| 163 | + // Format ['key', 'cert', 'ca'] | ||
| 164 | + [ | ||
| 165 | + [null, null, null], | ||
| 166 | + [false, false, false], | ||
| 167 | + [undefined, undefined, undefined], | ||
| 168 | + ['', '', ''], | ||
| 169 | + [0, 0, 0] | ||
| 170 | + ].map(([key, cert, ca]) => { | ||
| 171 | + assert.doesNotThrow(() => { | ||
| 172 | + tls.createSecureContext({ key, cert, ca }); | ||
| 173 | + }); | ||
| 174 | + }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments