Repository navigation
Add configurable Severity Threshold for Dev Assist realtime scanners (AST-197154) #297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
cx-aniket-shinde
wants to merge
10
commits into
main
Choose a base branch
from
feature/severity-threshold-AST-195881
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3f55f4b
Add configurable severity threshold for Dev Assist realtime scanners …
cx-aniket-shinde dc1bfa3
Align severity threshold description with VS Code extension (AST-197154)
cx-aniket-shinde 9bccc9e
Match severity threshold hint text to the design in AST-195881
cx-aniket-shinde cf5db6c
Join severity hint labels with commas and a final ampersand
cx-aniket-shinde 5b5d4f2
Escape ampersand in severity hint so SWT label displays it
cx-aniket-shinde 161f545
Address review comments on severity threshold (AST-195881)
cx-aniket-shinde fce8b32
Update PluginConstants.java
cx-aniket-shinde 258790f
Remove Info from severity threshold options and add info hint box (AS…
cx-aniket-shinde 6c1595f
Fix AST-195881: clear all findings on severity threshold change, then…
cx-aniket-shinde 4212792
Fix AST-195881: reword severity threshold description and hint text
cx-aniket-shinde File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 2.4.33 | ||
| dev | ||
166 changes: 166 additions & 0 deletions
166
...kmarx/ast/eclipse/plugin/tests/unit/devassist/backend/SeverityThresholdRescannerTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,166 @@ | ||
| package checkmarx.ast.eclipse.plugin.tests.unit.devassist.backend; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertNotSame; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.LinkedHashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import com.checkmarx.eclipse.common.preferences.SeverityThreshold; | ||
| import com.checkmarx.eclipse.devassist.backend.SeverityThresholdRescanner; | ||
| import com.checkmarx.eclipse.devassist.model.ScanIssue; | ||
|
|
||
| /** | ||
| * Tests the pure decisions of the severity threshold change: which files are remembered for the rescan | ||
| * (taken BEFORE everything is cleared) and which earlier findings are put back when a rescan fails. | ||
| */ | ||
| class SeverityThresholdRescannerTest { | ||
|
|
||
| private static ScanIssue issue(String id, String severity) { | ||
| ScanIssue issue = new ScanIssue(); | ||
| issue.setScanIssueId(id); | ||
| issue.setSeverity(severity); | ||
| return issue; | ||
| } | ||
|
|
||
| private static List<String> ids(List<ScanIssue> issues) { | ||
| List<String> ids = new ArrayList<>(); | ||
| for (ScanIssue issue : issues) { | ||
| ids.add(issue.getScanIssueId()); | ||
| } | ||
| return ids; | ||
| } | ||
|
|
||
| // ---- snapshotOfFilesWithFindings ---- | ||
|
|
||
| @Test | ||
| void snapshotKeepsOnlyFilesThatHaveFindings() { | ||
| Map<String, List<ScanIssue>> all = new LinkedHashMap<>(); | ||
| all.put("a.java", List.of(issue("1", "HIGH"))); | ||
| all.put("empty.java", new ArrayList<>()); | ||
| all.put("null.java", null); | ||
| all.put(null, List.of(issue("2", "HIGH"))); | ||
|
|
||
| Map<String, List<ScanIssue>> snapshot = SeverityThresholdRescanner.snapshotOfFilesWithFindings(all); | ||
|
|
||
| assertEquals(List.of("a.java"), new ArrayList<>(snapshot.keySet())); | ||
| assertEquals(List.of("1"), ids(snapshot.get("a.java"))); | ||
| } | ||
|
|
||
| @Test | ||
| void snapshotOfNullOrEmptyIsEmpty() { | ||
| assertTrue(SeverityThresholdRescanner.snapshotOfFilesWithFindings(null).isEmpty()); | ||
| assertTrue(SeverityThresholdRescanner.snapshotOfFilesWithFindings(new LinkedHashMap<>()).isEmpty()); | ||
| } | ||
|
|
||
| @Test | ||
| void snapshotIsNotAffectedWhenTheSourceIsClearedAfterwards() { | ||
| // The rescan list must survive clearing the results store. | ||
| List<ScanIssue> source = new ArrayList<>(List.of(issue("1", "HIGH"), issue("2", "LOW"))); | ||
| Map<String, List<ScanIssue>> all = new LinkedHashMap<>(); | ||
| all.put("a.java", source); | ||
|
|
||
| Map<String, List<ScanIssue>> snapshot = SeverityThresholdRescanner.snapshotOfFilesWithFindings(all); | ||
| source.clear(); | ||
| all.clear(); | ||
|
|
||
| assertEquals(List.of("a.java"), new ArrayList<>(snapshot.keySet())); | ||
| assertEquals(List.of("1", "2"), ids(snapshot.get("a.java"))); | ||
| assertNotSame(source, snapshot.get("a.java")); | ||
| } | ||
|
|
||
| @Test | ||
| void snapshotKeepsFileOrder() { | ||
| Map<String, List<ScanIssue>> all = new LinkedHashMap<>(); | ||
| all.put("c.java", List.of(issue("3", "HIGH"))); | ||
| all.put("a.java", List.of(issue("1", "HIGH"))); | ||
| all.put("b.java", List.of(issue("2", "HIGH"))); | ||
|
|
||
| assertEquals(Arrays.asList("c.java", "a.java", "b.java"), | ||
| new ArrayList<>(SeverityThresholdRescanner.snapshotOfFilesWithFindings(all).keySet())); | ||
| } | ||
|
|
||
| // ---- findingsStillShownAt ---- | ||
|
|
||
| @Test | ||
| void highThresholdKeepsCriticalAndHighOnly() { | ||
| List<ScanIssue> previous = List.of(issue("c", "CRITICAL"), issue("h", "HIGH"), issue("m", "MEDIUM"), | ||
| issue("l", "LOW")); | ||
|
|
||
| assertEquals(List.of("c", "h"), ids(SeverityThresholdRescanner.findingsStillShownAt(previous, | ||
| SeverityThreshold.HIGH))); | ||
| } | ||
|
|
||
| @Test | ||
| void criticalThresholdKeepsCriticalOnly() { | ||
| List<ScanIssue> previous = List.of(issue("c", "CRITICAL"), issue("h", "HIGH")); | ||
|
|
||
| assertEquals(List.of("c"), ids(SeverityThresholdRescanner.findingsStillShownAt(previous, | ||
| SeverityThreshold.CRITICAL))); | ||
| } | ||
|
|
||
| @Test | ||
| void lowThresholdKeepsEverythingExceptInfo() { | ||
| List<ScanIssue> previous = List.of(issue("c", "CRITICAL"), issue("l", "LOW"), issue("i", "INFO")); | ||
|
|
||
| assertEquals(List.of("c", "l"), ids(SeverityThresholdRescanner.findingsStillShownAt(previous, | ||
| SeverityThreshold.LOW))); | ||
| } | ||
|
|
||
| @Test | ||
| void maliciousOkAndUnknownAreAlwaysKept() { | ||
| List<ScanIssue> previous = List.of(issue("m", "MALICIOUS"), issue("o", "OK"), issue("u", "UNKNOWN"), | ||
| issue("l", "LOW")); | ||
|
|
||
| assertEquals(List.of("m", "o", "u"), ids(SeverityThresholdRescanner.findingsStillShownAt(previous, | ||
| SeverityThreshold.CRITICAL))); | ||
| } | ||
|
|
||
| @Test | ||
| void severityMatchIsCaseInsensitive() { | ||
| List<ScanIssue> previous = List.of(issue("h", "high"), issue("m", "Medium")); | ||
|
|
||
| assertEquals(List.of("h"), ids(SeverityThresholdRescanner.findingsStillShownAt(previous, | ||
| SeverityThreshold.HIGH))); | ||
| } | ||
|
|
||
| @Test | ||
| void missingSeverityIsKept() { | ||
| List<ScanIssue> previous = List.of(issue("n", null), issue("b", " ")); | ||
|
|
||
| assertEquals(List.of("n", "b"), ids(SeverityThresholdRescanner.findingsStillShownAt(previous, | ||
| SeverityThreshold.CRITICAL))); | ||
| } | ||
|
|
||
| @Test | ||
| void nullInputsGiveNothing() { | ||
| assertTrue(SeverityThresholdRescanner.findingsStillShownAt(null, SeverityThreshold.HIGH).isEmpty()); | ||
| assertTrue(SeverityThresholdRescanner.findingsStillShownAt(List.of(issue("h", "HIGH")), null).isEmpty()); | ||
| } | ||
|
|
||
| @Test | ||
| void nullEntriesAreSkipped() { | ||
| List<ScanIssue> previous = new ArrayList<>(); | ||
| previous.add(null); | ||
| previous.add(issue("h", "HIGH")); | ||
|
|
||
| assertEquals(List.of("h"), ids(SeverityThresholdRescanner.findingsStillShownAt(previous, | ||
| SeverityThreshold.HIGH))); | ||
| } | ||
|
|
||
| @Test | ||
| void resultIsACopy() { | ||
| List<ScanIssue> previous = new ArrayList<>(List.of(issue("h", "HIGH"))); | ||
|
|
||
| List<ScanIssue> kept = SeverityThresholdRescanner.findingsStillShownAt(previous, SeverityThreshold.HIGH); | ||
| previous.clear(); | ||
|
|
||
| assertEquals(List.of("h"), ids(kept)); | ||
| } | ||
| } |
108 changes: 108 additions & 0 deletions
108
...c/test/java/checkmarx/ast/eclipse/plugin/tests/unit/properties/SeverityThresholdTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| package checkmarx.ast.eclipse.plugin.tests.unit.properties; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
| import static org.junit.jupiter.api.Assertions.assertSame; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import com.checkmarx.eclipse.common.preferences.SeverityThreshold; | ||
|
|
||
| class SeverityThresholdTest { | ||
|
|
||
| @Test | ||
| void defaultIsHigh() { | ||
| assertSame(SeverityThreshold.HIGH, SeverityThreshold.DEFAULT); | ||
| } | ||
|
|
||
| @Test | ||
| void levelsAreOrderedFromCriticalToLow() { | ||
| assertEquals(List.of(SeverityThreshold.CRITICAL, SeverityThreshold.HIGH, SeverityThreshold.MEDIUM, | ||
| SeverityThreshold.LOW), List.of(SeverityThreshold.values())); | ||
| } | ||
|
|
||
| @Test | ||
| void cliValueIsLowerCase() { | ||
| assertEquals("critical", SeverityThreshold.CRITICAL.getCliValue()); | ||
| assertEquals("high", SeverityThreshold.HIGH.getCliValue()); | ||
| assertEquals("medium", SeverityThreshold.MEDIUM.getCliValue()); | ||
| assertEquals("low", SeverityThreshold.LOW.getCliValue()); | ||
| } | ||
|
|
||
| @Test | ||
| void labelsAreDisplayNames() { | ||
| assertEquals("Critical", SeverityThreshold.CRITICAL.getLabel()); | ||
| assertEquals("High", SeverityThreshold.HIGH.toString()); | ||
| } | ||
|
|
||
| @Test | ||
| void fromValueIsCaseInsensitiveAndTrims() { | ||
| assertSame(SeverityThreshold.MEDIUM, SeverityThreshold.fromValue("medium")); | ||
| assertSame(SeverityThreshold.MEDIUM, SeverityThreshold.fromValue("MEDIUM")); | ||
| assertSame(SeverityThreshold.LOW, SeverityThreshold.fromValue(" Low ")); | ||
| } | ||
|
|
||
| @Test | ||
| void fromValueFallsBackToDefaultForMissingOrInvalid() { | ||
| assertSame(SeverityThreshold.DEFAULT, SeverityThreshold.fromValue(null)); | ||
| assertSame(SeverityThreshold.DEFAULT, SeverityThreshold.fromValue("")); | ||
| assertSame(SeverityThreshold.DEFAULT, SeverityThreshold.fromValue(" ")); | ||
| assertSame(SeverityThreshold.DEFAULT, SeverityThreshold.fromValue("not-a-level")); | ||
| assertSame(SeverityThreshold.DEFAULT, SeverityThreshold.fromValue("malicious")); | ||
| } | ||
|
|
||
| @Test | ||
| void fromLabelMatchesDropDownEntries() { | ||
| for (SeverityThreshold level : SeverityThreshold.values()) { | ||
| assertSame(level, SeverityThreshold.fromLabel(level.getLabel())); | ||
| } | ||
| assertSame(SeverityThreshold.DEFAULT, SeverityThreshold.fromLabel("")); | ||
| } | ||
|
|
||
| @Test | ||
| void includedLabelsListThisLevelAndEverythingMoreSevere() { | ||
| assertEquals(List.of("Critical"), SeverityThreshold.CRITICAL.getIncludedLabels()); | ||
| assertEquals(List.of("Critical", "High"), SeverityThreshold.HIGH.getIncludedLabels()); | ||
| assertEquals(List.of("Critical", "High", "Medium", "Low"), SeverityThreshold.LOW.getIncludedLabels()); | ||
| } | ||
|
|
||
| @Test | ||
| void highReportsCriticalAndHighOnly() { | ||
| SeverityThreshold high = SeverityThreshold.HIGH; | ||
| assertTrue(high.includes("CRITICAL")); | ||
| assertTrue(high.includes("High")); | ||
| assertFalse(high.includes("medium")); | ||
| assertFalse(high.includes("LOW")); | ||
| assertFalse(high.includes("Info")); | ||
| } | ||
|
|
||
| @Test | ||
| void lowReportsEverythingExceptInfo() { | ||
| for (String severity : new String[] { "critical", "high", "medium", "low" }) { | ||
| assertTrue(SeverityThreshold.LOW.includes(severity), severity); | ||
| } | ||
| assertFalse(SeverityThreshold.LOW.includes("info")); | ||
| } | ||
|
|
||
| @Test | ||
| void criticalReportsOnlyCritical() { | ||
| assertTrue(SeverityThreshold.CRITICAL.includes("critical")); | ||
| assertFalse(SeverityThreshold.CRITICAL.includes("high")); | ||
| } | ||
|
|
||
| @Test | ||
| void missingOrUnrecognisedSeverityIsAlwaysIncluded() { | ||
| // Malicious, OK and Unknown are not threshold levels, so the threshold never hides them. | ||
| for (SeverityThreshold level : SeverityThreshold.values()) { | ||
| assertTrue(level.includes(null), level + " null"); | ||
| assertTrue(level.includes(""), level + " empty"); | ||
| assertTrue(level.includes(" "), level + " blank"); | ||
| assertTrue(level.includes("MALICIOUS"), level + " malicious"); | ||
| assertTrue(level.includes("OK"), level + " ok"); | ||
| assertTrue(level.includes("UNKNOWN"), level + " unknown"); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.