@@ -46,7 +46,14 @@ assert.throws(function() {
46
46
const context = credentials . context ;
47
47
const notcontext = { setOptions : context . setOptions , setKey : context . setKey } ;
48
48
tls . createSecureContext ( { secureOptions : 1 } , notcontext ) ;
49
- } , / ^ T y p e E r r o r : I l l e g a l i n v o c a t i o n $ / ) ;
49
+ } , ( err ) => {
50
+ // Throws TypeError, so there is no opensslErrorStack property.
51
+ if ( ( err instanceof Error ) &&
52
+ / ^ T y p e E r r o r : I l l e g a l i n v o c a t i o n $ / . test ( err ) &&
53
+ err . opensslErrorStack === undefined ) {
54
+ return true ;
55
+ }
56
+ } ) ;
50
57
51
58
// PFX tests
52
59
assert . doesNotThrow ( function ( ) {
@@ -55,15 +62,36 @@ assert.doesNotThrow(function() {
55
62
56
63
assert . throws ( function ( ) {
57
64
tls . createSecureContext ( { pfx : certPfx } ) ;
58
- } , / ^ E r r o r : m a c v e r i f y f a i l u r e $ / ) ;
65
+ } , ( err ) => {
66
+ // Throws general Error, so there is no opensslErrorStack property.
67
+ if ( ( err instanceof Error ) &&
68
+ / ^ E r r o r : m a c v e r i f y f a i l u r e $ / . test ( err ) &&
69
+ err . opensslErrorStack === undefined ) {
70
+ return true ;
71
+ }
72
+ } ) ;
59
73
60
74
assert . throws ( function ( ) {
61
75
tls . createSecureContext ( { pfx : certPfx , passphrase : 'test' } ) ;
62
- } , / ^ E r r o r : m a c v e r i f y f a i l u r e $ / ) ;
76
+ } , ( err ) => {
77
+ // Throws general Error, so there is no opensslErrorStack property.
78
+ if ( ( err instanceof Error ) &&
79
+ / ^ E r r o r : m a c v e r i f y f a i l u r e $ / . test ( err ) &&
80
+ err . opensslErrorStack === undefined ) {
81
+ return true ;
82
+ }
83
+ } ) ;
63
84
64
85
assert . throws ( function ( ) {
65
86
tls . createSecureContext ( { pfx : 'sample' , passphrase : 'test' } ) ;
66
- } , / ^ E r r o r : n o t e n o u g h d a t a $ / ) ;
87
+ } , ( err ) => {
88
+ // Throws general Error, so there is no opensslErrorStack property.
89
+ if ( ( err instanceof Error ) &&
90
+ / ^ E r r o r : n o t e n o u g h d a t a $ / . test ( err ) &&
91
+ err . opensslErrorStack === undefined ) {
92
+ return true ;
93
+ }
94
+ } ) ;
67
95
68
96
69
97
// update() should only take buffers / strings
@@ -135,23 +163,62 @@ testImmutability(crypto.getCurves);
135
163
// throw, not assert in C++ land.
136
164
assert . throws ( function ( ) {
137
165
crypto . createCipher ( 'aes192' , 'test' ) . update ( '0' , 'hex' ) ;
138
- } , common . hasFipsCrypto ? / n o t s u p p o r t e d i n F I P S m o d e / : / B a d i n p u t s t r i n g / ) ;
166
+ } , ( err ) => {
167
+ const errorMessage =
168
+ common . hasFipsCrypto ? / n o t s u p p o r t e d i n F I P S m o d e / : / B a d i n p u t s t r i n g / ;
169
+ // Throws general Error, so there is no opensslErrorStack property.
170
+ if ( ( err instanceof Error ) &&
171
+ errorMessage . test ( err ) &&
172
+ err . opensslErrorStack === undefined ) {
173
+ return true ;
174
+ }
175
+ } ) ;
139
176
140
177
assert . throws ( function ( ) {
141
178
crypto . createDecipher ( 'aes192' , 'test' ) . update ( '0' , 'hex' ) ;
142
- } , common . hasFipsCrypto ? / n o t s u p p o r t e d i n F I P S m o d e / : / B a d i n p u t s t r i n g / ) ;
179
+ } , ( err ) => {
180
+ const errorMessage =
181
+ common . hasFipsCrypto ? / n o t s u p p o r t e d i n F I P S m o d e / : / B a d i n p u t s t r i n g / ;
182
+ // Throws general Error, so there is no opensslErrorStack property.
183
+ if ( ( err instanceof Error ) &&
184
+ errorMessage . test ( err ) &&
185
+ err . opensslErrorStack === undefined ) {
186
+ return true ;
187
+ }
188
+ } ) ;
143
189
144
190
assert . throws ( function ( ) {
145
191
crypto . createHash ( 'sha1' ) . update ( '0' , 'hex' ) ;
146
- } , / ^ T y p e E r r o r : B a d i n p u t s t r i n g $ / ) ;
192
+ } , ( err ) => {
193
+ // Throws TypeError, so there is no opensslErrorStack property.
194
+ if ( ( err instanceof Error ) &&
195
+ / ^ T y p e E r r o r : B a d i n p u t s t r i n g $ / . test ( err ) &&
196
+ err . opensslErrorStack === undefined ) {
197
+ return true ;
198
+ }
199
+ } ) ;
147
200
148
201
assert . throws ( function ( ) {
149
202
crypto . createSign ( 'SHA1' ) . update ( '0' , 'hex' ) ;
150
- } , / ^ T y p e E r r o r : B a d i n p u t s t r i n g $ / ) ;
203
+ } , ( err ) => {
204
+ // Throws TypeError, so there is no opensslErrorStack property.
205
+ if ( ( err instanceof Error ) &&
206
+ / ^ T y p e E r r o r : B a d i n p u t s t r i n g $ / . test ( err ) &&
207
+ err . opensslErrorStack === undefined ) {
208
+ return true ;
209
+ }
210
+ } ) ;
151
211
152
212
assert . throws ( function ( ) {
153
213
crypto . createVerify ( 'SHA1' ) . update ( '0' , 'hex' ) ;
154
- } , / ^ T y p e E r r o r : B a d i n p u t s t r i n g $ / ) ;
214
+ } , ( err ) => {
215
+ // Throws TypeError, so there is no opensslErrorStack property.
216
+ if ( ( err instanceof Error ) &&
217
+ / ^ T y p e E r r o r : B a d i n p u t s t r i n g $ / . test ( err ) &&
218
+ err . opensslErrorStack === undefined ) {
219
+ return true ;
220
+ }
221
+ } ) ;
155
222
156
223
assert . throws ( function ( ) {
157
224
const priv = [
@@ -164,7 +231,13 @@ assert.throws(function() {
164
231
''
165
232
] . join ( '\n' ) ;
166
233
crypto . createSign ( 'SHA256' ) . update ( 'test' ) . sign ( priv ) ;
167
- } , / d i g e s t t o o b i g f o r r s a k e y $ / ) ;
234
+ } , ( err ) => {
235
+ if ( ( err instanceof Error ) &&
236
+ / d i g e s t t o o b i g f o r r s a k e y $ / . test ( err ) &&
237
+ err . opensslErrorStack === undefined ) {
238
+ return true ;
239
+ }
240
+ } ) ;
168
241
169
242
assert . throws ( function ( ) {
170
243
// The correct header inside `test_bad_rsa_privkey.pem` should have been
@@ -180,14 +253,31 @@ assert.throws(function() {
180
253
'ascii' ) ;
181
254
// this would inject errors onto OpenSSL's error stack
182
255
crypto . createSign ( 'sha1' ) . sign ( sha1_privateKey ) ;
183
- } , / a s n 1 e n c o d i n g r o u t i n e s : A S N 1 _ C H E C K _ T L E N : w r o n g t a g / ) ;
256
+ } , ( err ) => {
257
+ // Throws crypto error, so there is an opensslErrorStack property.
258
+ // The openSSL stack should have content.
259
+ if ( ( err instanceof Error ) &&
260
+ / a s n 1 e n c o d i n g r o u t i n e s : A S N 1 _ C H E C K _ T L E N : w r o n g t a g / . test ( err ) &&
261
+ err . opensslErrorStack !== undefined &&
262
+ Array . isArray ( err . opensslErrorStack ) &&
263
+ err . opensslErrorStack . length > 0 ) {
264
+ return true ;
265
+ }
266
+ } ) ;
184
267
185
268
// Make sure memory isn't released before being returned
186
269
console . log ( crypto . randomBytes ( 16 ) ) ;
187
270
188
271
assert . throws ( function ( ) {
189
272
tls . createSecureContext ( { crl : 'not a CRL' } ) ;
190
- } , / ^ E r r o r : F a i l e d t o p a r s e C R L $ / ) ;
273
+ } , ( err ) => {
274
+ // Throws general error, so there is no opensslErrorStack property.
275
+ if ( ( err instanceof Error ) &&
276
+ / ^ E r r o r : F a i l e d t o p a r s e C R L $ / . test ( err ) &&
277
+ err . opensslErrorStack === undefined ) {
278
+ return true ;
279
+ }
280
+ } ) ;
191
281
192
282
/**
193
283
* Check if the stream function uses utf8 as a default encoding.
0 commit comments