Skip to content

Commit

Permalink
fix bug #414 where the jira consumer would not create issues with zer…
Browse files Browse the repository at this point in the history
…o scanstart time
  • Loading branch information
northdpole committed Oct 11, 2024
1 parent 4489f0f commit 93a1f3a
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 18 deletions.
5 changes: 0 additions & 5 deletions components/consumers/jira/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 3 additions & 0 deletions pkg/jira/jira/apiutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package jira

import (
"testing"
"time"

Check failure on line 5 in pkg/jira/jira/apiutils_test.go

View workflow job for this annotation

GitHub Actions / Test

"time" imported and not used

Check failure on line 5 in pkg/jira/jira/apiutils_test.go

View workflow job for this annotation

GitHub Actions / Test

"time" imported and not used

jira "github.com/andygrunwald/go-jira"
"github.com/ocurity/dracon/pkg/jira/document"

Check failure on line 8 in pkg/jira/jira/apiutils_test.go

View workflow job for this annotation

GitHub Actions / Test

"github.com/ocurity/dracon/pkg/jira/document" imported and not used

Check failure on line 8 in pkg/jira/jira/apiutils_test.go

View workflow job for this annotation

GitHub Actions / Test

"github.com/ocurity/dracon/pkg/jira/document" imported and not used
"github.com/stretchr/testify/require"
"github.com/trivago/tgo/tcontainer"
)
Expand Down Expand Up @@ -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"
Expand Down
28 changes: 15 additions & 13 deletions pkg/templating/template_description.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "" {
Expand Down Expand Up @@ -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
}
}
Expand Down
51 changes: 51 additions & 0 deletions pkg/templating/template_description_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
}
}

0 comments on commit 93a1f3a

Please sign in to comment.