Skip to content

Commit 26a95b3

Browse files
authored
Ignore suppressed issues by default (#964)
1 parent 81a3a34 commit 26a95b3

File tree

9 files changed

+368
-1
lines changed

9 files changed

+368
-1
lines changed

docs/input/documentation/issue-providers/sarif/features.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ The [Cake.Issues.Sarif addin](https://cakebuild.net/extensions/cake-issues-sarif
99
## Basic features
1010

1111
- [x] Reads issues from files in [SARIF](https://sarifweb.azurewebsites.net/){target="_blank"} format.
12+
- [x] Support for reading issues reported as suppressed by the linter
1213

1314
## Supported IIssue properties
1415

src/Cake.Issues.Sarif.Tests/SarifIssuesProviderFixture.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@ internal class SarifIssuesProviderFixture(string fileResourceName)
55
{
66
public bool UseToolNameAsIssueProviderName { get; set; } = true;
77

8+
public bool IgnoreSuppressedIssues { get; set; } = true;
9+
810
protected override string FileResourceNamespace => "Cake.Issues.Sarif.Tests.Testfiles.";
911

1012
protected override SarifIssuesSettings CreateIssueProviderSettings()
1113
{
1214
var settings = base.CreateIssueProviderSettings();
1315
settings.UseToolNameAsIssueProviderName = this.UseToolNameAsIssueProviderName;
16+
settings.IgnoreSuppressedIssues = this.IgnoreSuppressedIssues;
1417
return settings;
1518
}
1619

src/Cake.Issues.Sarif.Tests/SarifIssuesProviderTests.cs

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@ public void Should_Read_Issue_Correct_For_Recommended_File_With_Source()
9494
public void Should_Read_Issue_Correct_For_Comprehensive_File()
9595
{
9696
// Given
97-
var fixture = new SarifIssuesProviderFixture("comprehensive.sarif");
97+
var fixture = new SarifIssuesProviderFixture("comprehensive.sarif")
98+
{
99+
IgnoreSuppressedIssues = false
100+
};
98101

99102
// When
100103
var issues = fixture.ReadIssues().ToList();
@@ -118,6 +121,86 @@ public void Should_Read_Issue_Correct_For_Comprehensive_File()
118121
.Create());
119122
}
120123

124+
[Fact]
125+
public void Should_Ignore_Suppressed_Issues_If_IgnoreSuppressedIssues_Is_Enabled()
126+
{
127+
// Given
128+
var fixture = new SarifIssuesProviderFixture("suppression-without-status.sarif")
129+
{
130+
IgnoreSuppressedIssues = true
131+
};
132+
133+
// When
134+
var issues = fixture.ReadIssues().ToList();
135+
136+
// Then
137+
issues.Count.ShouldBe(0);
138+
}
139+
140+
[Fact]
141+
public void Should_Read_Suppressed_Issues_If_IgnoreSuppressedIssues_Is_Disabled()
142+
{
143+
// Given
144+
var fixture = new SarifIssuesProviderFixture("suppression-without-status.sarif")
145+
{
146+
IgnoreSuppressedIssues = false
147+
};
148+
149+
// When
150+
var issues = fixture.ReadIssues().ToList();
151+
152+
// Then
153+
issues.Count.ShouldBe(1);
154+
}
155+
156+
[Fact]
157+
public void Should_Ignore_Suppressed_Issues_With_Status_Accepted()
158+
{
159+
// Given
160+
var fixture = new SarifIssuesProviderFixture("suppression-accepted.sarif")
161+
{
162+
IgnoreSuppressedIssues = true
163+
};
164+
165+
// When
166+
var issues = fixture.ReadIssues().ToList();
167+
168+
// Then
169+
issues.Count.ShouldBe(0);
170+
}
171+
172+
[Fact]
173+
public void Should_Read_Suppressed_Issues_With_Status_Under_Review()
174+
{
175+
// Given
176+
var fixture = new SarifIssuesProviderFixture("suppression-under-review.sarif")
177+
{
178+
IgnoreSuppressedIssues = true
179+
};
180+
181+
// When
182+
var issues = fixture.ReadIssues().ToList();
183+
184+
// Then
185+
issues.Count.ShouldBe(1);
186+
}
187+
188+
[Fact]
189+
public void Should_Read_Suppressed_Issues_With_Status_Rejected()
190+
{
191+
// Given
192+
var fixture = new SarifIssuesProviderFixture("suppression-rejected.sarif")
193+
{
194+
IgnoreSuppressedIssues = true
195+
};
196+
197+
// When
198+
var issues = fixture.ReadIssues().ToList();
199+
200+
// Then
201+
issues.Count.ShouldBe(1);
202+
}
203+
121204
[Fact]
122205
public void Should_Consider_UseToolNameAsIssueProviderName()
123206
{
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
3+
"version": "2.1.0",
4+
"runs": [
5+
{
6+
"tool": {
7+
"driver": {
8+
"name": "Checkov",
9+
"version": "3.2.351",
10+
"informationUri": "https://checkov.io",
11+
"rules": [
12+
{
13+
"id": "CKV_DOCKER_3",
14+
"name": "Ensure that a user for the container has been created",
15+
"shortDescription": {
16+
"text": "Ensure that a user for the container has been created"
17+
},
18+
"fullDescription": {
19+
"text": "Ensure that a user for the container has been created"
20+
},
21+
"help": {
22+
"text": "Ensure that a user for the container has been created\nResource: /TenantInstance/TenantInstance.Frontend/Dockerfile."
23+
},
24+
"defaultConfiguration": {
25+
"level": "error"
26+
},
27+
"helpUri": "https://docs.prismacloud.io/en/enterprise-edition/policy-reference/docker-policies/docker-policy-index/ensure-that-a-user-for-the-container-has-been-created"
28+
}
29+
],
30+
"organization": "bridgecrew"
31+
}
32+
},
33+
"results": [
34+
{
35+
"ruleId": "CKV_DOCKER_3",
36+
"ruleIndex": 0,
37+
"level": "warning",
38+
"attachments": [],
39+
"message": {
40+
"text": "Ensure that a user for the container has been created"
41+
},
42+
"locations": [
43+
{
44+
"physicalLocation": {
45+
"artifactLocation": {
46+
"uri": "src/Dockerfile"
47+
},
48+
"region": {
49+
"startLine": 1,
50+
"endLine": 24
51+
}
52+
}
53+
}
54+
],
55+
"suppressions": [
56+
{
57+
"kind": "external",
58+
"status": "accepted",
59+
"justification": " Is not used in production and therefore is OK to run as root user"
60+
}
61+
]
62+
}
63+
]
64+
}
65+
]
66+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
3+
"version": "2.1.0",
4+
"runs": [
5+
{
6+
"tool": {
7+
"driver": {
8+
"name": "Checkov",
9+
"version": "3.2.351",
10+
"informationUri": "https://checkov.io",
11+
"rules": [
12+
{
13+
"id": "CKV_DOCKER_3",
14+
"name": "Ensure that a user for the container has been created",
15+
"shortDescription": {
16+
"text": "Ensure that a user for the container has been created"
17+
},
18+
"fullDescription": {
19+
"text": "Ensure that a user for the container has been created"
20+
},
21+
"help": {
22+
"text": "Ensure that a user for the container has been created\nResource: /TenantInstance/TenantInstance.Frontend/Dockerfile."
23+
},
24+
"defaultConfiguration": {
25+
"level": "error"
26+
},
27+
"helpUri": "https://docs.prismacloud.io/en/enterprise-edition/policy-reference/docker-policies/docker-policy-index/ensure-that-a-user-for-the-container-has-been-created"
28+
}
29+
],
30+
"organization": "bridgecrew"
31+
}
32+
},
33+
"results": [
34+
{
35+
"ruleId": "CKV_DOCKER_3",
36+
"ruleIndex": 0,
37+
"level": "warning",
38+
"attachments": [],
39+
"message": {
40+
"text": "Ensure that a user for the container has been created"
41+
},
42+
"locations": [
43+
{
44+
"physicalLocation": {
45+
"artifactLocation": {
46+
"uri": "src/Dockerfile"
47+
},
48+
"region": {
49+
"startLine": 1,
50+
"endLine": 24
51+
}
52+
}
53+
}
54+
],
55+
"suppressions": [
56+
{
57+
"kind": "external",
58+
"status": "rejected",
59+
"justification": " Is not used in production and therefore is OK to run as root user"
60+
}
61+
]
62+
}
63+
]
64+
}
65+
]
66+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
3+
"version": "2.1.0",
4+
"runs": [
5+
{
6+
"tool": {
7+
"driver": {
8+
"name": "Checkov",
9+
"version": "3.2.351",
10+
"informationUri": "https://checkov.io",
11+
"rules": [
12+
{
13+
"id": "CKV_DOCKER_3",
14+
"name": "Ensure that a user for the container has been created",
15+
"shortDescription": {
16+
"text": "Ensure that a user for the container has been created"
17+
},
18+
"fullDescription": {
19+
"text": "Ensure that a user for the container has been created"
20+
},
21+
"help": {
22+
"text": "Ensure that a user for the container has been created\nResource: /TenantInstance/TenantInstance.Frontend/Dockerfile."
23+
},
24+
"defaultConfiguration": {
25+
"level": "error"
26+
},
27+
"helpUri": "https://docs.prismacloud.io/en/enterprise-edition/policy-reference/docker-policies/docker-policy-index/ensure-that-a-user-for-the-container-has-been-created"
28+
}
29+
],
30+
"organization": "bridgecrew"
31+
}
32+
},
33+
"results": [
34+
{
35+
"ruleId": "CKV_DOCKER_3",
36+
"ruleIndex": 0,
37+
"level": "warning",
38+
"attachments": [],
39+
"message": {
40+
"text": "Ensure that a user for the container has been created"
41+
},
42+
"locations": [
43+
{
44+
"physicalLocation": {
45+
"artifactLocation": {
46+
"uri": "src/Dockerfile"
47+
},
48+
"region": {
49+
"startLine": 1,
50+
"endLine": 24
51+
}
52+
}
53+
}
54+
],
55+
"suppressions": [
56+
{
57+
"kind": "external",
58+
"status": "underReview",
59+
"justification": " Is not used in production and therefore is OK to run as root user"
60+
}
61+
]
62+
}
63+
]
64+
}
65+
]
66+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
3+
"version": "2.1.0",
4+
"runs": [
5+
{
6+
"tool": {
7+
"driver": {
8+
"name": "Checkov",
9+
"version": "3.2.351",
10+
"informationUri": "https://checkov.io",
11+
"rules": [
12+
{
13+
"id": "CKV_DOCKER_3",
14+
"name": "Ensure that a user for the container has been created",
15+
"shortDescription": {
16+
"text": "Ensure that a user for the container has been created"
17+
},
18+
"fullDescription": {
19+
"text": "Ensure that a user for the container has been created"
20+
},
21+
"help": {
22+
"text": "Ensure that a user for the container has been created\nResource: /TenantInstance/TenantInstance.Frontend/Dockerfile."
23+
},
24+
"defaultConfiguration": {
25+
"level": "error"
26+
},
27+
"helpUri": "https://docs.prismacloud.io/en/enterprise-edition/policy-reference/docker-policies/docker-policy-index/ensure-that-a-user-for-the-container-has-been-created"
28+
}
29+
],
30+
"organization": "bridgecrew"
31+
}
32+
},
33+
"results": [
34+
{
35+
"ruleId": "CKV_DOCKER_3",
36+
"ruleIndex": 0,
37+
"level": "warning",
38+
"attachments": [],
39+
"message": {
40+
"text": "Ensure that a user for the container has been created"
41+
},
42+
"locations": [
43+
{
44+
"physicalLocation": {
45+
"artifactLocation": {
46+
"uri": "src/Dockerfile"
47+
},
48+
"region": {
49+
"startLine": 1,
50+
"endLine": 24
51+
}
52+
}
53+
}
54+
],
55+
"suppressions": [
56+
{
57+
"kind": "inSource",
58+
"justification": " Is not used in production and therefore is OK to run as root user"
59+
}
60+
]
61+
}
62+
]
63+
}
64+
]
65+
}

0 commit comments

Comments
 (0)