6
6
*/
7
7
8
8
import type { PerformBulkActionSchema } from './perform_bulk_action_schema' ;
9
- import { performBulkActionSchema } from './perform_bulk_action_schema' ;
9
+ import {
10
+ performBulkActionSchema ,
11
+ BulkAction ,
12
+ BulkActionEditType ,
13
+ } from './perform_bulk_action_schema' ;
10
14
import { exactCheck , foldLeftRight , getPaths } from '@kbn/securitysolution-io-ts-utils' ;
11
15
import { left } from 'fp-ts/lib/Either' ;
12
- import { BulkAction , BulkActionEditType } from '../common/schemas' ;
13
16
14
17
const retrieveValidationMessage = ( payload : unknown ) => {
15
18
const decoded = performBulkActionSchema . decode ( payload ) ;
@@ -343,12 +346,12 @@ describe('perform_bulk_action_schema', () => {
343
346
344
347
const message = retrieveValidationMessage ( payload ) ;
345
348
346
- expect ( getPaths ( left ( message . errors ) ) ) . toEqual ( [
347
- 'Invalid value "edit" supplied to "action"' ,
348
- 'Invalid value "set_timeline" supplied to "edit,type "' ,
349
- 'Invalid value "{"timeline_title":"Test timeline title"}" supplied to "edit,value"' ,
350
- 'Invalid value "undefined" supplied to "edit,value,timeline_id"' ,
351
- ] ) ;
349
+ expect ( getPaths ( left ( message . errors ) ) ) . toEqual (
350
+ expect . arrayContaining ( [
351
+ 'Invalid value "{"timeline_title":"Test timeline title"}" supplied to "edit,value "' ,
352
+ 'Invalid value "undefined" supplied to "edit,value,timeline_id "' ,
353
+ ] )
354
+ ) ;
352
355
expect ( message . schema ) . toEqual ( { } ) ;
353
356
} ) ;
354
357
@@ -373,5 +376,163 @@ describe('perform_bulk_action_schema', () => {
373
376
expect ( message . schema ) . toEqual ( payload ) ;
374
377
} ) ;
375
378
} ) ;
379
+
380
+ describe ( 'rule actions' , ( ) => {
381
+ test ( 'invalid request: invalid rule actions payload' , ( ) => {
382
+ const payload = {
383
+ query : 'name: test' ,
384
+ action : BulkAction . edit ,
385
+ [ BulkAction . edit ] : [ { type : BulkActionEditType . add_rule_actions , value : [ ] } ] ,
386
+ } ;
387
+
388
+ const message = retrieveValidationMessage ( payload ) ;
389
+
390
+ expect ( getPaths ( left ( message . errors ) ) ) . toEqual (
391
+ expect . arrayContaining ( [ 'Invalid value "[]" supplied to "edit,value"' ] )
392
+ ) ;
393
+ expect ( message . schema ) . toEqual ( { } ) ;
394
+ } ) ;
395
+
396
+ test ( 'invalid request: missing throttle in payload' , ( ) => {
397
+ const payload = {
398
+ query : 'name: test' ,
399
+ action : BulkAction . edit ,
400
+ [ BulkAction . edit ] : [
401
+ {
402
+ type : BulkActionEditType . add_rule_actions ,
403
+ value : {
404
+ actions : [ ] ,
405
+ } ,
406
+ } ,
407
+ ] ,
408
+ } ;
409
+
410
+ const message = retrieveValidationMessage ( payload ) ;
411
+
412
+ expect ( getPaths ( left ( message . errors ) ) ) . toEqual (
413
+ expect . arrayContaining ( [ 'Invalid value "undefined" supplied to "edit,value,throttle"' ] )
414
+ ) ;
415
+ expect ( message . schema ) . toEqual ( { } ) ;
416
+ } ) ;
417
+
418
+ test ( 'invalid request: missing actions in payload' , ( ) => {
419
+ const payload = {
420
+ query : 'name: test' ,
421
+ action : BulkAction . edit ,
422
+ [ BulkAction . edit ] : [
423
+ {
424
+ type : BulkActionEditType . add_rule_actions ,
425
+ value : {
426
+ throttle : '1h' ,
427
+ } ,
428
+ } ,
429
+ ] ,
430
+ } ;
431
+
432
+ const message = retrieveValidationMessage ( payload ) ;
433
+
434
+ expect ( getPaths ( left ( message . errors ) ) ) . toEqual (
435
+ expect . arrayContaining ( [ 'Invalid value "undefined" supplied to "edit,value,actions"' ] )
436
+ ) ;
437
+ expect ( message . schema ) . toEqual ( { } ) ;
438
+ } ) ;
439
+
440
+ test ( 'invalid request: invalid action_type_id property in actions array' , ( ) => {
441
+ const payload = {
442
+ query : 'name: test' ,
443
+ action : BulkAction . edit ,
444
+ [ BulkAction . edit ] : [
445
+ {
446
+ type : BulkActionEditType . add_rule_actions ,
447
+ value : {
448
+ throttle : '1h' ,
449
+ actions : [
450
+ {
451
+ action_type_id : '.webhook' ,
452
+ group : 'default' ,
453
+ id : '458a50e0-1a28-11ed-9098-47fd8e1f3345' ,
454
+ params : {
455
+ body : {
456
+ rule_id : '{{rule.id}}' ,
457
+ } ,
458
+ } ,
459
+ } ,
460
+ ] ,
461
+ } ,
462
+ } ,
463
+ ] ,
464
+ } ;
465
+
466
+ const message = retrieveValidationMessage ( payload ) ;
467
+ expect ( getPaths ( left ( message . errors ) ) ) . toEqual (
468
+ expect . arrayContaining ( [ 'invalid keys "action_type_id"' ] )
469
+ ) ;
470
+ expect ( message . schema ) . toEqual ( { } ) ;
471
+ } ) ;
472
+
473
+ test ( 'valid request: add_rule_actions edit action' , ( ) => {
474
+ const payload : PerformBulkActionSchema = {
475
+ query : 'name: test' ,
476
+ action : BulkAction . edit ,
477
+ [ BulkAction . edit ] : [
478
+ {
479
+ type : BulkActionEditType . add_rule_actions ,
480
+ value : {
481
+ throttle : '1h' ,
482
+ actions : [
483
+ {
484
+ group : 'default' ,
485
+ id : '458a50e0-1a28-11ed-9098-47fd8e1f3345' ,
486
+ params : {
487
+ body : {
488
+ rule_id : '{{rule.id}}' ,
489
+ } ,
490
+ } ,
491
+ } ,
492
+ ] ,
493
+ } ,
494
+ } ,
495
+ ] ,
496
+ } ;
497
+
498
+ const message = retrieveValidationMessage ( payload ) ;
499
+
500
+ expect ( getPaths ( left ( message . errors ) ) ) . toEqual ( [ ] ) ;
501
+ expect ( message . schema ) . toEqual ( payload ) ;
502
+ } ) ;
503
+
504
+ test ( 'valid request: set_rule_actions edit action' , ( ) => {
505
+ const payload : PerformBulkActionSchema = {
506
+ query : 'name: test' ,
507
+ action : BulkAction . edit ,
508
+ [ BulkAction . edit ] : [
509
+ {
510
+ type : BulkActionEditType . set_rule_actions ,
511
+ value : {
512
+ throttle : '1h' ,
513
+ actions : [
514
+ {
515
+ group : 'default' ,
516
+ id : '458a50e0-1a28-11ed-9098-47fd8e1f3345' ,
517
+ params : {
518
+ documents : [
519
+ {
520
+ rule_id : '{{rule.id}}' ,
521
+ } ,
522
+ ] ,
523
+ } ,
524
+ } ,
525
+ ] ,
526
+ } ,
527
+ } ,
528
+ ] ,
529
+ } ;
530
+
531
+ const message = retrieveValidationMessage ( payload ) ;
532
+
533
+ expect ( getPaths ( left ( message . errors ) ) ) . toEqual ( [ ] ) ;
534
+ expect ( message . schema ) . toEqual ( payload ) ;
535
+ } ) ;
536
+ } ) ;
376
537
} ) ;
377
538
} ) ;
0 commit comments