diff --git a/checkmarx-ast-eclipse-plugin-tests/src/test/java/checkmarx/ast/eclipse/plugin/tests/unit/runner/AuthenticatorTest.java b/checkmarx-ast-eclipse-plugin-tests/src/test/java/checkmarx/ast/eclipse/plugin/tests/unit/runner/AuthenticatorTest.java index 740e12a6..3df473f4 100644 --- a/checkmarx-ast-eclipse-plugin-tests/src/test/java/checkmarx/ast/eclipse/plugin/tests/unit/runner/AuthenticatorTest.java +++ b/checkmarx-ast-eclipse-plugin-tests/src/test/java/checkmarx/ast/eclipse/plugin/tests/unit/runner/AuthenticatorTest.java @@ -7,12 +7,14 @@ import org.junit.jupiter.api.Test; import org.mockito.MockedConstruction; +import org.mockito.MockedStatic; import org.mockito.Mockito; import org.slf4j.Logger; import com.checkmarx.ast.wrapper.CxException; import com.checkmarx.ast.wrapper.CxWrapper; import com.checkmarx.eclipse.runner.Authenticator; +import com.checkmarx.eclipse.utils.CxLogger; import com.checkmarx.eclipse.utils.PluginConstants; class AuthenticatorTest { @@ -24,14 +26,15 @@ void testDoAuthenticationSuccess() throws Exception { try (MockedConstruction mocked = Mockito.mockConstruction(CxWrapper.class, - (mock, context) -> when(mock.authValidate()).thenReturn("SUCCESS"))) { + (mock, context) -> when(mock.authValidate()).thenReturn("SUCCESS")); + MockedStatic mockedCxLogger = Mockito.mockStatic(CxLogger.class)) { Authenticator authenticator = new Authenticator(mockLogger); String result = authenticator.doAuthentication("dummyKey", "--param"); assertEquals("SUCCESS", result); - verify(mockLogger).info("Authentication Status: SUCCESS"); + mockedCxLogger.verify(() -> CxLogger.info(String.format(PluginConstants.INFO_AUTHENTICATION_STATUS, "SUCCESS"))); } } @@ -43,17 +46,18 @@ void testDoAuthenticationIOException() throws Exception { try (MockedConstruction mocked = Mockito.mockConstruction(CxWrapper.class, (mock, context) -> when(mock.authValidate()) - .thenThrow(new IOException("IO error")))) { + .thenThrow(new IOException("IO error"))); + MockedStatic mockedCxLogger = Mockito.mockStatic(CxLogger.class)) { Authenticator authenticator = new Authenticator(mockLogger); String result = authenticator.doAuthentication("dummyKey", "--param"); assertEquals("IO error", result); - verify(mockLogger).error( - eq(String.format(PluginConstants.ERROR_AUTHENTICATING_AST, "IO error")), - any(IOException.class) - ); + mockedCxLogger.verify(() -> CxLogger.error( + eq(String.format(PluginConstants.ERROR_AUTHENTICATING_AST, "IO error")), + any(IOException.class) + )); } } @@ -65,17 +69,18 @@ void testDoAuthenticationInterruptedException() throws Exception { try (MockedConstruction mocked = Mockito.mockConstruction(CxWrapper.class, (mock, context) -> when(mock.authValidate()) - .thenThrow(new InterruptedException("Interrupted")))) { + .thenThrow(new InterruptedException("Interrupted"))); + MockedStatic mockedCxLogger = Mockito.mockStatic(CxLogger.class)) { Authenticator authenticator = new Authenticator(mockLogger); String result = authenticator.doAuthentication("dummyKey", "--param"); assertEquals("Interrupted", result); - verify(mockLogger).error( - eq(String.format(PluginConstants.ERROR_AUTHENTICATING_AST, "Interrupted")), - any(InterruptedException.class) - ); + mockedCxLogger.verify(() -> CxLogger.error( + eq(String.format(PluginConstants.ERROR_AUTHENTICATING_AST, "Interrupted")), + any(InterruptedException.class) + )); } } @@ -87,17 +92,18 @@ void testDoAuthenticationCxException() throws Exception { try (MockedConstruction mocked = Mockito.mockConstruction(CxWrapper.class, (mock, context) -> when(mock.authValidate()) - .thenThrow(new CxException(1, "Cx error")))) { + .thenThrow(new CxException(1, "Cx error"))); + MockedStatic mockedCxLogger = Mockito.mockStatic(CxLogger.class)) { Authenticator authenticator = new Authenticator(mockLogger); String result = authenticator.doAuthentication("dummyKey", "--param"); assertEquals("Cx error", result); - verify(mockLogger).error( - eq(String.format(PluginConstants.ERROR_AUTHENTICATING_AST, "Cx error")), - any(CxException.class) - ); + mockedCxLogger.verify(() -> CxLogger.error( + eq(String.format(PluginConstants.ERROR_AUTHENTICATING_AST, "Cx error")), + any(CxException.class) + )); } } diff --git a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/runner/Authenticator.java b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/runner/Authenticator.java index 9484950e..202baa99 100644 --- a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/runner/Authenticator.java +++ b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/runner/Authenticator.java @@ -33,10 +33,10 @@ public String doAuthentication(String apiKey, String additionalParams) { try { CxWrapper wrapper = new CxWrapper(config, log); String cxValidateOutput = wrapper.authValidate(); - log.info(AUTH_STATUS + cxValidateOutput); + CxLogger.info(String.format(PluginConstants.INFO_AUTHENTICATION_STATUS, cxValidateOutput)); return cxValidateOutput; } catch (IOException | InterruptedException | CxException e) { - log.error(String.format(PluginConstants.ERROR_AUTHENTICATING_AST, e.getMessage()), e); + CxLogger.error(String.format(PluginConstants.ERROR_AUTHENTICATING_AST, e.getMessage()), e); return e.getMessage(); } } diff --git a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/CheckmarxView.java b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/CheckmarxView.java index 43c16a47..ec897c11 100644 --- a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/CheckmarxView.java +++ b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/CheckmarxView.java @@ -160,6 +160,7 @@ public class CheckmarxView extends ViewPart implements EventHandler { private Text commentText; private DisplayModel rootModel; private String selectedSeverity, selectedState; + private DisplayModel currentlyDisplayedItem; private Button triageButton; private SelectionAdapter triageButtonAdapter, codeBashingAdapter; private Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); @@ -626,6 +627,13 @@ private void createResultViewPanel(Composite resultsComposite) { combo_1.setLayoutData(gd_combo_1); triageStateComboViewer = new ComboViewer(triageView, SWT.READ_ONLY); + triageStateComboViewer.setLabelProvider(new LabelProvider() { + @Override + public String getText(Object element) { + String s = element instanceof String ? (String) element : super.getText(element); + return s.length() > 50 ? s.substring(0, 47) + "..." : s; + } + }); Combo combo_2 = triageStateComboViewer.getCombo(); combo_2.setEnabled(true); combo_2.setData(PluginConstants.DATA_ID_KEY, PluginConstants.TRIAGE_STATE_COMBO_ID); @@ -1082,8 +1090,7 @@ private void createScanIdComboBox(Composite parent) { scanIdComboViewer.setContentProvider(ArrayContentProvider.getInstance()); scanIdComboViewer.setInput(new ArrayList<>()); - GridData gridData = new GridData(); - gridData.widthHint = 520; + GridData gridData = new GridData(SWT.FILL, SWT.CENTER, true, false); scanIdComboViewer.getCombo().setLayoutData(gridData); scanIdComboViewer.getCombo().addListener(SWT.DefaultSelection, new Listener() { @@ -1386,6 +1393,7 @@ protected IStatus run(IProgressMonitor arg0) { if (selectedItem.getResult() != null && selectedItem.getResult().getSimilarityId() != null) { sync.asyncExec(() -> { + currentlyDisplayedItem = selectedItem; createTriageSeverityAndStateCombos(selectedItem); populateTriageChanges(selectedItem); resultViewComposite.setVisible(true); @@ -2473,6 +2481,8 @@ private Image findSeverityImage(DisplayModel model) { private void listener(PluginListenerDefinition definition) { switch (definition.getListenerType()) { case FILTER_CHANGED: + updateResultsTree(definition.getResutls(), true); + break; case GET_RESULTS: updateResultsTree(definition.getResutls(), false); break; @@ -2489,9 +2499,15 @@ private void listener(PluginListenerDefinition definition) { private void updateResultsTree(List results, boolean expand) { sync.asyncExec(() -> { + if (currentlyDisplayedItem == null + || currentlyDisplayedItem.getSeverity() == null + || !FilterState.isSeverityEnabled(currentlyDisplayedItem.getSeverity())) { + resultViewComposite.setVisible(false); + attackVectorCompositePanel.setVisible(false); + } + Object[] expanded = resultsTree.getExpandedElements(); rootModel.children.clear(); rootModel.children.addAll(results); - Object[] expanded = resultsTree.getExpandedElements(); resultsTree.refresh(); if (expand) { Set expandedDMNames = new HashSet<>(); diff --git a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/actions/ActionFilterStatePreference.java b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/actions/ActionFilterStatePreference.java index f67d6899..ecc6bbcb 100644 --- a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/actions/ActionFilterStatePreference.java +++ b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/actions/ActionFilterStatePreference.java @@ -89,7 +89,7 @@ public Menu getMenu(final Control parent) { for (String customState : customStates) { MenuItem item = new MenuItem(menu, SWT.CHECK); - item.setText(customState); + item.setText(truncate(customState)); item.setSelection(FilterState.isCustomStateSelected(customState)); item.addSelectionListener(new SelectionAdapter() { @Override @@ -127,4 +127,8 @@ public void widgetSelected(SelectionEvent e) { public Menu getMenu(final Menu parent) { return null; } + + private static String truncate(String text) { + return text.length() > 50 ? text.substring(0, 47) + "..." : text; + } } \ No newline at end of file diff --git a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/actions/ActionStartScan.java b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/actions/ActionStartScan.java index 43a5cb9c..972a5d68 100644 --- a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/actions/ActionStartScan.java +++ b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/actions/ActionStartScan.java @@ -220,7 +220,7 @@ private String getCurrentGitBranch() { */ private boolean cxProjectMatchesWorkspaceProject() { Results results = DataProvider.getInstance().getCurrentResults(); - boolean noResultsInScan = results == null || results.getResults().isEmpty(); + boolean noResultsInScan = results == null || results.getResults() == null || results.getResults().isEmpty(); boolean noFilesInWorkspace = ResourcesPlugin.getWorkspace().getRoot().getProjects().length == 0; if (noResultsInScan || noFilesInWorkspace) {