add tags support for csv and sarif formats (#1176)

* add tags support for csv and sarif formats

* add tests
This commit is contained in:
eyalatox authored and GitHub committed 2023-06-15 07:16:23 -05:00
1 parent 3f894cbafc
commit 86197b0848
6 files changed
+22 -3

No files matched your search

+3
View File
@@ -4,6 +4,7 @@ import (
"encoding/csv" "encoding/csv"
"io" "io"
"strconv" "strconv"
"strings"
) )
// writeCsv writes the list of findings to a writeCloser. // writeCsv writes the list of findings to a writeCloser.
@@ -28,6 +29,7 @@ func writeCsv(f []Finding, w io.WriteCloser) error {
"Date", "Date",
"Email", "Email",
"Fingerprint", "Fingerprint",
"Tags",
}) })
if err != nil { if err != nil {
return err return err
@@ -48,6 +50,7 @@ func writeCsv(f []Finding, w io.WriteCloser) error {
f.Date, f.Date,
f.Email, f.Email,
f.Fingerprint, f.Fingerprint,
strings.Join(f.Tags, " "),
}) })
if err != nil { if err != nil {
return err return err
+1
View File
@@ -35,6 +35,7 @@ func TestWriteCSV(t *testing.T) {
Email: "johndoe@gmail.com", Email: "johndoe@gmail.com",
Date: "10-19-2003", Date: "10-19-2003",
Fingerprint: "fingerprint", Fingerprint: "fingerprint",
Tags: []string{"tag1", "tag2", "tag3"},
}, },
}}, }},
{ {
+8
View File
@@ -104,6 +104,9 @@ func getResults(findings []Finding) []Results {
Date: f.Date, Date: f.Date,
Author: f.Author, Author: f.Author,
}, },
Properties: Properties{
Tags: f.Tags,
},
} }
results = append(results, r) results = append(results, r)
} }
@@ -203,11 +206,16 @@ type Locations struct {
PhysicalLocation PhysicalLocation `json:"physicalLocation"` PhysicalLocation PhysicalLocation `json:"physicalLocation"`
} }
type Properties struct {
Tags []string `json:"tags"`
}
type Results struct { type Results struct {
Message Message `json:"message"` Message Message `json:"message"`
RuleId string `json:"ruleId"` RuleId string `json:"ruleId"`
Locations []Locations `json:"locations"` Locations []Locations `json:"locations"`
PartialFingerPrints `json:"partialFingerprints"` PartialFingerPrints `json:"partialFingerprints"`
Properties Properties `json:"properties"`
} }
type Runs struct { type Runs struct {
+1 -1
View File
@@ -43,7 +43,7 @@ func TestWriteSarif(t *testing.T) {
Author: "John Doe", Author: "John Doe",
Email: "johndoe@gmail.com", Email: "johndoe@gmail.com",
Date: "10-19-2003", Date: "10-19-2003",
Tags: []string{}, Tags: []string{"tag1", "tag2", "tag3"},
}, },
}}, }},
} }
+2 -2
View File
@@ -1,2 +1,2 @@
RuleID,Commit,File,SymlinkFile,Secret,Match,StartLine,EndLine,StartColumn,EndColumn,Author,Message,Date,Email,Fingerprint RuleID,Commit,File,SymlinkFile,Secret,Match,StartLine,EndLine,StartColumn,EndColumn,Author,Message,Date,Email,Fingerprint,Tags
test-rule,0000000000000000,auth.py,,a secret,line containing secret,1,2,1,2,John Doe,opps,10-19-2003,johndoe@gmail.com,fingerprint test-rule,0000000000000000,auth.py,,a secret,line containing secret,1,2,1,2,John Doe,opps,10-19-2003,johndoe@gmail.com,fingerprint,tag1 tag2 tag3
1 RuleID Commit File SymlinkFile Secret Match StartLine EndLine StartColumn EndColumn Author Message Date Email Fingerprint Tags
2 test-rule 0000000000000000 auth.py a secret line containing secret 1 2 1 2 John Doe opps 10-19-2003 johndoe@gmail.com fingerprint tag1 tag2 tag3
+7
View File
@@ -294,6 +294,13 @@
"author": "John Doe", "author": "John Doe",
"date": "10-19-2003", "date": "10-19-2003",
"commitMessage": "opps" "commitMessage": "opps"
},
"properties": {
"tags": [
"tag1",
"tag2",
"tag3"
]
} }
} }
] ]