@@ -503,7 +503,7 @@ func TestReportStepEnd(t *testing.T) {
503
503
mock_time .AssertExpectations (t )
504
504
}
505
505
506
- func TestInvalidStepReport (t * testing.T ) {
506
+ func TestInvalidStepReportAfterExecutionEnd (t * testing.T ) {
507
507
mock_time := new (mock_time.MockTime )
508
508
cacheReporter := cache .New (mock_time )
509
509
@@ -578,7 +578,87 @@ func TestInvalidStepReport(t *testing.T) {
578
578
t .Fail ()
579
579
}
580
580
581
- expectedErr := errors .New ("trying to report on the execution of a step for a completed or failed execution" )
581
+ expectedErr := errors .New ("trying to report on the execution of a step for an already reported completed or failed execution" )
582
+ assert .Equal (t , err , expectedErr )
583
+ mock_time .AssertExpectations (t )
584
+ }
585
+
586
+ func TestInvalidStepReportAfterStepEnd (t * testing.T ) {
587
+ mock_time := new (mock_time.MockTime )
588
+ cacheReporter := cache .New (mock_time )
589
+
590
+ expectedCommand := cacao.Command {
591
+ Type : "ssh" ,
592
+ Command : "ssh ls -la" ,
593
+ }
594
+
595
+ expectedVariables := cacao.Variable {
596
+ Type : "string" ,
597
+ Name : "var1" ,
598
+ Value : "testing" ,
599
+ }
600
+
601
+ step1 := cacao.Step {
602
+ Type : "action" ,
603
+ ID : "action--test" ,
604
+ Name : "ssh-tests" ,
605
+ StepVariables : cacao .NewVariables (expectedVariables ),
606
+ Commands : []cacao.Command {expectedCommand },
607
+ Cases : map [string ]string {},
608
+ OnCompletion : "end--test" ,
609
+ Agent : "agent1" ,
610
+ Targets : []string {"target1" },
611
+ }
612
+
613
+ end := cacao.Step {
614
+ Type : "end" ,
615
+ ID : "end--test" ,
616
+ Name : "end step" ,
617
+ }
618
+
619
+ expectedAuth := cacao.AuthenticationInformation {
620
+ Name : "user" ,
621
+ ID : "auth1" ,
622
+ }
623
+
624
+ expectedTarget := cacao.AgentTarget {
625
+ Name : "sometarget" ,
626
+ AuthInfoIdentifier : "auth1" ,
627
+ ID : "target1" ,
628
+ }
629
+
630
+ expectedAgent := cacao.AgentTarget {
631
+ Type : "soarca" ,
632
+ Name : "soarca-ssh" ,
633
+ }
634
+
635
+ playbook := cacao.Playbook {
636
+ ID : "test" ,
637
+ Type : "test" ,
638
+ Name : "ssh-test" ,
639
+ WorkflowStart : step1 .ID ,
640
+ AuthenticationInfoDefinitions : map [string ]cacao.AuthenticationInformation {"id" : expectedAuth },
641
+ AgentDefinitions : map [string ]cacao.AgentTarget {"agent1" : expectedAgent },
642
+ TargetDefinitions : map [string ]cacao.AgentTarget {"target1" : expectedTarget },
643
+
644
+ Workflow : map [string ]cacao.Step {step1 .ID : step1 , end .ID : end },
645
+ }
646
+ executionId0 , _ := uuid .Parse ("6ba7b810-9dad-11d1-80b4-00c04fd430c0" )
647
+ layout := "2006-01-02T15:04:05.000Z"
648
+ str := "2014-11-12T11:45:26.371Z"
649
+ timeNow , _ := time .Parse (layout , str )
650
+ mock_time .On ("Now" ).Return (timeNow )
651
+
652
+ cacheReporter .ReportWorkflowStart (executionId0 , playbook )
653
+ cacheReporter .ReportStepStart (executionId0 , step1 , cacao .NewVariables (expectedVariables ))
654
+ cacheReporter .ReportStepEnd (executionId0 , step1 , cacao .NewVariables (expectedVariables ), nil )
655
+ err := cacheReporter .ReportStepEnd (executionId0 , step1 , cacao .NewVariables (expectedVariables ), nil )
656
+
657
+ if err == nil {
658
+ t .Fail ()
659
+ }
660
+
661
+ expectedErr := errors .New ("trying to report on the execution of a step that was already reported completed or failed" )
582
662
assert .Equal (t , err , expectedErr )
583
663
mock_time .AssertExpectations (t )
584
664
}
0 commit comments