From b76064aab22283707188ed20616d49a081861217 Mon Sep 17 00:00:00 2001 From: hmmachadocx <91129244+hmmachadocx@users.noreply.github.com> Date: Fri, 30 Aug 2024 12:07:52 +0100 Subject: [PATCH] AST-32018: Support Critical Severity (#152) * Support Critical Severity * Display triage error message * Fix icons in second panel --------- Co-authored-by: Pedro Lopes --- .../icons/critical.png | Bin 0 -> 615 bytes .../checkmarx/eclipse/enums/ActionName.java | 1 + .../eclipse/views/CheckmarxView.java | 30 ++++++------------ .../checkmarx/eclipse/views/DataProvider.java | 20 +++++++++--- .../eclipse/views/filters/ActionFilters.java | 6 +++- .../eclipse/views/filters/FilterState.java | 8 +++++ 6 files changed, 39 insertions(+), 26 deletions(-) create mode 100644 checkmarx-ast-eclipse-plugin/icons/critical.png diff --git a/checkmarx-ast-eclipse-plugin/icons/critical.png b/checkmarx-ast-eclipse-plugin/icons/critical.png new file mode 100644 index 0000000000000000000000000000000000000000..ad86fc35a29e9e3c1ba2c771dcade5c933c601a0 GIT binary patch literal 615 zcmV-t0+{`YP)KqTl=PIe6> zPlZrWPzzRK7#Ml!5QNmBQxJIwB0EJEu2zQ#q@Z0wox>&=MY-0Jp$NLW^L1Fq9e2n1 zPA}j0{?GrtKl~6-@uueXv8b7fN6oe%pYm(IjU0+Nn%*Z$&LU_)P835pa;M!+rZ$Dd zqvrh(YL_5~fpEaZGYa(?apo;M83WKgw2OjN2CcnTVL`$u&&Lqb%^pnw$#*MK72sMHUoR$HktPyIB@+MJFH{Ako7nMtFEp+X;EPq zeCh7x@5fKfy&Pfr`ww!9OWw0tKS { selectedItem.setSeverity(selectedSeverity); selectedItem.setState(selectedState); @@ -1321,16 +1317,10 @@ protected IStatus run(IProgressMonitor arg0) { commentText.setText(PluginConstants.DEFAULT_COMMENT_TXT); commentText.setEditable(true); }); - } else { - // TODO: inform the user that update failed? -// sync.asyncExec(() -> { -// MessageBox box = new MessageBox(parent.getDisplay().getActiveShell(), SWT.CANCEL | SWT.OK); -// box.setText("Triage failed"); -// // correct the message -// box.setMessage("Triage update failed. Check logs"); -// box.open(); -// }); - + } catch (Exception e) { + sync.asyncExec(() -> { + new NotificationPopUpUI(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().getDisplay(), "Triage failed", e.getMessage(), null, null, null).open(); + }); } // reset the triageButton when triage update fails diff --git a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/DataProvider.java b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/DataProvider.java index d694f67..13f4b3e 100644 --- a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/DataProvider.java +++ b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/DataProvider.java @@ -6,6 +6,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Optional; @@ -38,6 +39,8 @@ public class DataProvider { + private static final List SEVERITY_ORDER = Arrays.asList("CRITICAL", "HIGH", "MEDIUM", "LOW", "INFO"); + private static final String LIMIT_FILTER="limit=10000"; private static final String FILTER_SCANS_FOR_PROJECT = "project-id=%s,branch=%s,limit=10000,statuses=Completed"; @@ -418,7 +421,7 @@ private Map> filterResultsByScannerType(List> filteredResultsByScannerType) { filteredResultsByScannerType.entrySet().stream().forEach(entry -> { - Map> mapBySeverity = new HashMap<>(); + Map> mapBySeverity = new LinkedHashMap<>(); String scanner = entry.getKey(); List vulnerabilities = entry.getValue(); @@ -432,6 +435,13 @@ private void groupResultsBySeverity(Map> filteredResu } } + Map> sortedMapBySeverity = new LinkedHashMap<>(); + SEVERITY_ORDER.forEach(severity -> { + if (mapBySeverity.containsKey(severity)) { + sortedMapBySeverity.put(severity, mapBySeverity.get(severity)); + } + }); + List children = createParentNodeByScanner(mapBySeverity); filteredResultsByScannerType.put(scanner, children); @@ -659,8 +669,9 @@ public List getTriageShow(UUID projectID, String similarityID, String * @param state * @param comment * @param severity + * @throws Exception */ - public boolean triageUpdate(UUID projectId, String similarityId, String engineType, String state, String comment, String severity) { + public void triageUpdate(UUID projectId, String similarityId, String engineType, String state, String comment, String severity) throws Exception { try { CxWrapper cxWrapper = authenticateWithAST(); @@ -668,11 +679,10 @@ public boolean triageUpdate(UUID projectId, String similarityId, String engineTy if (cxWrapper != null) { cxWrapper.triageUpdate(projectId, similarityId, engineType, state, comment, severity); } - - return true; } catch (Exception e) { CxLogger.error(String.format(PluginConstants.ERROR_UPDATING_TRIAGE, e.getMessage()), e); - return false; + throw new Exception(e.getMessage()); + } } diff --git a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/filters/ActionFilters.java b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/filters/ActionFilters.java index f467475..49a6ee0 100644 --- a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/filters/ActionFilters.java +++ b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/filters/ActionFilters.java @@ -14,6 +14,9 @@ public class ActionFilters { + private static final String ACTION_FILTER_CRITICAL_TOOLTIP = "Critical"; + private static final String ACTION_FILTER_CRITICAL_ICON_PATH = "/icons/critical.png"; + private static final String ACTION_FILTER_HIGH_TOOLTIP = "High"; private static final String ACTION_FILTER_HIGH_ICON_PATH = "/icons/high_untoggle.png"; @@ -42,12 +45,13 @@ public ActionFilters(EventBus pluginEventBus) { public List createFilterActions(){ List filters = new ArrayList<>(); + Action filterCriticalAction = createFilterAction(ACTION_FILTER_CRITICAL_TOOLTIP, ACTION_FILTER_CRITICAL_ICON_PATH, Severity.CRITICAL, ActionName.CRITICAL); Action filterHighAction = createFilterAction(ACTION_FILTER_HIGH_TOOLTIP, ACTION_FILTER_HIGH_ICON_PATH, Severity.HIGH, ActionName.HIGH); Action filterMediumAction = createFilterAction(ACTION_FILTER_MEDIUM_TOOLTIP, ACTION_FILTER_MEDIUM_ICON_PATH, Severity.MEDIUM, ActionName.MEDIUM); Action filterLowAction = createFilterAction(ACTION_FILTER_LOW_TOOLTIP, ACTION_FILTER_LOW_ICON_PATH, Severity.LOW, ActionName.LOW); Action filterInfoAction = createFilterAction(ACTION_FILTER_INFO_TOOLTIP, ACTION_FILTER_INFO_ICON_PATH, Severity.INFO, ActionName.INFO); - + filters.add(filterCriticalAction); filters.add(filterHighAction); filters.add(filterMediumAction); filters.add(filterLowAction); diff --git a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/filters/FilterState.java b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/filters/FilterState.java index b7c00c4..2ff44cc 100644 --- a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/filters/FilterState.java +++ b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/filters/FilterState.java @@ -7,6 +7,7 @@ public class FilterState { + public static boolean critical = true; public static boolean high = true; public static boolean medium = true; public static boolean low = false; @@ -30,6 +31,7 @@ public class FilterState { public static void loadFiltersFromSettings() { + critical = Boolean.parseBoolean(GlobalSettings.getFromPreferences(Severity.CRITICAL.name(), "true")); high = Boolean.parseBoolean(GlobalSettings.getFromPreferences(Severity.HIGH.name(), "true")); medium = Boolean.parseBoolean(GlobalSettings.getFromPreferences(Severity.MEDIUM.name(), "true")); low = Boolean.parseBoolean(GlobalSettings.getFromPreferences(Severity.LOW.name(), "false")); @@ -54,6 +56,10 @@ public static void loadFiltersFromSettings() { */ public static void setState(Severity severity) { switch(severity) { + case CRITICAL: + critical = !critical; + GlobalSettings.storeInPreferences(Severity.CRITICAL.name(), String.valueOf(critical)); + break; case HIGH: high = !high; GlobalSettings.storeInPreferences(Severity.HIGH.name(), String.valueOf(high)); @@ -147,6 +153,7 @@ public static boolean isFilterStateEnabled(String state) { */ public static boolean isSeverityEnabled(String severity) { switch(Severity.getSeverity(severity)) { + case CRITICAL: return critical; case HIGH: return high; case MEDIUM: return medium; case LOW: return low; @@ -165,6 +172,7 @@ public static boolean isSeverityEnabled(String severity) { * Reset filters state */ public static void resetFilters() { + critical = true; high = true; medium = true; low = false;