Skip to content

Commit c5f9495

Browse files
feat: fake ignore findings [IDE-176] (#8)
1 parent ed28820 commit c5f9495

File tree

3 files changed

+55
-3
lines changed

3 files changed

+55
-3
lines changed

sarif_types.go

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
//nolint:revive,tagliatelle // These are all SARIF documented types that need to match the exact JSON format.
1818
package codeclient
1919

20+
// SarifResponse matches the spec in https://docs.oasis-open.org/sarif/sarif/v2.1.0/os/schemas/sarif-schema-2.1.0.json
2021
type SarifResponse struct {
2122
Type string `json:"type"`
2223
Progress float64 `json:"progress"`
@@ -101,6 +102,7 @@ type Result struct {
101102
Fingerprints Fingerprints `json:"Fingerprints"`
102103
CodeFlows []CodeFlow `json:"codeFlows"`
103104
Properties ResultProperties `json:"properties"`
105+
Suppressions []Suppression `json:"suppressions"`
104106
}
105107

106108
type ExampleCommitFix struct {
@@ -164,7 +166,7 @@ type Tool struct {
164166
Driver Driver `json:"Driver"`
165167
}
166168

167-
type runProperties struct {
169+
type RunProperties struct {
168170
Coverage []struct {
169171
Files int `json:"files"`
170172
IsSupported bool `json:"isSupported"`
@@ -175,5 +177,30 @@ type runProperties struct {
175177
type Run struct {
176178
Tool Tool `json:"Tool"`
177179
Results []Result `json:"results"`
178-
Properties runProperties `json:"RuleProperties"`
180+
Properties RunProperties `json:"RuleProperties"`
181+
}
182+
183+
type Suppression struct {
184+
Justification string `json:"justification"`
185+
Properties SuppressionProperties `json:"properties"`
186+
}
187+
188+
type SuppressionProperties struct {
189+
Category Category `json:"category"`
190+
Expiration *string `json:"expiration"`
191+
IgnoredOn string `json:"ignoredOn"` // https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/sarif-v2.1.0-errata01-os-complete.html#_Toc141790703
192+
IgnoredBy IgnoredBy `json:"ignoredBy"`
193+
}
194+
195+
type Category string
196+
197+
const (
198+
WontFix Category = "wont-fix"
199+
NotVulnerable Category = "not-vulnerable"
200+
TemporaryIgnore Category = "temporary-ignore"
201+
)
202+
203+
type IgnoredBy struct {
204+
Name string `json:"name"`
205+
Email *string `json:"email"`
179206
}

scan.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,20 @@ var fakeResponse = `{
524524
"[java.lang.InterruptedException](0)"
525525
]
526526
},
527+
"suppressions": [
528+
{
529+
"justification": "False positive",
530+
"properties": {
531+
"category": "wont-fix",
532+
"expiration": "13 days",
533+
"ignoredOn": "2024-02-23T16:08:25Z",
534+
"ignoredBy": {
535+
"name": "Neil M",
536+
"email": "[email protected]"
537+
}
538+
}
539+
}
540+
],
527541
"locations": [
528542
{
529543
"PhysicalLocation": {

scan_test.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,24 @@ package codeclient_test
33
import (
44
"testing"
55

6-
codeClient "github.com/snyk/code-client-go"
76
"github.com/stretchr/testify/assert"
87
"github.com/stretchr/testify/require"
8+
9+
codeClient "github.com/snyk/code-client-go"
910
)
1011

1112
func TestUploadAndAnalyze(t *testing.T) {
1213
actual, err := codeClient.UploadAndAnalyze()
1314
require.NoError(t, err)
1415
assert.Equal(t, "COMPLETE", actual.Status)
16+
assert.Contains(t, actual.Sarif.Runs[0].Results[0].Locations[0].PhysicalLocation.ArtifactLocation.URI, "src/main.ts")
17+
assert.Nil(t, actual.Sarif.Runs[0].Results[0].Suppressions)
18+
assert.NotNil(t, actual.Sarif.Runs[0].Results[1].Suppressions)
19+
assert.Len(t, actual.Sarif.Runs[0].Results[1].Suppressions, 1)
20+
assert.Equal(t, "False positive", actual.Sarif.Runs[0].Results[1].Suppressions[0].Justification)
21+
assert.Equal(t, codeClient.WontFix, actual.Sarif.Runs[0].Results[1].Suppressions[0].Properties.Category)
22+
assert.Equal(t, "13 days", *actual.Sarif.Runs[0].Results[1].Suppressions[0].Properties.Expiration)
23+
assert.Equal(t, "2024-02-23T16:08:25Z", actual.Sarif.Runs[0].Results[1].Suppressions[0].Properties.IgnoredOn)
24+
assert.Equal(t, "Neil M", actual.Sarif.Runs[0].Results[1].Suppressions[0].Properties.IgnoredBy.Name)
25+
assert.Equal(t, "[email protected]", *actual.Sarif.Runs[0].Results[1].Suppressions[0].Properties.IgnoredBy.Email)
1526
}

0 commit comments

Comments
 (0)