Skip to content
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

AST-32018: Support Critical Severity #152

Merged
merged 4 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added checkmarx-ast-eclipse-plugin/icons/critical.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

public enum ActionName {

CRITICAL,
HIGH,
MEDIUM,
LOW,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public class CheckmarxView extends ViewPart implements EventHandler {
public static final Image CHECKMARX_OPEN_SETTINGS_LOGO = Activator.getImageDescriptor("/icons/checkmarx-80.png")
.createImage();

public static final Image CRITICAL_SEVERITY = Activator.getImageDescriptor("/icons/severity-critical.png")
public static final Image CRITICAL_SEVERITY = Activator.getImageDescriptor("/icons/critical.png")
.createImage();

public static final Image HIGH_SEVERITY = Activator.getImageDescriptor("/icons/high_untoggle.png").createImage();
Expand Down Expand Up @@ -1213,14 +1213,10 @@ protected IStatus run(IProgressMonitor arg0) {
}

private void populateTitleLabel(DisplayModel selectedItem) {
ImageData titleImageData = findSeverityImage(selectedItem).getImageData()
.scaledTo(PluginConstants.TITLE_LABEL_WIDTH, PluginConstants.TITLE_LABEL_HEIGHT);
Image titleImage = new Image(parent.getShell().getDisplay(), titleImageData);
titleLabel.setImage(titleImage);
titleLabel.setImage(findSeverityImage(selectedItem));
titleText.setText(selectedItem.getName());
titleLabel.layout();
titleText.requestLayout();

}
});
}
Expand All @@ -1233,7 +1229,7 @@ private void populateTitleLabel(DisplayModel selectedItem) {
private void createTriageSeverityAndStateCombos(DisplayModel selectedItem) {
String currentSeverity = selectedItem.getSeverity();
selectedSeverity = selectedItem.getSeverity();
String[] severity = { "HIGH", "MEDIUM", "LOW", "INFO" };
String[] severity = { "CRITICAL", "HIGH", "MEDIUM", "LOW", "INFO" };

triageSeverityComboViewew.setContentProvider(ArrayContentProvider.getInstance());
triageSeverityComboViewew.setInput(severity);
Expand Down Expand Up @@ -1303,9 +1299,9 @@ public void widgetSelected(SelectionEvent event) {

@Override
protected IStatus run(IProgressMonitor arg0) {
boolean successfullyUpdate = DataProvider.getInstance().triageUpdate(projectId,
similarityId, engineType, selectedState, comment, selectedSeverity);
if (successfullyUpdate) {
try {
DataProvider.getInstance().triageUpdate(projectId,similarityId, engineType, selectedState, comment, selectedSeverity);
sync.asyncExec(() -> {
selectedItem.setSeverity(selectedSeverity);
selectedItem.setState(selectedState);
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -38,6 +39,8 @@

public class DataProvider {

private static final List<String> 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";

Expand Down Expand Up @@ -418,7 +421,7 @@ private Map<String, List<DisplayModel>> filterResultsByScannerType(List<DisplayM
private void groupResultsBySeverity(Map<String, List<DisplayModel>> filteredResultsByScannerType) {
filteredResultsByScannerType.entrySet().stream().forEach(entry -> {

Map<String, List<DisplayModel>> mapBySeverity = new HashMap<>();
Map<String, List<DisplayModel>> mapBySeverity = new LinkedHashMap<>();
String scanner = entry.getKey();
List<DisplayModel> vulnerabilities = entry.getValue();

Expand All @@ -432,6 +435,13 @@ private void groupResultsBySeverity(Map<String, List<DisplayModel>> filteredResu
}
}

Map<String, List<DisplayModel>> sortedMapBySeverity = new LinkedHashMap<>();
SEVERITY_ORDER.forEach(severity -> {
if (mapBySeverity.containsKey(severity)) {
sortedMapBySeverity.put(severity, mapBySeverity.get(severity));
}
});

List<DisplayModel> children = createParentNodeByScanner(mapBySeverity);

filteredResultsByScannerType.put(scanner, children);
Expand Down Expand Up @@ -659,20 +669,20 @@ public List<Predicate> 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();

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());

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -42,12 +45,13 @@ public ActionFilters(EventBus pluginEventBus) {
public List<Action> createFilterActions(){
List<Action> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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"));
Expand All @@ -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));
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Loading