@@ -22,13 +22,16 @@ const FIPS_ENABLE_ERROR_STRING = 'OpenSSL error when trying to enable FIPS:';
22
22
const CNF_FIPS_ON = fixtures . path ( 'openssl_fips_enabled.cnf' ) ;
23
23
const CNF_FIPS_OFF = fixtures . path ( 'openssl_fips_disabled.cnf' ) ;
24
24
25
+ const kNoFailure = 0 ;
26
+ const kGenericUserError = 1 ;
27
+
25
28
let num_children_ok = 0 ;
26
29
27
30
function sharedOpenSSL ( ) {
28
31
return process . config . variables . node_shared_openssl ;
29
32
}
30
33
31
- function testHelper ( stream , args , expectedOutput , cmd , env ) {
34
+ function testHelper ( stream , args , expectedStatus , expectedOutput , cmd , env ) {
32
35
const fullArgs = args . concat ( [ '-e' , `console.log(${ cmd } )` ] ) ;
33
36
const child = spawnSync ( process . execPath , fullArgs , {
34
37
cwd : path . dirname ( process . execPath ) ,
@@ -55,6 +58,7 @@ function testHelper(stream, args, expectedOutput, cmd, env) {
55
58
// Normal path where we expect either FIPS enabled or disabled.
56
59
assert . strictEqual ( getFipsValue , expectedOutput ) ;
57
60
}
61
+ assert . strictEqual ( child . status , expectedStatus ) ;
58
62
childOk ( child ) ;
59
63
}
60
64
@@ -65,6 +69,7 @@ function testHelper(stream, args, expectedOutput, cmd, env) {
65
69
testHelper (
66
70
testFipsCrypto ( ) ? 'stdout' : 'stderr' ,
67
71
[ '--enable-fips' ] ,
72
+ testFipsCrypto ( ) ? kNoFailure : kGenericUserError ,
68
73
testFipsCrypto ( ) ? FIPS_ENABLED : FIPS_ENABLE_ERROR_STRING ,
69
74
'process.versions' ,
70
75
process . env ) ;
@@ -73,6 +78,7 @@ testHelper(
73
78
testHelper (
74
79
testFipsCrypto ( ) ? 'stdout' : 'stderr' ,
75
80
[ '--force-fips' ] ,
81
+ testFipsCrypto ( ) ? kNoFailure : kGenericUserError ,
76
82
testFipsCrypto ( ) ? FIPS_ENABLED : FIPS_ENABLE_ERROR_STRING ,
77
83
'process.versions' ,
78
84
process . env ) ;
@@ -84,6 +90,7 @@ if (!sharedOpenSSL()) {
84
90
testHelper (
85
91
'stdout' ,
86
92
[ ] ,
93
+ kNoFailure ,
87
94
FIPS_DISABLED ,
88
95
'require("crypto").getFips()' ,
89
96
{ ...process . env , 'OPENSSL_CONF' : ' ' } ) ;
@@ -93,6 +100,7 @@ if (!sharedOpenSSL()) {
93
100
testHelper (
94
101
'stderr' ,
95
102
[ ] ,
103
+ kGenericUserError ,
96
104
'Calling crypto.setFips() is not supported in workers' ,
97
105
'new worker_threads.Worker(\'require("crypto").setFips(true);\', { eval: true })' ,
98
106
process . env ) ;
@@ -119,6 +127,7 @@ if (!sharedOpenSSL() && !common.hasOpenSSL3) {
119
127
testHelper (
120
128
'stdout' ,
121
129
[ `--openssl-config=${ CNF_FIPS_ON } ` ] ,
130
+ kNoFailure ,
122
131
testFipsCrypto ( ) ? FIPS_ENABLED : FIPS_DISABLED ,
123
132
'require("crypto").getFips()' ,
124
133
process . env ) ;
@@ -127,6 +136,7 @@ if (!sharedOpenSSL() && !common.hasOpenSSL3) {
127
136
testHelper (
128
137
'stdout' ,
129
138
[ ] ,
139
+ kNoFailure ,
130
140
testFipsCrypto ( ) ? FIPS_ENABLED : FIPS_DISABLED ,
131
141
'require("crypto").getFips()' ,
132
142
Object . assign ( { } , process . env , { 'OPENSSL_CONF' : CNF_FIPS_ON } ) ) ;
@@ -135,6 +145,7 @@ if (!sharedOpenSSL() && !common.hasOpenSSL3) {
135
145
testHelper (
136
146
'stdout' ,
137
147
[ `--openssl-config=${ CNF_FIPS_ON } ` ] ,
148
+ kNoFailure ,
138
149
testFipsCrypto ( ) ? FIPS_ENABLED : FIPS_DISABLED ,
139
150
'require("crypto").getFips()' ,
140
151
Object . assign ( { } , process . env , { 'OPENSSL_CONF' : CNF_FIPS_OFF } ) ) ;
@@ -148,6 +159,7 @@ if (!common.hasOpenSSL3) {
148
159
testHelper (
149
160
'stdout' ,
150
161
[ `--openssl-config=${ CNF_FIPS_OFF } ` ] ,
162
+ kNoFailure ,
151
163
FIPS_DISABLED ,
152
164
'require("crypto").getFips()' ,
153
165
Object . assign ( { } , process . env , { 'OPENSSL_CONF' : CNF_FIPS_ON } ) ) ;
@@ -156,20 +168,23 @@ if (!common.hasOpenSSL3) {
156
168
testHelper (
157
169
testFipsCrypto ( ) ? 'stdout' : 'stderr' ,
158
170
[ '--enable-fips' , `--openssl-config=${ CNF_FIPS_OFF } ` ] ,
171
+ testFipsCrypto ( ) ? kNoFailure : kGenericUserError ,
159
172
testFipsCrypto ( ) ? FIPS_ENABLED : FIPS_UNSUPPORTED_ERROR_STRING ,
160
173
'require("crypto").getFips()' ,
161
174
process . env ) ;
162
175
// --force-fips should take precedence over OpenSSL config file
163
176
testHelper (
164
177
testFipsCrypto ( ) ? 'stdout' : 'stderr' ,
165
178
[ '--force-fips' , `--openssl-config=${ CNF_FIPS_OFF } ` ] ,
179
+ testFipsCrypto ( ) ? kNoFailure : kGenericUserError ,
166
180
testFipsCrypto ( ) ? FIPS_ENABLED : FIPS_UNSUPPORTED_ERROR_STRING ,
167
181
'require("crypto").getFips()' ,
168
182
process . env ) ;
169
183
// --enable-fips should turn FIPS mode on
170
184
testHelper (
171
185
testFipsCrypto ( ) ? 'stdout' : 'stderr' ,
172
186
[ '--enable-fips' ] ,
187
+ testFipsCrypto ( ) ? kNoFailure : kGenericUserError ,
173
188
testFipsCrypto ( ) ? FIPS_ENABLED : FIPS_UNSUPPORTED_ERROR_STRING ,
174
189
'require("crypto").getFips()' ,
175
190
process . env ) ;
@@ -178,6 +193,7 @@ if (!common.hasOpenSSL3) {
178
193
testHelper (
179
194
testFipsCrypto ( ) ? 'stdout' : 'stderr' ,
180
195
[ '--force-fips' ] ,
196
+ testFipsCrypto ( ) ? kNoFailure : kGenericUserError ,
181
197
testFipsCrypto ( ) ? FIPS_ENABLED : FIPS_UNSUPPORTED_ERROR_STRING ,
182
198
'require("crypto").getFips()' ,
183
199
process . env ) ;
@@ -186,6 +202,7 @@ if (!common.hasOpenSSL3) {
186
202
testHelper (
187
203
testFipsCrypto ( ) ? 'stdout' : 'stderr' ,
188
204
[ '--enable-fips' ] ,
205
+ testFipsCrypto ( ) ? kNoFailure : kGenericUserError ,
189
206
testFipsCrypto ( ) ? FIPS_ENABLED : FIPS_UNSUPPORTED_ERROR_STRING ,
190
207
'require("crypto").getFips()' ,
191
208
Object . assign ( { } , process . env , { 'OPENSSL_CONF' : CNF_FIPS_OFF } ) ) ;
@@ -194,6 +211,7 @@ if (!common.hasOpenSSL3) {
194
211
testHelper (
195
212
testFipsCrypto ( ) ? 'stdout' : 'stderr' ,
196
213
[ '--force-fips' ] ,
214
+ testFipsCrypto ( ) ? kNoFailure : kGenericUserError ,
197
215
testFipsCrypto ( ) ? FIPS_ENABLED : FIPS_UNSUPPORTED_ERROR_STRING ,
198
216
'require("crypto").getFips()' ,
199
217
Object . assign ( { } , process . env , { 'OPENSSL_CONF' : CNF_FIPS_OFF } ) ) ;
@@ -202,6 +220,7 @@ if (!common.hasOpenSSL3) {
202
220
testHelper (
203
221
testFipsCrypto ( ) ? 'stdout' : 'stderr' ,
204
222
[ ] ,
223
+ testFipsCrypto ( ) ? kNoFailure : kGenericUserError ,
205
224
testFipsCrypto ( ) ? FIPS_ENABLED : FIPS_UNSUPPORTED_ERROR_STRING ,
206
225
'(require("crypto").setFips(true),' +
207
226
'require("crypto").getFips())' ,
@@ -211,6 +230,7 @@ if (!common.hasOpenSSL3) {
211
230
testHelper (
212
231
testFipsCrypto ( ) ? 'stdout' : 'stderr' ,
213
232
[ ] ,
233
+ testFipsCrypto ( ) ? kNoFailure : kGenericUserError ,
214
234
testFipsCrypto ( ) ? FIPS_DISABLED : FIPS_UNSUPPORTED_ERROR_STRING ,
215
235
'(require("crypto").setFips(true),' +
216
236
'require("crypto").setFips(false),' +
@@ -221,6 +241,7 @@ if (!common.hasOpenSSL3) {
221
241
testHelper (
222
242
testFipsCrypto ( ) ? 'stdout' : 'stderr' ,
223
243
[ `--openssl-config=${ CNF_FIPS_OFF } ` ] ,
244
+ testFipsCrypto ( ) ? kNoFailure : kGenericUserError ,
224
245
testFipsCrypto ( ) ? FIPS_ENABLED : FIPS_UNSUPPORTED_ERROR_STRING ,
225
246
'(require("crypto").setFips(true),' +
226
247
'require("crypto").getFips())' ,
@@ -230,6 +251,7 @@ if (!common.hasOpenSSL3) {
230
251
testHelper (
231
252
'stdout' ,
232
253
[ `--openssl-config=${ CNF_FIPS_ON } ` ] ,
254
+ kNoFailure ,
233
255
FIPS_DISABLED ,
234
256
'(require("crypto").setFips(false),' +
235
257
'require("crypto").getFips())' ,
@@ -239,6 +261,7 @@ if (!common.hasOpenSSL3) {
239
261
testHelper (
240
262
testFipsCrypto ( ) ? 'stdout' : 'stderr' ,
241
263
[ '--enable-fips' ] ,
264
+ testFipsCrypto ( ) ? kNoFailure : kGenericUserError ,
242
265
testFipsCrypto ( ) ? FIPS_DISABLED : FIPS_UNSUPPORTED_ERROR_STRING ,
243
266
'(require("crypto").setFips(false),' +
244
267
'require("crypto").getFips())' ,
@@ -248,6 +271,7 @@ if (!common.hasOpenSSL3) {
248
271
testHelper (
249
272
'stderr' ,
250
273
[ '--force-fips' ] ,
274
+ kGenericUserError ,
251
275
testFipsCrypto ( ) ? FIPS_ERROR_STRING2 : FIPS_UNSUPPORTED_ERROR_STRING ,
252
276
'require("crypto").setFips(false)' ,
253
277
process . env ) ;
@@ -256,6 +280,7 @@ if (!common.hasOpenSSL3) {
256
280
testHelper (
257
281
testFipsCrypto ( ) ? 'stdout' : 'stderr' ,
258
282
[ '--force-fips' ] ,
283
+ testFipsCrypto ( ) ? kNoFailure : kGenericUserError ,
259
284
testFipsCrypto ( ) ? FIPS_ENABLED : FIPS_UNSUPPORTED_ERROR_STRING ,
260
285
'(require("crypto").setFips(true),' +
261
286
'require("crypto").getFips())' ,
@@ -265,6 +290,7 @@ if (!common.hasOpenSSL3) {
265
290
testHelper (
266
291
'stderr' ,
267
292
[ '--force-fips' , '--enable-fips' ] ,
293
+ kGenericUserError ,
268
294
testFipsCrypto ( ) ? FIPS_ERROR_STRING2 : FIPS_UNSUPPORTED_ERROR_STRING ,
269
295
'require("crypto").setFips(false)' ,
270
296
process . env ) ;
@@ -273,6 +299,7 @@ if (!common.hasOpenSSL3) {
273
299
testHelper (
274
300
'stderr' ,
275
301
[ '--enable-fips' , '--force-fips' ] ,
302
+ kGenericUserError ,
276
303
testFipsCrypto ( ) ? FIPS_ERROR_STRING2 : FIPS_UNSUPPORTED_ERROR_STRING ,
277
304
'require("crypto").setFips(false)' ,
278
305
process . env ) ;
0 commit comments