@@ -141,7 +141,7 @@ static void dieIfNotSuccess(CURLcode ret)
141
141
}
142
142
143
143
static void
144
- checkCertificateRevocationStatus (char * host , char * port , char * cacert , char * proxy , char * no_proxy , int oob_enable , int failopen )
144
+ checkCertificateRevocationStatus (char * host , char * port , char * cacert , char * proxy , char * no_proxy , int oob_enable , int failopen , int expect_fail )
145
145
{
146
146
CURL * ch ;
147
147
struct configData config ;
@@ -198,7 +198,19 @@ checkCertificateRevocationStatus(char *host, char *port, char *cacert, char *pro
198
198
dieIfNotSuccess (curl_easy_setopt (ch , CURLOPT_SSL_SF_OCSP_FAIL_OPEN , 0 ));
199
199
}
200
200
201
- dieIfNotSuccess (curl_easy_perform (ch ));
201
+ CURLcode ret = curl_easy_perform (ch );
202
+ if (expect_fail == 0 )
203
+ {
204
+ dieIfNotSuccess (ret );
205
+ }
206
+ else
207
+ {
208
+ if (ret == CURLE_OK )
209
+ {
210
+ fprintf (stderr , "FAILED!\n" );
211
+ exit (1 );
212
+ }
213
+ }
202
214
203
215
curl_easy_cleanup (ch );
204
216
curl_global_cleanup ();
@@ -269,29 +281,36 @@ int main(int argc, char **argv)
269
281
return 2 ;
270
282
}
271
283
printf ("host: %s, port: %s, cacert: %s\n" , host , port , cacert );
284
+ #ifdef __linux__
272
285
sprintf (cache_file , "%s/.cache/snowflake/ocsp_response_cache.json" ,
273
286
getenv ("HOME" ));
287
+ #elif defined(__APPLE__ )
288
+ sprintf (cache_file , "%s/Library/Caches//Snowflake/ocsp_response_cache.json" ,
289
+ getenv ("HOME" ));
290
+ #else
291
+ return 0 ;
292
+ #endif
274
293
275
294
printf ("===> Case 1: whatever default\n" );
276
- checkCertificateRevocationStatus (host , port , cacert , NULL , NULL , 0 , 0 );
295
+ checkCertificateRevocationStatus (host , port , cacert , NULL , NULL , 0 , 0 , 0 );
277
296
278
297
printf ("===> Case 2: Delete file cache and No Use Cache Server\n" );
279
298
setenv ("SF_OCSP_RESPONSE_CACHE_SERVER_ENABLED" , "false" , 1 );
280
299
unlink (cache_file );
281
- checkCertificateRevocationStatus (host , port , cacert , NULL , NULL , 0 , 0 );
300
+ checkCertificateRevocationStatus (host , port , cacert , NULL , NULL , 0 , 0 , 0 );
282
301
283
302
printf ("===> Case 3: Delete file cache and Use Cache Server\n" );
284
303
setenv ("SF_OCSP_RESPONSE_CACHE_SERVER_ENABLED" , "true" , 1 );
285
304
unlink (cache_file );
286
- checkCertificateRevocationStatus (host , port , cacert , NULL , NULL , 0 , 0 );
305
+ checkCertificateRevocationStatus (host , port , cacert , NULL , NULL , 0 , 0 , 0 );
287
306
288
307
printf ("===> Case 4: No Delete file cache and No Use Cache Server\n" );
289
308
setenv ("SF_OCSP_RESPONSE_CACHE_SERVER_ENABLED" , "false" , 1 );
290
- checkCertificateRevocationStatus (host , port , cacert , NULL , NULL , 0 , 0 );
309
+ checkCertificateRevocationStatus (host , port , cacert , NULL , NULL , 0 , 0 , 0 );
291
310
292
311
printf ("===> Case 5: No Delete file cache and No Use Cache Server\n" );
293
312
setenv ("SF_OCSP_RESPONSE_CACHE_SERVER_ENABLED" , "false" , 1 );
294
- checkCertificateRevocationStatus (host , port , cacert , NULL , NULL , 0 , 0 );
313
+ checkCertificateRevocationStatus (host , port , cacert , NULL , NULL , 0 , 0 , 0 );
295
314
296
315
if (getenv ("all_proxy" ) || getenv ("https_proxy" ) ||
297
316
getenv ("http_proxy" ))
@@ -305,14 +324,14 @@ int main(int argc, char **argv)
305
324
setenv ("http_proxy" , "a.b.c" , 1 );
306
325
setenv ("https_proxy" , "a.b.c" , 1 );
307
326
unlink (cache_file );
308
- checkCertificateRevocationStatus (host , port , cacert , "" , "" , 0 , 0 );
327
+ checkCertificateRevocationStatus (host , port , cacert , "" , "" , 0 , 0 , 0 );
309
328
310
329
printf ("===> Case 7: Delete file cache and overwrite invalid proxy with no_proxy\n" );
311
330
setenv ("SF_OCSP_RESPONSE_CACHE_SERVER_ENABLED" , "true" , 1 );
312
331
setenv ("http_proxy" , "a.b.c" , 1 );
313
332
setenv ("https_proxy" , "a.b.c" , 1 );
314
333
unlink (cache_file );
315
- checkCertificateRevocationStatus (host , port , cacert , "a.b.c" , "*" , 0 , 0 );
334
+ checkCertificateRevocationStatus (host , port , cacert , "a.b.c" , "*" , 0 , 0 , 0 );
316
335
317
336
unsetenv ("http_proxy" );
318
337
unsetenv ("https_proxy" );
@@ -326,7 +345,7 @@ int main(int argc, char **argv)
326
345
// use random IP address so it will get connection timeout
327
346
setenv ("SF_OCSP_RESPONSE_CACHE_SERVER_URL" , "http://10.24.123.89/ocsp_response_cache.json" , 1 );
328
347
unlink (cache_file );
329
- checkCertificateRevocationStatus (host , port , cacert , NULL , NULL , 1 , 1 );
348
+ checkCertificateRevocationStatus (host , port , cacert , NULL , NULL , 1 , 1 , 0 );
330
349
331
350
printf ("===> Case 10: Delete file cache with invalid cache server URL to test delay on failure and OOB disabled\n" );
332
351
setenv ("SF_OCSP_RESPONSE_CACHE_SERVER_ENABLED" , "false" , 1 );
@@ -335,7 +354,7 @@ int main(int argc, char **argv)
335
354
unlink (cache_file );
336
355
337
356
time_t start_time = time (NULL );
338
- checkCertificateRevocationStatus (host , port , cacert , NULL , NULL , 0 , 1 );
357
+ checkCertificateRevocationStatus (host , port , cacert , NULL , NULL , 0 , 1 , 0 );
339
358
time_t end_time = time (NULL );
340
359
// should be around 5 seconds but no longer than 10.
341
360
if ((end_time - start_time ) > 10 )
@@ -348,6 +367,14 @@ int main(int argc, char **argv)
348
367
fprintf (stderr , "Delay check OK\n" );
349
368
}
350
369
370
+ printf ("===> Case 11: Delete file cache with invalid cache server URL test with fail close\n" );
371
+ setenv ("SF_OCSP_RESPONSE_CACHE_SERVER_ENABLED" , "true" , 1 );
372
+ // use random IP address so it will get connection timeout
373
+ setenv ("SF_OCSP_RESPONSE_CACHE_SERVER_URL" , "http://10.24.123.89/ocsp_response_cache.json" , 1 );
374
+ unlink (cache_file );
375
+
376
+ checkCertificateRevocationStatus (host , port , cacert , NULL , NULL , 0 , 0 , 1 );
377
+
351
378
unsetenv ("SF_OCSP_RESPONSE_CACHE_SERVER_ENABLED" );
352
379
unsetenv ("SF_OCSP_RESPONSE_CACHE_SERVER_URL" );
353
380
0 commit comments