Jelajahi Sumber

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

* add tags support for csv and sarif formats

* add tests
eyalatox 2 tahun lalu
induk
melakukan
86197b0848

+ 3 - 0
report/csv.go

@@ -4,6 +4,7 @@ import (
 	"encoding/csv"
 	"io"
 	"strconv"
+	"strings"
 )
 
 // writeCsv writes the list of findings to a writeCloser.
@@ -28,6 +29,7 @@ func writeCsv(f []Finding, w io.WriteCloser) error {
 		"Date",
 		"Email",
 		"Fingerprint",
+		"Tags",
 	})
 	if err != nil {
 		return err
@@ -48,6 +50,7 @@ func writeCsv(f []Finding, w io.WriteCloser) error {
 			f.Date,
 			f.Email,
 			f.Fingerprint,
+			strings.Join(f.Tags, " "),
 		})
 		if err != nil {
 			return err

+ 1 - 0
report/csv_test.go

@@ -35,6 +35,7 @@ func TestWriteCSV(t *testing.T) {
 					Email:       "johndoe@gmail.com",
 					Date:        "10-19-2003",
 					Fingerprint: "fingerprint",
+					Tags:        []string{"tag1", "tag2", "tag3"},
 				},
 			}},
 		{

+ 8 - 0
report/sarif.go

@@ -104,6 +104,9 @@ func getResults(findings []Finding) []Results {
 				Date:          f.Date,
 				Author:        f.Author,
 			},
+			Properties: Properties{
+				Tags: f.Tags,
+			},
 		}
 		results = append(results, r)
 	}
@@ -203,11 +206,16 @@ type Locations struct {
 	PhysicalLocation PhysicalLocation `json:"physicalLocation"`
 }
 
+type Properties struct {
+	Tags []string `json:"tags"`
+}
+
 type Results struct {
 	Message             Message     `json:"message"`
 	RuleId              string      `json:"ruleId"`
 	Locations           []Locations `json:"locations"`
 	PartialFingerPrints `json:"partialFingerprints"`
+	Properties          Properties `json:"properties"`
 }
 
 type Runs struct {

+ 1 - 1
report/sarif_test.go

@@ -43,7 +43,7 @@ func TestWriteSarif(t *testing.T) {
 					Author:      "John Doe",
 					Email:       "johndoe@gmail.com",
 					Date:        "10-19-2003",
-					Tags:        []string{},
+					Tags:        []string{"tag1", "tag2", "tag3"},
 				},
 			}},
 	}

+ 2 - 2
testdata/expected/report/csv_simple.csv

@@ -1,2 +1,2 @@
-RuleID,Commit,File,SymlinkFile,Secret,Match,StartLine,EndLine,StartColumn,EndColumn,Author,Message,Date,Email,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
+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,tag1 tag2 tag3

+ 7 - 0
testdata/expected/report/sarif_simple.sarif

@@ -294,6 +294,13 @@
       "author": "John Doe",
       "date": "10-19-2003",
       "commitMessage": "opps"
+     },
+     "properties": {
+      "tags": [
+       "tag1",
+       "tag2",
+       "tag3"
+      ]
      }
     }
    ]