Skip to content

Commit

Permalink
fix issue #393 by adjusting the default workspace for the source-code
Browse files Browse the repository at this point in the history
  • Loading branch information
northdpole committed Oct 3, 2024
1 parent 49b41f4 commit 87413c5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions components/producers/producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var (
)

const (
sourceDir = "/workspace/output"
sourceDir = "/workspace/output/source-code/"
)

var fileTargetPattern = regexp.MustCompile(`^(.*?:.*?):(.*)$`)
Expand Down Expand Up @@ -102,9 +102,9 @@ func WriteDraconOut(
source := getSource()
cleanIssues := []*draconapiv1.Issue{}
for _, iss := range issues {
iss.Description = strings.ReplaceAll(iss.Description, sourceDir, ".")
iss.Title = strings.ReplaceAll(iss.Title, sourceDir, ".")
iss.Target = strings.ReplaceAll(iss.Target, sourceDir, ".")
iss.Description = strings.ReplaceAll(iss.Description, sourceDir, "")
iss.Title = strings.ReplaceAll(iss.Title, sourceDir, "")
iss.Target = strings.ReplaceAll(iss.Target, sourceDir, "")
iss.Source = source
cleanIssues = append(cleanIssues, iss)
slog.Debug(fmt.Sprintf("found issue: %+v\n", iss))
Expand Down
12 changes: 6 additions & 6 deletions components/producers/producer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ func TestWriteDraconOut(t *testing.T) {
"dracon-test",
[]*v1.Issue{
{
Target: "/workspace/output/foobar",
Title: "/workspace/output/barfoo",
Description: "/workspace/output/example.yaml",
Target: "/workspace/output/source-code/foobar",
Title: "/workspace/output/source-code/barfoo",
Description: "/workspace/output/source-code/example.yaml",
Cve: "123-321",
},
},
Expand All @@ -75,9 +75,9 @@ func TestWriteDraconOut(t *testing.T) {
require.NoError(t, proto.Unmarshal(pBytes, &res))

assert.Equal(t, "dracon-test", res.GetToolName())
assert.Equal(t, "./foobar", res.GetIssues()[0].GetTarget())
assert.Equal(t, "./barfoo", res.GetIssues()[0].GetTitle())
assert.Equal(t, "./example.yaml", res.GetIssues()[0].GetDescription())
assert.Equal(t, "foobar", res.GetIssues()[0].GetTarget())
assert.Equal(t, "barfoo", res.GetIssues()[0].GetTitle())
assert.Equal(t, "example.yaml", res.GetIssues()[0].GetDescription())
assert.Equal(t, baseTime.Unix(), res.GetScanInfo().GetScanStartTime().GetSeconds())
assert.Equal(t, "ab3d3290-cd9f-482c-97dc-ec48bdfcc4de", res.GetScanInfo().GetScanUuid())
assert.Equal(t, "123-321", res.GetIssues()[0].GetCve())
Expand Down
2 changes: 1 addition & 1 deletion pkg/sarif/sarif.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func FromDraconRawIssuesRun(responses []*v1.LaunchToolResponse) (*sarif.Report,
}

func removeDraconInternalPath(target string) string {
return strings.Replace(target, "/workspace/output", "", 1)
return strings.Replace(target, "/workspace/output/source-code", "", 1)
}

func draconIssueToSarif(issue *v1.Issue, rule *sarif.ReportingDescriptor) (*sarif.Result, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/sarif/sarif_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ func Test_draconIssueToSarif(t *testing.T) {
Severity: v1.Severity_SEVERITY_INFO,
Cvss: 0.0,
Source: "//foo/bar:baz",
Target: "/workspace/output/foo1/bar1:baz2",
Target: "/workspace/output/source-code/foo1/bar1:baz2",
Title: "Unit Test Title",
Type: "test type",
Cve: "CVE-0000-99999",
Expand Down

0 comments on commit 87413c5

Please sign in to comment.