Skip to content

Commit ce32ebc

Browse files
authored
feat: add unknown severity handling to DockerfileAnnotator (TC-4728) (#260)
Add UNKNOWN branch to getSeverity() cascade, ranked below LOW. Bump trustify-da-api-spec from 2.0.8 to 2.0.9 for the new UNKNOWN enum value. Add comprehensive tests for severity cascade logic. Implements TC-4728 Assisted-by: Claude Code
1 parent 102ce59 commit ce32ebc

3 files changed

Lines changed: 113 additions & 1 deletion

File tree

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
caffeine = "3.1.8"
44
commons-compress = "1.21"
55
commons-io = "2.16.1"
6-
trustify-da-api-spec = "2.0.8"
6+
trustify-da-api-spec = "2.0.9"
77
trustify-da-java-client = "0.0.17"
88
github-api = "1.314"
99
junit = "4.13.2"

src/main/java/org/jboss/tools/intellij/image/DockerfileAnnotator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ static Severity getSeverity(Source source) {
5959
severity = Severity.MEDIUM;
6060
} else if (source.getSummary().getLow() != null && source.getSummary().getLow() > 0) {
6161
severity = Severity.LOW;
62+
} else if (source.getSummary().getUnknown() != null && source.getSummary().getUnknown() > 0) {
63+
severity = Severity.UNKNOWN;
6264
}
6365
}
6466
return severity;
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 Red Hat, Inc.
3+
* Distributed under license by Red Hat, Inc. All rights reserved.
4+
* This program is made available under the terms of the
5+
* Eclipse Public License v2.0 which accompanies this distribution,
6+
* and is available at http://www.eclipse.org/legal/epl-v20.html
7+
*
8+
* Contributors:
9+
* Red Hat, Inc. - initial API and implementation
10+
******************************************************************************/
11+
12+
package org.jboss.tools.intellij.image;
13+
14+
import io.github.guacsec.trustifyda.api.v5.Severity;
15+
import io.github.guacsec.trustifyda.api.v5.Source;
16+
import io.github.guacsec.trustifyda.api.v5.SourceSummary;
17+
import org.junit.Test;
18+
19+
import static org.junit.Assert.assertEquals;
20+
import static org.junit.Assert.assertNull;
21+
22+
/**
23+
* Tests for {@link DockerfileAnnotator#getSeverity(Source)} severity cascade logic.
24+
*/
25+
public class DockerfileAnnotatorTest {
26+
27+
private static Source createSourceWithSummary(Integer critical, Integer high, Integer medium, Integer low, Integer unknown) {
28+
var summary = new SourceSummary();
29+
summary.setCritical(critical);
30+
summary.setHigh(high);
31+
summary.setMedium(medium);
32+
summary.setLow(low);
33+
summary.setUnknown(unknown);
34+
var source = new Source();
35+
source.setSummary(summary);
36+
return source;
37+
}
38+
39+
/**
40+
* Verifies that critical severity takes precedence over all others.
41+
*/
42+
@Test
43+
public void testGetSeverityCritical() {
44+
Source source = createSourceWithSummary(1, 2, 3, 4, 5);
45+
assertEquals(Severity.CRITICAL, DockerfileAnnotator.getSeverity(source));
46+
}
47+
48+
/**
49+
* Verifies that high severity is returned when no critical vulnerabilities exist.
50+
*/
51+
@Test
52+
public void testGetSeverityHigh() {
53+
Source source = createSourceWithSummary(0, 1, 2, 3, 4);
54+
assertEquals(Severity.HIGH, DockerfileAnnotator.getSeverity(source));
55+
}
56+
57+
/**
58+
* Verifies that medium severity is returned when no critical or high vulnerabilities exist.
59+
*/
60+
@Test
61+
public void testGetSeverityMedium() {
62+
Source source = createSourceWithSummary(0, 0, 1, 2, 3);
63+
assertEquals(Severity.MEDIUM, DockerfileAnnotator.getSeverity(source));
64+
}
65+
66+
/**
67+
* Verifies that low severity is returned when no critical, high, or medium vulnerabilities exist.
68+
*/
69+
@Test
70+
public void testGetSeverityLow() {
71+
Source source = createSourceWithSummary(0, 0, 0, 1, 2);
72+
assertEquals(Severity.LOW, DockerfileAnnotator.getSeverity(source));
73+
}
74+
75+
/**
76+
* Verifies that unknown severity is returned when only unknown-severity vulnerabilities exist.
77+
*/
78+
@Test
79+
public void testGetSeverityUnknown() {
80+
Source source = createSourceWithSummary(0, 0, 0, 0, 1);
81+
assertEquals(Severity.UNKNOWN, DockerfileAnnotator.getSeverity(source));
82+
}
83+
84+
/**
85+
* Verifies that null is returned when no vulnerabilities of any severity exist.
86+
*/
87+
@Test
88+
public void testGetSeverityNone() {
89+
Source source = createSourceWithSummary(0, 0, 0, 0, 0);
90+
assertNull(DockerfileAnnotator.getSeverity(source));
91+
}
92+
93+
/**
94+
* Verifies that null is returned when summary is null.
95+
*/
96+
@Test
97+
public void testGetSeverityNullSummary() {
98+
var source = new Source();
99+
assertNull(DockerfileAnnotator.getSeverity(source));
100+
}
101+
102+
/**
103+
* Verifies that null is returned when all severity counts are null.
104+
*/
105+
@Test
106+
public void testGetSeverityNullCounts() {
107+
Source source = createSourceWithSummary(null, null, null, null, null);
108+
assertNull(DockerfileAnnotator.getSeverity(source));
109+
}
110+
}

0 commit comments

Comments
 (0)