@@ -353,7 +353,23 @@ describe(`Run in Live mode`, () => {
353
353
await publicHomepageShouldBeAccessible ( ) ;
354
354
} ) ;
355
355
356
+ it ( "Should fallback to the selected remedition for unknown remediation" , async ( ) => {
357
+ await removeAllDecisions ( ) ;
358
+ await addDecision ( CLIENT_IP , "mfa" , ( 15 * 60 ) + "s" ) ;
359
+ await wait ( 1000 ) ;
360
+ await publicHomepageShouldBeCaptchaWall ( ) ;
361
+ await goToAdmin ( ) ;
362
+ await onAdminGoToAdvancedPage ( ) ;
363
+ await page . selectOption (
364
+ "[name=crowdsec_fallback_remediation]" ,
365
+ "bypass"
366
+ ) ;
367
+ await onAdminSaveSettings ( ) ;
368
+ await publicHomepageShouldBeAccessible ( ) ;
369
+ } ) ;
370
+
356
371
it ( 'Should handle X-Forwarded-For header for whitelisted IPs only"' , async ( ) => {
372
+ await removeAllDecisions ( ) ;
357
373
await banIpForSeconds ( OTHER_IP , 15 * 60 ) ;
358
374
359
375
// Should be banned as current IP is not trust by CDN
@@ -372,6 +388,46 @@ describe(`Run in Live mode`, () => {
372
388
// // Remove the XFF header for next requests
373
389
page . setExtraHTTPHeaders ( { } ) ;
374
390
} ) ;
391
+
392
+ it ( "Should prune the File system cache" , async ( ) => {
393
+ await goToAdmin ( ) ;
394
+ await onAdminGoToAdvancedPage ( ) ;
395
+ await page . click ( "#crowdsec_prune_cache" ) ;
396
+ await waitForNavigation ;
397
+
398
+ await expect ( page ) . toHaveText (
399
+ "#wpbody-content > div.wrap > div.notice.notice-success" ,
400
+ "CrowdSec cache has just been pruned."
401
+ ) ;
402
+ } ) ;
403
+
404
+ it ( "Should clear the cache on demand" , async ( ) => {
405
+ await onAdminGoToAdvancedPage ( ) ;
406
+ await onAdminAdvancedSettingsPageSetCleanIpCacheDurationTo ( 60 ) ;
407
+ await onAdminAdvancedSettingsPageSetBadIpCacheDurationTo ( 60 ) ;
408
+ await onAdminSaveSettings ( ) ;
409
+ await banOwnIpForSeconds ( 15 * 60 ) ;
410
+ await publicHomepageShouldBeBanWall ( ) ;
411
+ wait ( 2000 ) ;
412
+ await publicHomepageShouldBeBanWall ( ) ;
413
+ await removeAllDecisions ( ) ;
414
+ wait ( 2000 ) ;
415
+ await publicHomepageShouldBeBanWall ( ) ;
416
+
417
+ await goToAdmin ( ) ;
418
+ await onAdminGoToAdvancedPage ( ) ;
419
+ await page . on ( 'dialog' , async ( dialog ) => {
420
+ await dialog . accept ( ) ;
421
+ } ) ;
422
+ await page . click ( "#crowdsec_clear_cache" ) ;
423
+ await waitForNavigation ;
424
+
425
+ await expect ( page ) . toHaveText (
426
+ "#wpbody-content > div.wrap > div.notice.notice-success" ,
427
+ "CrowdSec cache has just been cleared."
428
+ ) ;
429
+ await publicHomepageShouldBeAccessible ( ) ;
430
+ } ) ;
375
431
} ) ;
376
432
377
433
describe ( `Run in Stream mode` , ( ) => {
@@ -398,58 +454,97 @@ describe(`Run in Stream mode`, () => {
398
454
await forceCronRun ( ) ;
399
455
await publicHomepageShouldBeAccessible ( ) ;
400
456
} ) ;
401
- } ) ;
402
457
403
- /*
404
- # Public website only
405
-
406
- In live mode (1s + 1s), disable "Public website only"
407
- Ban current IP during 5 sec
408
- Try to access admin each 2 sec
409
- The third time admin should be back
410
- Re-enable "Public website only"
411
-
412
- # Manually clear the cache
458
+ it ( "Should refresh the cache" , async ( ) => {
459
+ await goToAdmin ( ) ;
460
+ await onAdminGoToAdvancedPage ( ) ;
461
+ await page . click ( "#crowdsec_refresh_cache" ) ;
462
+ await waitForNavigation ;
413
463
414
- Set cache duration to 1min (clean + bad IP)
415
- Remove all decisions + Ban current IP during 15min
416
- The public page should be forbidden
417
- Remove all decisions
418
- The public page should still be forbidden
419
- Click the "Clear now" button
420
- The public page should be accessible
464
+ await expect ( page ) . toHaveText (
465
+ "#wpbody-content > div.wrap > div.notice.notice-success" ,
466
+ "The cache has just been refreshed (0 new decision, 0 deleted)."
467
+ ) ;
468
+ } ) ;
469
+ } ) ;
421
470
422
- # Refresh cache button
471
+ describe ( `Use Redis technology` , ( ) => {
472
+ it ( 'Should be able to use Redis cache"' , async ( ) => {
473
+ notify ( "Use Redis technology" ) ;
423
474
424
- (to write )
475
+ // TODO (+ bad DSN format, + DSN down )
425
476
426
- # Stream mode: Resync decisions each
477
+ await goToAdmin ( ) ;
478
+ await onAdminGoToAdvancedPage ( ) ;
479
+ await page . selectOption ( "[name=crowdsec_cache_system]" , "redis" ) ;
480
+ await wait ( 200 ) ;
481
+ await fillInput ( "crowdsec_redis_dsn" , "redis://redis:6379" ) ; // TODO test bad DSN format and test DSN down
482
+ await onAdminSaveSettings ( ) ;
427
483
428
- Remove all decisions + Ban current IP during 15min
429
- Set stream mode with 15 seconds resync
430
- Refresh cache
484
+ await expect ( page ) . toHaveText (
485
+ "#wpbody-content > div.wrap > div.notice.notice-success" ,
486
+ "As the stream mode is enabled, the cache has just been warmed up, there is now 0 decision in cache."
487
+ ) ;
431
488
432
- (to finish, I'm gonna sleep)
489
+ await publicHomepageShouldBeAccessible ( ) ;
490
+ await banOwnIpForSeconds ( 15 * 60 ) ;
491
+ await forceCronRun ( ) ;
492
+ await publicHomepageShouldBeBanWall ( ) ;
493
+ await removeAllDecisions ( ) ;
494
+ await forceCronRun ( ) ;
495
+ await publicHomepageShouldBeAccessible ( ) ;
496
+ } ) ;
497
+ } ) ;
433
498
434
- # Loop avec Redis / Memcached (+ mauvais format DSN, DSN down)
499
+ describe ( `Use Memcached technology` , ( ) => {
500
+ it ( 'Should be able to use Memcached cache"' , async ( ) => {
501
+ notify ( "Use Memcached technology" ) ;
435
502
436
- (to write)
503
+ await goToAdmin ( ) ;
504
+ await onAdminGoToAdvancedPage ( ) ;
505
+ await page . selectOption ( "[name=crowdsec_cache_system]" , "memcached" ) ;
506
+ await wait ( 200 ) ;
507
+ await fillInput (
508
+ "crowdsec_memcached_dsn" ,
509
+ "memcached://memcached:11211"
510
+ ) ;
437
511
438
- # Fallback
512
+ // TODO test bad DSN format and test DSN down
439
513
440
- (to write)
514
+ await onAdminSaveSettings ( ) ;
515
+ await expect ( page ) . toHaveText (
516
+ "#wpbody-content > div.wrap > div.notice.notice-success" ,
517
+ "As the stream mode is enabled, the cache has just been warmed up, there is now 0 decision in cache."
518
+ ) ;
441
519
520
+ await publicHomepageShouldBeAccessible ( ) ;
521
+ await banOwnIpForSeconds ( 15 * 60 ) ;
522
+ await forceCronRun ( ) ;
523
+ await publicHomepageShouldBeBanWall ( ) ;
524
+ await removeAllDecisions ( ) ;
525
+ await forceCronRun ( ) ;
526
+ await publicHomepageShouldBeAccessible ( ) ;
527
+ } ) ;
528
+ } ) ;
442
529
443
- # Recheck clean IP
530
+ /*
531
+ # Public website only
444
532
445
- (to write)
533
+ In live mode (1s + 1s), disable "Public website only"
534
+ Ban current IP during 5 sec
535
+ Try to access admin each 2 sec
536
+ The third time admin should be back
537
+ Re-enable "Public website only"
446
538
447
- # Recheck Bad IP
539
+ # Stream mode: Resync decisions each
448
540
449
- (to write)
541
+ Remove all decisions + Ban current IP during 15min
542
+ Set stream mode with 15 seconds resync
543
+ Refresh cache
544
+ (to finish writing)
450
545
451
- # Prune FS Cache
546
+ # Recheck clean IP (to write)
452
547
453
- (to write)
548
+ # Recheck Bad IP (to write)
454
549
455
550
*/
0 commit comments