@@ -369,7 +369,7 @@ func restoreCampaigns(ctx context.Context, client graphql.Client, db string, ass
369369 // if it is not, throw an error
370370 for _ , serialized_tc := range c .TestCases {
371371 if _ , ok := outcomeStatusMap [serialized_tc .Status ]; ! ok {
372- slog .ErrorContext (ctx , "could not find outcome for this test case" , "outcome" , serialized_tc .Status , "test-case" , serialized_tc .Name , "campaign" , c .Name )
372+ slog .ErrorContext (ctx , "could not find outcome for this test case" , "outcome" , serialized_tc .Status , "test-case" , serialized_tc .Name , "campaign" , c .Name , "campaign-id" , c . Id , "test-case-id" , serialized_tc . Id )
373373 return fmt .Errorf ("outcome %s not found" , serialized_tc .Status )
374374 }
375375 testCaseData := dao.CreateTestCaseDataInput {
@@ -402,7 +402,7 @@ func restoreCampaigns(ctx context.Context, client graphql.Client, db string, ass
402402 //DefenseToolOutcomes: []DefenseToolOutcomeInput{}, // handle below
403403 }
404404 if testCaseData .AttackStart == 0 {
405- slog .WarnContext (ctx , "Attack Start is set to 0, reset to the AttackStop time" , "attack-stop-time" , testCaseData .AttackStop )
405+ slog .WarnContext (ctx , "Attack Start is set to 0, reset to the AttackStop time" , "attack-stop-time" , testCaseData .AttackStop , "campaign-name" , c . Name , "test-case-name" , serialized_tc . Name )
406406 testCaseData .AttackStart = testCaseData .AttackStop
407407 }
408408 for _ , tag := range serialized_tc .Tags {
@@ -426,7 +426,22 @@ func restoreCampaigns(ctx context.Context, client graphql.Client, db string, ass
426426 testCaseData .RedTeamMetadata = append (testCaseData .RedTeamMetadata , dao .MetadataKeyValuePairInput (md ))
427427 }
428428 if serialized_tc .AutomationCmd != "" {
429- testCaseData .AttackAutomation = buildAttackAutomationInput (& serialized_tc )
429+ var errors []error
430+ testCaseData .AttackAutomation , errors = buildAttackAutomationInput (& serialized_tc )
431+ if len (errors ) > 0 {
432+ for _ , err := range errors {
433+ slog .WarnContext (ctx , "parsing discrepencies found, they were recovered but review if needed" ,
434+ "test-case-id" , serialized_tc .Id ,
435+ "test-case-name" , serialized_tc .Name ,
436+ "campaign" , c .Name ,
437+ "campaign-id" , c .Id ,
438+ "assessment-name" , assessmentName ,
439+ "db" , db ,
440+ "err" , err ,
441+ )
442+
443+ }
444+ }
430445 }
431446 for _ , redtool := range serialized_tc .RedTools {
432447 testCaseData .RedTools = append (testCaseData .RedTools , dao.RedToolInput {
@@ -608,7 +623,21 @@ func RestoreAssessment(ctx context.Context, client graphql.Client, db string, ad
608623 if len (ad .LibraryTestCases ) > 0 {
609624 for _ , template_test_case := range ad .LibraryTestCases {
610625 slog .DebugContext (ctx , "library test case" , "name" , template_test_case .Name , "template_id" , template_test_case .LibraryTestCaseId )
611- input .TestCaseTemplateData = append (input .TestCaseTemplateData , createTemplateData (template_test_case ))
626+ tctd , errors := createTemplateData (template_test_case )
627+ if len (errors ) > 0 {
628+ for _ , err := range errors {
629+ slog .WarnContext (ctx , "parsing discrepencies found, they were recovered but review if needed" ,
630+ "test-case-id" , template_test_case .Id ,
631+ "test-case-library-id" , template_test_case .LibraryTestCaseId ,
632+ "test-case-name" , template_test_case .Name ,
633+ "assessment-name" , ad .Assessment .Name ,
634+ "db" , db ,
635+ "err" , err ,
636+ )
637+
638+ }
639+ }
640+ input .TestCaseTemplateData = append (input .TestCaseTemplateData , tctd )
612641 }
613642
614643 _ , err := dao .CreateTemplateTestCases (ctx , client , input )
@@ -781,7 +810,8 @@ func loadVatMetadata(md []dao.GetAllAssessmentsAssessmentsAssessmentConnectionNo
781810 return md
782811}
783812
784- func createTemplateData (template_test_case dao.GetLibraryTestCasesLibraryTestcasesByIdsTestCaseConnectionNodesTestCase ) dao.CreateTestCaseTemplateDataInput {
813+ func createTemplateData (template_test_case dao.GetLibraryTestCasesLibraryTestcasesByIdsTestCaseConnectionNodesTestCase ) (dao.CreateTestCaseTemplateDataInput , []error ) {
814+ var errors []error
785815 ttc := dao.CreateTestCaseTemplateDataInput {
786816 LibraryTestCaseId : template_test_case .LibraryTestCaseId ,
787817 Name : template_test_case .Name ,
@@ -815,7 +845,7 @@ func createTemplateData(template_test_case dao.GetLibraryTestCasesLibraryTestcas
815845 ttc .BlueTeamMetadata = append (ttc .BlueTeamMetadata , dao .MetadataKeyValuePairInput (md ))
816846 }
817847 if template_test_case .AutomationCmd != "" {
818- ttc .AttackAutomation = buildAttackAutomationInput (& template_test_case )
848+ ttc .AttackAutomation , errors = buildAttackAutomationInput (& template_test_case )
819849 }
820850 // check for the prefix
821851 for _ , md := range template_test_case .Metadata {
@@ -828,31 +858,34 @@ func createTemplateData(template_test_case dao.GetLibraryTestCasesLibraryTestcas
828858 break
829859 }
830860 }
831- return ttc
861+ return ttc , errors
832862}
833863
834- func buildAttackAutomationInput [A AutomationArgumentTypes , PA pointerAutomationArgs [A ], T Automator [A ]](automator T ) * dao.AttackAutomationInput {
864+ func buildAttackAutomationInput [A AutomationArgumentTypes , PA pointerAutomationArgs [A ], T Automator [A ]](automator T ) ( * dao.AttackAutomationInput , [] error ) {
835865 attackAutomation := & dao.AttackAutomationInput {
836866 Command : automator .GetAutomationCmd (),
837867 Executor : executorMap [automator .GetAutomationExecutor ()],
838868 CleanupCommand : automator .GetAutomationCleanup (),
839869 CleanupExecutor : executorMap [automator .GetAutomationCleanupExecutor ()],
840870 }
841871 args := automator .GetAutomationArgument ()
872+ errors := make ([]error , 0 , len (args ))
842873 for _ , autoArg := range args {
843874 pointerAutoArg := PA (& autoArg )
844875 // set the default type to be a string, if it is set to path we will use that, else use the string
845876 argTypeDefault := dao .AutomationVarTypeString
846- if dao .AutomationVarType (strings .ToUpper (pointerAutoArg .GetArgumentValue ())) == dao .AutomationVarTypePath {
877+ if dao .AutomationVarType (strings .ToUpper (pointerAutoArg .GetArgumentType ())) == dao .AutomationVarTypePath {
847878 argTypeDefault = dao .AutomationVarTypePath
879+ } else {
880+ errors = append (errors , fmt .Errorf ("cmd: %s, arugment: %s with the value: %s has the type: %s, resetting to %s" , automator .GetAutomationCmd (), pointerAutoArg .GetArgumentKey (), pointerAutoArg .GetArgumentValue (), pointerAutoArg .GetArgumentType (), dao .AutomationVarTypeString ))
848881 }
849882 attackAutomation .AttackVariables = append (attackAutomation .AttackVariables , dao.AttackAutomationVariable {
850883 InputName : pointerAutoArg .GetArgumentKey (),
851884 InputValue : pointerAutoArg .GetArgumentValue (),
852885 Type : argTypeDefault ,
853886 })
854887 }
855- return attackAutomation
888+ return attackAutomation , errors
856889}
857890
858891func ParseLibraryTestcasesByIdsError (e string ) ([]string , error ) {
0 commit comments