diff --git a/components/consumers/jira/utils/utils.go b/components/consumers/jira/utils/utils.go index 10ed296b3..e01285b9b 100644 --- a/components/consumers/jira/utils/utils.go +++ b/components/consumers/jira/utils/utils.go @@ -21,11 +21,6 @@ func ProcessMessages(allowDuplicates, allowFP bool, sevThreshold int) ([]documen return nil, 0, err } messages, discarded := ProcessRawMessages(responses, sevThreshold) - if err != nil { - log.Print("Could not Process Raw Messages: ", err) - return nil, 0, err - } - return messages, discarded, nil } log.Print("Parsing Enriched results") diff --git a/pkg/jira/jira/apiutils_test.go b/pkg/jira/jira/apiutils_test.go index 8215004c9..b4137446c 100644 --- a/pkg/jira/jira/apiutils_test.go +++ b/pkg/jira/jira/apiutils_test.go @@ -2,8 +2,10 @@ package jira import ( "testing" + "time" jira "github.com/andygrunwald/go-jira" + "github.com/ocurity/dracon/pkg/jira/document" "github.com/stretchr/testify/require" "github.com/trivago/tgo/tcontainer" ) @@ -65,6 +67,7 @@ func TestMakeDescription(t *testing.T) { require.Equal(t, res, exp) } + func TestMakeSummary(t *testing.T) { res, extra := makeSummary(sampleResult) exp := "bar1:baz2 Unit Test Title" diff --git a/pkg/templating/template_description.go b/pkg/templating/template_description.go index 5e0491cbe..5dd746539 100644 --- a/pkg/templating/template_description.go +++ b/pkg/templating/template_description.go @@ -58,16 +58,6 @@ func EnrichedIssueWithToolName(toolname string) enrichedIssueOption { } } -func EnrichedIssueWithScanStartTime(startTime time.Time) enrichedIssueOption { - return func(ei *enrichedIssue) error { - if time.Time.IsZero(startTime) { - return errors.New("invalid startTime zero") - } - ei.ScanStartTime = startTime.Format(time.RFC3339) - return nil - } -} - func EnrichedIssueWithConfidenceText(confidence string) enrichedIssueOption { return func(ei *enrichedIssue) error { if confidence == "" { @@ -108,12 +98,24 @@ func EnrichedIssueWithScanID(scanID string) enrichedIssueOption { } } +func EnrichedIssueWithScanStartTime(startTime time.Time) enrichedIssueOption { + return func(ei *enrichedIssue) error { + st := startTime.Format(time.RFC3339) + if startTime.IsZero() { + return errors.Errorf("invalid startTime zero: %s", st) + } + ei.ScanStartTime = st + return nil + } +} + func EnrichedIssueWithFirstFound(firstFound time.Time) enrichedIssueOption { return func(ei *enrichedIssue) error { - if time.Time.IsZero(firstFound) { - return errors.New("invalid firstFound zero") + ff := firstFound.Format(time.RFC3339) + if firstFound.IsZero() { + return errors.Errorf("invalid firstFound zero %s", ff) } - ei.FirstFound = firstFound.Format(time.RFC3339) + ei.FirstFound = ff return nil } } diff --git a/pkg/templating/template_description_test.go b/pkg/templating/template_description_test.go index 3d8cb7e0c..e00db49b1 100644 --- a/pkg/templating/template_description_test.go +++ b/pkg/templating/template_description_test.go @@ -138,3 +138,54 @@ func Test_TemplateStringEnriched(t *testing.T) { }) } } + +func TestDescriptionOptions(t *testing.T) { + type args struct { + option enrichedIssueOption + } + + acceptableTime, err := time.Parse(time.RFC3339, "2024-10-10T20:06:33Z") + require.NoError(t, err) + tests := []struct { + name string + args args + wantErr bool + }{ + { + name: "zero startTime returns err", + args: args{ + option: EnrichedIssueWithScanStartTime(time.Time{}), + }, + wantErr: true, + }, + { + name: "non zero startTime returns no err", + args: args{ + option: EnrichedIssueWithScanStartTime(acceptableTime), + }, + wantErr: false, + }, + { + name: "zero firstFound returns err", + args: args{ + option: EnrichedIssueWithFirstFound(time.Time{}), + }, + wantErr: true, + }, + { + name: "non zero firstFound returns no err", + args: args{ + option: EnrichedIssueWithFirstFound(acceptableTime), + }, + wantErr: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := tt.args.option(&enrichedIssue{}) + if tt.wantErr { + require.Error(t, err) + } + }) + } +}