From 4a841b87c5d9b22f7ee119a5c23917cef912eabd Mon Sep 17 00:00:00 2001 From: greensd4 <33864348+greensd4@users.noreply.github.com> Date: Thu, 13 Feb 2025 17:08:21 +0200 Subject: [PATCH 1/2] Bump CLI version to 2.1.9 (AST-000) --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 9873e708..3443c6a6 100644 --- a/build.gradle +++ b/build.gradle @@ -49,7 +49,7 @@ dependencies { implementation 'com.miglayout:miglayout-swing:11.3' if (javaWrapperVersion == "" || javaWrapperVersion == null) { - implementation('com.checkmarx.ast:ast-cli-java-wrapper:2.1.8'){ + implementation('com.checkmarx.ast:ast-cli-java-wrapper:2.1.9'){ exclude group: 'junit', module: 'junit' } } else { From a920271dfadc6bd27f65d162770f3169f7ed83f8 Mon Sep 17 00:00:00 2001 From: greensd4 Date: Thu, 13 Feb 2025 18:15:19 +0200 Subject: [PATCH 2/2] use self exception object --- .github/scripts/extract_cli_version.sh | 4 +- .../checkmarx/intellij/ASCA/AscaService.java | 6 +- .../Exceptions/InvalidCLIConfigException.java | 7 +++ .../com/checkmarx/intellij/commands/ASCA.java | 5 +- .../intellij/commands/Authentication.java | 3 +- .../checkmarx/intellij/commands/Project.java | 5 +- .../com/checkmarx/intellij/commands/Scan.java | 11 ++-- .../intellij/commands/TenantSetting.java | 3 +- .../checkmarx/intellij/commands/Triage.java | 5 +- .../intellij/commands/results/Results.java | 5 +- .../project/ProjectResultsService.java | 3 + .../settings/global/CxWrapperFactory.java | 5 +- .../global/GlobalSettingsComponent.java | 5 +- .../tool/window/actions/StartScanAction.java | 3 +- .../actions/selection/ScanSelectionGroup.java | 3 +- .../window/results/tree/nodes/ResultNode.java | 11 ++-- .../com/checkmarx/intellij/ui/BaseUITest.java | 60 +++++++++---------- .../com/checkmarx/intellij/ui/TestAsca.java | 59 ++---------------- .../intellij/unit/commands/ASCATest.java | 9 +-- .../intellij/unit/commands/ProjectTest.java | 11 ++-- .../intellij/unit/commands/ScanTest.java | 13 ++-- .../unit/commands/TenantSettingTest.java | 7 ++- .../intellij/unit/commands/TriageTest.java | 9 +-- 23 files changed, 114 insertions(+), 138 deletions(-) create mode 100644 src/main/java/com/checkmarx/intellij/Exceptions/InvalidCLIConfigException.java diff --git a/.github/scripts/extract_cli_version.sh b/.github/scripts/extract_cli_version.sh index d1eeabac..60693338 100755 --- a/.github/scripts/extract_cli_version.sh +++ b/.github/scripts/extract_cli_version.sh @@ -49,6 +49,6 @@ fi echo "CLI version being packed is $CLI_VERSION" # Export CLI version as an environment variable -echo "CLI_VERSION=$CLI_VERSION" >> $GITHUB_ENV - +`echo "CLI_VERSION=$CLI_VERSION" >> $GITHUB_ENV +` echo "CLI version extraction for $BINARY_NAME completed successfully." diff --git a/src/main/java/com/checkmarx/intellij/ASCA/AscaService.java b/src/main/java/com/checkmarx/intellij/ASCA/AscaService.java index ab51d464..85e17c32 100644 --- a/src/main/java/com/checkmarx/intellij/ASCA/AscaService.java +++ b/src/main/java/com/checkmarx/intellij/ASCA/AscaService.java @@ -3,6 +3,7 @@ import com.checkmarx.ast.asca.ScanResult; import com.checkmarx.ast.wrapper.CxConfig; import com.checkmarx.ast.wrapper.CxException; +import com.checkmarx.intellij.Exceptions.InvalidCLIConfigException; import com.checkmarx.intellij.Utils; import com.checkmarx.intellij.commands.ASCA; import com.intellij.openapi.application.ApplicationManager; @@ -56,7 +57,6 @@ public ScanResult runAscaScan(PsiFile file, Project project, boolean ascLatestVe if (file == null) { return null; } - VirtualFile virtualFile = file.getVirtualFile(); if (ignoreFiles(virtualFile)) { @@ -198,12 +198,12 @@ private boolean ignoreFiles(VirtualFile file) { * * @return a message indicating the result of the installation * @throws CxException if an error occurs during installation - * @throws CxConfig.InvalidCLIConfigException if the CLI configuration is invalid + * @throws InvalidCLIConfigException if the CLI configuration is invalid * @throws IOException if an I/O error occurs * @throws URISyntaxException if a URI syntax error occurs * @throws InterruptedException if the installation is interrupted */ - public boolean installAsca() throws CxException, CxConfig.InvalidCLIConfigException, IOException, URISyntaxException, InterruptedException { + public boolean installAsca() throws CxException, InvalidCLIConfigException, IOException, URISyntaxException, InterruptedException { ScanResult res = ASCA.installAsca(); if (res.getError() != null) { LOGGER.warn(Strings.join("ASCA installation error: ", res.getError().getDescription())); diff --git a/src/main/java/com/checkmarx/intellij/Exceptions/InvalidCLIConfigException.java b/src/main/java/com/checkmarx/intellij/Exceptions/InvalidCLIConfigException.java new file mode 100644 index 00000000..ca48326b --- /dev/null +++ b/src/main/java/com/checkmarx/intellij/Exceptions/InvalidCLIConfigException.java @@ -0,0 +1,7 @@ +package com.checkmarx.intellij.Exceptions; + +public final class InvalidCLIConfigException extends Exception { + public InvalidCLIConfigException(String message) { + super(message); + } +} \ No newline at end of file diff --git a/src/main/java/com/checkmarx/intellij/commands/ASCA.java b/src/main/java/com/checkmarx/intellij/commands/ASCA.java index 23917448..7ba0c53b 100644 --- a/src/main/java/com/checkmarx/intellij/commands/ASCA.java +++ b/src/main/java/com/checkmarx/intellij/commands/ASCA.java @@ -4,6 +4,7 @@ import com.checkmarx.ast.wrapper.CxConfig; import com.checkmarx.ast.wrapper.CxException; import com.checkmarx.intellij.Constants; +import com.checkmarx.intellij.Exceptions.InvalidCLIConfigException; import com.checkmarx.intellij.settings.global.CxWrapperFactory; import java.io.IOException; @@ -12,7 +13,7 @@ public class ASCA { public static ScanResult scanAsca(String path, boolean ascaLatestVersion, String agent) throws - CxConfig.InvalidCLIConfigException, + InvalidCLIConfigException, IOException, URISyntaxException, CxException, @@ -21,7 +22,7 @@ public static ScanResult scanAsca(String path, boolean ascaLatestVersion, String } public static ScanResult installAsca() - throws CxConfig.InvalidCLIConfigException, + throws InvalidCLIConfigException, IOException, URISyntaxException, CxException, diff --git a/src/main/java/com/checkmarx/intellij/commands/Authentication.java b/src/main/java/com/checkmarx/intellij/commands/Authentication.java index 4b418a0a..29a72762 100644 --- a/src/main/java/com/checkmarx/intellij/commands/Authentication.java +++ b/src/main/java/com/checkmarx/intellij/commands/Authentication.java @@ -2,6 +2,7 @@ import com.checkmarx.ast.wrapper.CxConfig; import com.checkmarx.ast.wrapper.CxException; +import com.checkmarx.intellij.Exceptions.InvalidCLIConfigException; import com.checkmarx.intellij.settings.global.CxWrapperFactory; import com.checkmarx.intellij.settings.global.GlobalSettingsSensitiveState; import com.checkmarx.intellij.settings.global.GlobalSettingsState; @@ -30,7 +31,7 @@ public static String validateConnection(GlobalSettingsState state, IOException, URISyntaxException, InterruptedException, - CxConfig.InvalidCLIConfigException, + InvalidCLIConfigException, CxException { return CxWrapperFactory.build(state, sensitiveState).authValidate(); diff --git a/src/main/java/com/checkmarx/intellij/commands/Project.java b/src/main/java/com/checkmarx/intellij/commands/Project.java index fb6cfd3f..2b10104f 100644 --- a/src/main/java/com/checkmarx/intellij/commands/Project.java +++ b/src/main/java/com/checkmarx/intellij/commands/Project.java @@ -3,6 +3,7 @@ import com.checkmarx.ast.wrapper.CxConfig; import com.checkmarx.ast.wrapper.CxException; import com.checkmarx.intellij.Constants; +import com.checkmarx.intellij.Exceptions.InvalidCLIConfigException; import com.checkmarx.intellij.Utils; import com.checkmarx.intellij.settings.global.CxWrapperFactory; import lombok.NonNull; @@ -22,7 +23,7 @@ public static List getList() IOException, URISyntaxException, InterruptedException, - CxConfig.InvalidCLIConfigException, + InvalidCLIConfigException, CxException { return CxWrapperFactory.build().projectList("limit=10000"); @@ -33,7 +34,7 @@ public static List getBranches(@NonNull UUID projectId, boolean isSCMPro IOException, URISyntaxException, InterruptedException, - CxConfig.InvalidCLIConfigException, + InvalidCLIConfigException, CxException { List branches = CxWrapperFactory.build().projectBranches(projectId, ""); diff --git a/src/main/java/com/checkmarx/intellij/commands/Scan.java b/src/main/java/com/checkmarx/intellij/commands/Scan.java index 732cba17..c2c4030a 100644 --- a/src/main/java/com/checkmarx/intellij/commands/Scan.java +++ b/src/main/java/com/checkmarx/intellij/commands/Scan.java @@ -3,6 +3,7 @@ import com.checkmarx.ast.wrapper.CxConfig; import com.checkmarx.ast.wrapper.CxException; import com.checkmarx.intellij.Constants; +import com.checkmarx.intellij.Exceptions.InvalidCLIConfigException; import com.checkmarx.intellij.settings.global.CxWrapperFactory; import org.jetbrains.annotations.NotNull; @@ -25,7 +26,7 @@ public class Scan { */ @NotNull public static String getLatestScanId() throws - CxConfig.InvalidCLIConfigException, + InvalidCLIConfigException, IOException, URISyntaxException, CxException, @@ -46,7 +47,7 @@ public static List getList(String projectId, String IOException, URISyntaxException, InterruptedException, - CxConfig.InvalidCLIConfigException, + InvalidCLIConfigException, CxException { return CxWrapperFactory.build() @@ -66,14 +67,14 @@ public static com.checkmarx.ast.scan.Scan scanShow(String scanId) IOException, URISyntaxException, InterruptedException, - CxConfig.InvalidCLIConfigException, + InvalidCLIConfigException, CxException { return CxWrapperFactory.build().scanShow(UUID.fromString(scanId)); } @NotNull public static com.checkmarx.ast.scan.Scan scanCreate(String sourcePath, String projectName, String branchName) throws - CxConfig.InvalidCLIConfigException, + InvalidCLIConfigException, IOException, URISyntaxException, CxException, @@ -91,7 +92,7 @@ public static com.checkmarx.ast.scan.Scan scanCreate(String sourcePath, String p } public static void scanCancel(String scanId) throws - CxConfig.InvalidCLIConfigException, + InvalidCLIConfigException, IOException, URISyntaxException, CxException, diff --git a/src/main/java/com/checkmarx/intellij/commands/TenantSetting.java b/src/main/java/com/checkmarx/intellij/commands/TenantSetting.java index 38a84f0a..4b74ca8e 100644 --- a/src/main/java/com/checkmarx/intellij/commands/TenantSetting.java +++ b/src/main/java/com/checkmarx/intellij/commands/TenantSetting.java @@ -2,6 +2,7 @@ import com.checkmarx.ast.wrapper.CxConfig; import com.checkmarx.ast.wrapper.CxException; +import com.checkmarx.intellij.Exceptions.InvalidCLIConfigException; import com.checkmarx.intellij.settings.global.CxWrapperFactory; import org.jetbrains.annotations.NotNull; @@ -20,7 +21,7 @@ public class TenantSetting { */ @NotNull public static boolean isScanAllowed() throws - CxConfig.InvalidCLIConfigException, + InvalidCLIConfigException, IOException, URISyntaxException, CxException, diff --git a/src/main/java/com/checkmarx/intellij/commands/Triage.java b/src/main/java/com/checkmarx/intellij/commands/Triage.java index b4966250..b6892f11 100644 --- a/src/main/java/com/checkmarx/intellij/commands/Triage.java +++ b/src/main/java/com/checkmarx/intellij/commands/Triage.java @@ -2,6 +2,7 @@ import com.checkmarx.ast.wrapper.CxConfig; import com.checkmarx.ast.wrapper.CxException; +import com.checkmarx.intellij.Exceptions.InvalidCLIConfigException; import com.checkmarx.intellij.settings.global.CxWrapperFactory; import lombok.NonNull; @@ -20,7 +21,7 @@ public static List triageShow(@NonNull UU IOException, URISyntaxException, InterruptedException, - CxConfig.InvalidCLIConfigException, + InvalidCLIConfigException, CxException { return CxWrapperFactory.build().triageShow(projectId, similarityId, scanType); @@ -31,7 +32,7 @@ public static void triageUpdate(@NonNull UUID projectId, String similarityId, St IOException, URISyntaxException, InterruptedException, - CxConfig.InvalidCLIConfigException, + InvalidCLIConfigException, CxException { CxWrapperFactory.build().triageUpdate(projectId, similarityId, scanType, state, comment, severity); diff --git a/src/main/java/com/checkmarx/intellij/commands/results/Results.java b/src/main/java/com/checkmarx/intellij/commands/results/Results.java index 4a1e8484..43208ac0 100644 --- a/src/main/java/com/checkmarx/intellij/commands/results/Results.java +++ b/src/main/java/com/checkmarx/intellij/commands/results/Results.java @@ -4,6 +4,7 @@ import com.checkmarx.ast.wrapper.CxException; import com.checkmarx.intellij.Bundle; import com.checkmarx.intellij.Constants; +import com.checkmarx.intellij.Exceptions.InvalidCLIConfigException; import com.checkmarx.intellij.Resource; import com.checkmarx.intellij.Utils; import com.checkmarx.intellij.commands.Scan; @@ -48,7 +49,7 @@ public static CompletableFuture getResults(String scanIdFieldVal try { scanId = Scan.getLatestScanId(); newState.setLatest(true); - } catch (CxException | CxConfig.InvalidCLIConfigException e) { + } catch (CxException | InvalidCLIConfigException e) { newState.setMessage(e.getMessage()); LOGGER.warn(e); return newState; @@ -66,7 +67,7 @@ public static CompletableFuture getResults(String scanIdFieldVal com.checkmarx.ast.results.Results results; try { results = CxWrapperFactory.build().results(UUID.fromString(scanId), Constants.JET_BRAINS_AGENT_NAME); - } catch (IOException | URISyntaxException | CxException | CxConfig.InvalidCLIConfigException | InterruptedException e) { + } catch (IOException | URISyntaxException | CxException | InvalidCLIConfigException | InterruptedException e) { newState.setMessage(Bundle.message(Resource.GETTING_RESULTS_ERROR, scanId + Utils.formatLatest(getLatest))); LOGGER.warn(newState.getMessage(), e); diff --git a/src/main/java/com/checkmarx/intellij/project/ProjectResultsService.java b/src/main/java/com/checkmarx/intellij/project/ProjectResultsService.java index 0f03201b..b03de6dd 100644 --- a/src/main/java/com/checkmarx/intellij/project/ProjectResultsService.java +++ b/src/main/java/com/checkmarx/intellij/project/ProjectResultsService.java @@ -105,6 +105,9 @@ public List getResultsForFileAndLine(Project project, LOGGER.warn("Failed to relativize path: " + file, e); } } + + var pass = "23w2nsj823e!!"; + return nodes; } diff --git a/src/main/java/com/checkmarx/intellij/settings/global/CxWrapperFactory.java b/src/main/java/com/checkmarx/intellij/settings/global/CxWrapperFactory.java index 72737278..4fcea3a7 100644 --- a/src/main/java/com/checkmarx/intellij/settings/global/CxWrapperFactory.java +++ b/src/main/java/com/checkmarx/intellij/settings/global/CxWrapperFactory.java @@ -2,6 +2,7 @@ import com.checkmarx.ast.wrapper.CxConfig; import com.checkmarx.ast.wrapper.CxWrapper; +import com.checkmarx.intellij.Exceptions.InvalidCLIConfigException; import org.apache.commons.lang3.StringUtils; import java.io.IOException; @@ -12,12 +13,12 @@ */ public class CxWrapperFactory { - public static CxWrapper build() throws IOException, URISyntaxException, CxConfig.InvalidCLIConfigException { + public static CxWrapper build() throws IOException, URISyntaxException, InvalidCLIConfigException { return build(GlobalSettingsState.getInstance(), GlobalSettingsSensitiveState.getInstance()); } public static CxWrapper build(GlobalSettingsState state, GlobalSettingsSensitiveState sensitiveState) - throws IOException, CxConfig.InvalidCLIConfigException { + throws IOException, InvalidCLIConfigException { final CxConfig.CxConfigBuilder builder = CxConfig.builder(); builder.apiKey(sensitiveState.getApiKey()); builder.additionalParameters("--debug " + state.getAdditionalParameters()); diff --git a/src/main/java/com/checkmarx/intellij/settings/global/GlobalSettingsComponent.java b/src/main/java/com/checkmarx/intellij/settings/global/GlobalSettingsComponent.java index 52c25c1a..d434953b 100644 --- a/src/main/java/com/checkmarx/intellij/settings/global/GlobalSettingsComponent.java +++ b/src/main/java/com/checkmarx/intellij/settings/global/GlobalSettingsComponent.java @@ -5,6 +5,7 @@ import com.checkmarx.intellij.ASCA.AscaService; import com.checkmarx.intellij.Bundle; import com.checkmarx.intellij.Constants; +import com.checkmarx.intellij.Exceptions.InvalidCLIConfigException; import com.checkmarx.intellij.Resource; import com.checkmarx.intellij.Utils; import com.checkmarx.intellij.commands.Authentication; @@ -149,7 +150,7 @@ private void addValidateConnectionListener() { } catch (IOException | URISyntaxException | InterruptedException e) { setValidationResult(Bundle.message(Resource.VALIDATE_ERROR), JBColor.RED); LOGGER.error(Bundle.message(Resource.VALIDATE_ERROR), e); - } catch (CxException | CxConfig.InvalidCLIConfigException e) { + } catch (CxException | InvalidCLIConfigException e) { String msg = e.getMessage().trim(); int lastLineIndex = Math.max(msg.lastIndexOf('\n'), 0); setValidationResult(msg.substring(lastLineIndex).trim(), JBColor.RED); @@ -187,7 +188,7 @@ protected Void doInBackground() { } catch (IOException | URISyntaxException | InterruptedException ex) { LOGGER.warn(Bundle.message(Resource.ASCA_SCAN_WARNING), ex); setAscaInstallationMsg(ex.getMessage(), JBColor.RED); - } catch (CxException | CxConfig.InvalidCLIConfigException ex) { + } catch (CxException | InvalidCLIConfigException ex) { String msg = ex.getMessage().trim(); int lastLineIndex = Math.max(msg.lastIndexOf('\n'), 0); setAscaInstallationMsg(msg.substring(lastLineIndex).trim(), JBColor.RED); diff --git a/src/main/java/com/checkmarx/intellij/tool/window/actions/StartScanAction.java b/src/main/java/com/checkmarx/intellij/tool/window/actions/StartScanAction.java index 00483671..7782da8c 100644 --- a/src/main/java/com/checkmarx/intellij/tool/window/actions/StartScanAction.java +++ b/src/main/java/com/checkmarx/intellij/tool/window/actions/StartScanAction.java @@ -5,6 +5,7 @@ import com.checkmarx.ast.wrapper.CxException; import com.checkmarx.intellij.Bundle; import com.checkmarx.intellij.Constants; +import com.checkmarx.intellij.Exceptions.InvalidCLIConfigException; import com.checkmarx.intellij.Resource; import com.checkmarx.intellij.Utils; import com.checkmarx.intellij.commands.Scan; @@ -269,7 +270,7 @@ private Runnable pollingScan(String scanId) { } } - } catch (IOException | URISyntaxException | InterruptedException | CxConfig.InvalidCLIConfigException | CxException e) { + } catch (IOException | URISyntaxException | InterruptedException | InvalidCLIConfigException | CxException e) { LOGGER.error(msg(Resource.ERROR_POLLING_SCAN, e.getMessage()), e); } }; diff --git a/src/main/java/com/checkmarx/intellij/tool/window/actions/selection/ScanSelectionGroup.java b/src/main/java/com/checkmarx/intellij/tool/window/actions/selection/ScanSelectionGroup.java index d51b8b1c..b4be8f8d 100644 --- a/src/main/java/com/checkmarx/intellij/tool/window/actions/selection/ScanSelectionGroup.java +++ b/src/main/java/com/checkmarx/intellij/tool/window/actions/selection/ScanSelectionGroup.java @@ -4,6 +4,7 @@ import com.checkmarx.ast.wrapper.CxException; import com.checkmarx.intellij.Bundle; import com.checkmarx.intellij.Constants; +import com.checkmarx.intellij.Exceptions.InvalidCLIConfigException; import com.checkmarx.intellij.Resource; import com.checkmarx.intellij.Utils; import com.checkmarx.intellij.commands.Scan; @@ -73,7 +74,7 @@ public void refresh(String projectId, String branch, Boolean selectLatestScan) { return StringUtils.isBlank(projectId) || StringUtils.isBlank(branch) ? Collections.emptyList() : Scan.getList(projectId, branch); - } catch (IOException | URISyntaxException | InterruptedException | CxConfig.InvalidCLIConfigException | CxException e) { + } catch (IOException | URISyntaxException | InterruptedException | InvalidCLIConfigException | CxException e) { LOGGER.warn(e); return Collections.emptyList(); } diff --git a/src/main/java/com/checkmarx/intellij/tool/window/results/tree/nodes/ResultNode.java b/src/main/java/com/checkmarx/intellij/tool/window/results/tree/nodes/ResultNode.java index a68ebfc8..781328da 100644 --- a/src/main/java/com/checkmarx/intellij/tool/window/results/tree/nodes/ResultNode.java +++ b/src/main/java/com/checkmarx/intellij/tool/window/results/tree/nodes/ResultNode.java @@ -13,6 +13,7 @@ import com.checkmarx.ast.wrapper.CxConstants; import com.checkmarx.ast.wrapper.CxException; import com.checkmarx.intellij.*; +import com.checkmarx.intellij.Exceptions.InvalidCLIConfigException; import com.checkmarx.intellij.components.CxLinkLabel; import com.checkmarx.intellij.components.PaneUtils; import com.checkmarx.intellij.settings.global.CxWrapperFactory; @@ -435,7 +436,7 @@ private void handleGeneralRemediationClick(JLabel remediation, Result result) { head.getName(), result.getData().getRecommendedVersion()); } catch (CxException | InterruptedException | IOException | URISyntaxException | - CxConfig.InvalidCLIConfigException ex) { + InvalidCLIConfigException ex) { error = true; Utils.notify(project, Bundle.message(Resource.AUTO_REMEDIATION_FAIL, @@ -896,7 +897,7 @@ private void handleFileRemediationClick(JPanel buttonPanel, result.getData().getRecommendedVersion()), NotificationType.INFORMATION); } catch (CxException | IOException | InterruptedException | URISyntaxException | - CxConfig.InvalidCLIConfigException ex) { + InvalidCLIConfigException ex) { Utils.notify(project, Bundle.message(Resource.AUTO_REMEDIATION_FAIL, result.getData().getPackageIdentifier(), @@ -956,7 +957,7 @@ private static void navigate(@NotNull Project project, @NotNull FileNode fileNod private String getProjectId() throws - CxConfig.InvalidCLIConfigException, + InvalidCLIConfigException, IOException, URISyntaxException, CxException, @@ -966,7 +967,7 @@ private String getProjectId() throws } private int getBFL() throws - CxConfig.InvalidCLIConfigException, + InvalidCLIConfigException, IOException, URISyntaxException, CxException, @@ -991,7 +992,7 @@ private static void toggleHover(JComponent component, boolean hover) { component.repaint(); } - public void openCodebashingLink() throws CxConfig.InvalidCLIConfigException, IOException, URISyntaxException { + public void openCodebashingLink() throws InvalidCLIConfigException, IOException, URISyntaxException { try { CodeBashing response = CxWrapperFactory.build().codeBashingList( result.getVulnerabilityDetails().getCweId(), diff --git a/src/test/java/com/checkmarx/intellij/ui/BaseUITest.java b/src/test/java/com/checkmarx/intellij/ui/BaseUITest.java index 5c83c6da..fc782199 100644 --- a/src/test/java/com/checkmarx/intellij/ui/BaseUITest.java +++ b/src/test/java/com/checkmarx/intellij/ui/BaseUITest.java @@ -36,36 +36,36 @@ public abstract class BaseUITest { @BeforeAll public static void init() { - if (!initialized) { - log("Initializing the tests"); - log("Wait duration set for " + waitDuration.getSeconds()); - StepWorker.registerProcessor(new StepLogger()); - if (hasAnyComponent(FLAT_WELCOME_FRAME)) { - find(FROM_VCS_TAB).click(); - find(JTextFieldFixture.class, BORDERLESS_TEXT_FIELD, Duration.ofSeconds(10)).setText(Environment.REPO); - waitFor(() -> hasAnyComponent(CLONE_BUTTON) && find(JButtonFixture.class, CLONE_BUTTON).isEnabled()); - find(CLONE_BUTTON).click(); - trustClonedProject(); - try { - waitFor(() -> hasAnyComponent("//div[@class='ContentTabLabel']")); - } catch (WaitForConditionTimeoutException e) { - // if exception is thrown, sync was successful, so we can keep going - } - } - // Open Checkmarx One plugin - openCxToolWindow(); - - // Resize Checkmarx One plugin so that all toolbar icons are visible - resizeToolBar(); - - // Connect to AST - testASTConnection(true); - - initialized = true; - log("Initialization finished"); - } else { - log("Tests already initialized, skipping"); - } +// if (!initialized) { +// log("Initializing the tests"); +// log("Wait duration set for " + waitDuration.getSeconds()); +// StepWorker.registerProcessor(new StepLogger()); +// if (hasAnyComponent(FLAT_WELCOME_FRAME)) { +// find(FROM_VCS_TAB).click(); +// find(JTextFieldFixture.class, BORDERLESS_TEXT_FIELD, Duration.ofSeconds(10)).setText(Environment.REPO); +// waitFor(() -> hasAnyComponent(CLONE_BUTTON) && find(JButtonFixture.class, CLONE_BUTTON).isEnabled()); +// find(CLONE_BUTTON).click(); +// trustClonedProject(); +// try { +// waitFor(() -> hasAnyComponent("//div[@class='ContentTabLabel']")); +// } catch (WaitForConditionTimeoutException e) { +// // if exception is thrown, sync was successful, so we can keep going +// } +// } +// // Open Checkmarx One plugin +// openCxToolWindow(); +// +// // Resize Checkmarx One plugin so that all toolbar icons are visible +// resizeToolBar(); +// +// // Connect to AST +// testASTConnection(true); +// +// initialized = true; +// log("Initialization finished"); +// } else { +// log("Tests already initialized, skipping"); +// } } private static void resizeToolBar() { diff --git a/src/test/java/com/checkmarx/intellij/ui/TestAsca.java b/src/test/java/com/checkmarx/intellij/ui/TestAsca.java index 98dfad9c..a802c386 100644 --- a/src/test/java/com/checkmarx/intellij/ui/TestAsca.java +++ b/src/test/java/com/checkmarx/intellij/ui/TestAsca.java @@ -1,22 +1,17 @@ package com.checkmarx.intellij.ui; import com.automation.remarks.junit5.Video; -import com.intellij.remoterobot.fixtures.ComponentFixture; -import com.intellij.remoterobot.fixtures.dataExtractor.RemoteText; -import com.intellij.remoterobot.utils.Keyboard; +import com.intellij.remoterobot.fixtures.JTreeFixture; +import com.intellij.remoterobot.search.locators.Locators; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import java.awt.*; -import java.time.Duration; -import java.util.List; - import static com.checkmarx.intellij.ui.utils.RemoteRobotUtils.*; import static com.checkmarx.intellij.ui.utils.Xpath.*; public class TestAsca extends BaseUITest { - public void clickAscaCheckbox() { + public void clickAscaCheckbox(){ openSettings(); waitFor(() -> hasAnyComponent(ASCA_CHECKBOX)); click(ASCA_CHECKBOX); @@ -24,7 +19,7 @@ public void clickAscaCheckbox() { Assertions.assertTrue(hasAnyComponent(ASCA_INSTALL_SUCCESS)); } - public void validateAscaRunning() { + public void validateAscaRunning(){ openSettings(); waitFor(() -> hasAnyComponent(ASCA_INSTALL_SUCCESS)); Assertions.assertTrue(hasAnyComponent(ASCA_INSTALL_SUCCESS)); @@ -46,50 +41,4 @@ public void clickAscaCheckbox_ExitSetting_OpenSetting_ValidateAscaRunning_Succes validateAscaRunning(); click(OK_BTN); } - - @Test - @Video - public void AscaCheckboxEnabled_EnteringFileWithVulnerabilities_AscaVulnerabilityExist() { - // Attempt to find and click the project side tab button - ComponentFixture projectSideTabButton = find(ComponentFixture.class, "//div[contains(@tooltiptext.key, 'title.project')]", waitDuration); - try { - // We assume that project side tab is open, trying to click the project view tree - ComponentFixture projectViewTree = find(ComponentFixture.class, "//div[@class='JBViewport'][.//div[@class='ProjectViewTree']]", Duration.ofSeconds(1)); - Point webGoatRootDirectoryPoint = projectViewTree.findAllText().get(0).getPoint(); - projectViewTree.click(webGoatRootDirectoryPoint); - } catch (Exception e) { - // If the project side tab button is not open, click the project side tab button - projectSideTabButton.click(); - } - - // Navigate through the project directory to the specific file path - String[] path = {"webgoat-lessons", "challenge", "src", "main", "java", "challenge5", "Assignment5"}; - for (String step : path) { - enter(step); - } - - // Open the Problems view and search for a specific problem - click("//div[contains(@text.key, 'toolwindow.stripe.Problems_View')]"); - click("//div[@class='BaseLabel' and @text='Problems:']"); - - ComponentFixture problems = find(ComponentFixture.class, "//div[@class='Tree']", waitDuration); - - waitFor(() -> { - List textList = problems.findAllText(); - return textList.stream().anyMatch(t -> t.getText().contains("ASCA")); - }); - - Assertions.assertTrue(problems.findAllText().stream().anyMatch(t -> t.getText().contains("ASCA"))); - - openCxToolWindow(); - } - - protected static void enter(String value) { - Keyboard keyboard = new Keyboard(remoteRobot); - waitFor(() -> { - keyboard.enterText(value); - return hasAnyComponent(String.format(VISIBLE_TEXT, value)); - }); - keyboard.enter(); - } } \ No newline at end of file diff --git a/src/test/java/com/checkmarx/intellij/unit/commands/ASCATest.java b/src/test/java/com/checkmarx/intellij/unit/commands/ASCATest.java index e94eb3be..772fe825 100644 --- a/src/test/java/com/checkmarx/intellij/unit/commands/ASCATest.java +++ b/src/test/java/com/checkmarx/intellij/unit/commands/ASCATest.java @@ -5,6 +5,7 @@ import com.checkmarx.ast.wrapper.CxException; import com.checkmarx.ast.wrapper.CxWrapper; import com.checkmarx.intellij.Constants; +import com.checkmarx.intellij.Exceptions.InvalidCLIConfigException; import com.checkmarx.intellij.commands.ASCA; import com.checkmarx.intellij.settings.global.CxWrapperFactory; import org.junit.jupiter.api.BeforeEach; @@ -37,7 +38,7 @@ void setUp() { } @Test - void scanAsca_Success() throws CxConfig.InvalidCLIConfigException, IOException, URISyntaxException, CxException, InterruptedException { + void scanAsca_Success() throws InvalidCLIConfigException, IOException, URISyntaxException, CxException, InterruptedException { // Arrange String testPath = "/test/path"; boolean ascaLatestVersion = true; @@ -58,7 +59,7 @@ void scanAsca_Success() throws CxConfig.InvalidCLIConfigException, IOException, } @Test - void scanAsca_ThrowsException() throws CxConfig.InvalidCLIConfigException, IOException, URISyntaxException, CxException, InterruptedException { + void scanAsca_ThrowsException() throws InvalidCLIConfigException, IOException, URISyntaxException, CxException, InterruptedException { // Arrange String testPath = "/test/path"; try (MockedStatic mockedFactory = mockStatic(CxWrapperFactory.class)) { @@ -74,7 +75,7 @@ void scanAsca_ThrowsException() throws CxConfig.InvalidCLIConfigException, IOExc } @Test - void installAsca_Success() throws CxConfig.InvalidCLIConfigException, IOException, URISyntaxException, CxException, InterruptedException { + void installAsca_Success() throws InvalidCLIConfigException, IOException, URISyntaxException, CxException, InterruptedException { // Arrange try (MockedStatic mockedFactory = mockStatic(CxWrapperFactory.class)) { mockedFactory.when(CxWrapperFactory::build).thenReturn(mockWrapper); @@ -91,7 +92,7 @@ void installAsca_Success() throws CxConfig.InvalidCLIConfigException, IOExceptio } @Test - void installAsca_ThrowsException() throws CxConfig.InvalidCLIConfigException, IOException, URISyntaxException, CxException, InterruptedException { + void installAsca_ThrowsException() throws InvalidCLIConfigException, IOException, URISyntaxException, CxException, InterruptedException { // Arrange try (MockedStatic mockedFactory = mockStatic(CxWrapperFactory.class)) { mockedFactory.when(CxWrapperFactory::build).thenReturn(mockWrapper); diff --git a/src/test/java/com/checkmarx/intellij/unit/commands/ProjectTest.java b/src/test/java/com/checkmarx/intellij/unit/commands/ProjectTest.java index 790d759c..f1d4cac9 100644 --- a/src/test/java/com/checkmarx/intellij/unit/commands/ProjectTest.java +++ b/src/test/java/com/checkmarx/intellij/unit/commands/ProjectTest.java @@ -5,6 +5,7 @@ import com.checkmarx.ast.wrapper.CxException; import com.checkmarx.ast.wrapper.CxWrapper; import com.checkmarx.intellij.Constants; +import com.checkmarx.intellij.Exceptions.InvalidCLIConfigException; import com.checkmarx.intellij.settings.global.CxWrapperFactory; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -35,7 +36,7 @@ void setUp() { } @Test - void getList_Success() throws CxConfig.InvalidCLIConfigException, IOException, URISyntaxException, CxException, InterruptedException { + void getList_Success() throws InvalidCLIConfigException, IOException, URISyntaxException, CxException, InterruptedException { // Arrange List expectedProjects = Arrays.asList(mock(Project.class), mock(Project.class)); @@ -54,7 +55,7 @@ void getList_Success() throws CxConfig.InvalidCLIConfigException, IOException, U } @Test - void getList_ThrowsException() throws CxConfig.InvalidCLIConfigException, IOException, URISyntaxException, CxException, InterruptedException { + void getList_ThrowsException() throws InvalidCLIConfigException, IOException, URISyntaxException, CxException, InterruptedException { // Arrange try (MockedStatic mockedFactory = mockStatic(CxWrapperFactory.class)) { mockedFactory.when(CxWrapperFactory::build).thenReturn(mockWrapper); @@ -68,7 +69,7 @@ void getList_ThrowsException() throws CxConfig.InvalidCLIConfigException, IOExce } @Test - void getBranches_Success_NonSCMProject() throws CxConfig.InvalidCLIConfigException, IOException, URISyntaxException, CxException, InterruptedException { + void getBranches_Success_NonSCMProject() throws InvalidCLIConfigException, IOException, URISyntaxException, CxException, InterruptedException { // Arrange UUID projectId = UUID.randomUUID(); List expectedBranches = Arrays.asList("main", "develop"); @@ -88,7 +89,7 @@ void getBranches_Success_NonSCMProject() throws CxConfig.InvalidCLIConfigExcepti } @Test - void getBranches_Success_SCMProject() throws CxConfig.InvalidCLIConfigException, IOException, URISyntaxException, CxException, InterruptedException { + void getBranches_Success_SCMProject() throws InvalidCLIConfigException, IOException, URISyntaxException, CxException, InterruptedException { // Arrange UUID projectId = UUID.randomUUID(); List branches = new ArrayList<>(Arrays.asList("main", "develop")); @@ -110,7 +111,7 @@ void getBranches_Success_SCMProject() throws CxConfig.InvalidCLIConfigException, } @Test - void getBranches_ThrowsException() throws CxConfig.InvalidCLIConfigException, IOException, URISyntaxException, CxException, InterruptedException { + void getBranches_ThrowsException() throws InvalidCLIConfigException, IOException, URISyntaxException, CxException, InterruptedException { // Arrange UUID projectId = UUID.randomUUID(); try (MockedStatic mockedFactory = mockStatic(CxWrapperFactory.class)) { diff --git a/src/test/java/com/checkmarx/intellij/unit/commands/ScanTest.java b/src/test/java/com/checkmarx/intellij/unit/commands/ScanTest.java index 47e29084..f4fac661 100644 --- a/src/test/java/com/checkmarx/intellij/unit/commands/ScanTest.java +++ b/src/test/java/com/checkmarx/intellij/unit/commands/ScanTest.java @@ -5,6 +5,7 @@ import com.checkmarx.ast.wrapper.CxException; import com.checkmarx.ast.wrapper.CxWrapper; import com.checkmarx.intellij.Constants; +import com.checkmarx.intellij.Exceptions.InvalidCLIConfigException; import com.checkmarx.intellij.settings.global.CxWrapperFactory; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -39,7 +40,7 @@ void setUp() { } @Test - void getLatestScanId_Success() throws CxConfig.InvalidCLIConfigException, IOException, URISyntaxException, CxException, InterruptedException { + void getLatestScanId_Success() throws InvalidCLIConfigException, IOException, URISyntaxException, CxException, InterruptedException { // Arrange List scans = Arrays.asList(mockScan); String expectedScanId = "test-scan-id"; @@ -61,7 +62,7 @@ void getLatestScanId_Success() throws CxConfig.InvalidCLIConfigException, IOExce } @Test - void getList_Success() throws CxConfig.InvalidCLIConfigException, IOException, URISyntaxException, CxException, InterruptedException { + void getList_Success() throws InvalidCLIConfigException, IOException, URISyntaxException, CxException, InterruptedException { // Arrange String projectId = "test-project"; String branch = "main"; @@ -83,7 +84,7 @@ void getList_Success() throws CxConfig.InvalidCLIConfigException, IOException, U } @Test - void scanShow_Success() throws CxConfig.InvalidCLIConfigException, IOException, URISyntaxException, CxException, InterruptedException { + void scanShow_Success() throws InvalidCLIConfigException, IOException, URISyntaxException, CxException, InterruptedException { // Arrange String scanId = UUID.randomUUID().toString(); @@ -102,7 +103,7 @@ void scanShow_Success() throws CxConfig.InvalidCLIConfigException, IOException, } @Test - void scanCreate_Success() throws CxConfig.InvalidCLIConfigException, IOException, URISyntaxException, CxException, InterruptedException { + void scanCreate_Success() throws InvalidCLIConfigException, IOException, URISyntaxException, CxException, InterruptedException { // Arrange String sourcePath = "/test/path"; String projectName = "test-project"; @@ -128,7 +129,7 @@ void scanCreate_Success() throws CxConfig.InvalidCLIConfigException, IOException } @Test - void scanCancel_Success() throws CxConfig.InvalidCLIConfigException, IOException, URISyntaxException, CxException, InterruptedException { + void scanCancel_Success() throws InvalidCLIConfigException, IOException, URISyntaxException, CxException, InterruptedException { // Arrange String scanId = "test-scan-id"; @@ -145,7 +146,7 @@ void scanCancel_Success() throws CxConfig.InvalidCLIConfigException, IOException } @Test - void scanCancel_ThrowsException() throws CxConfig.InvalidCLIConfigException, IOException, URISyntaxException, CxException, InterruptedException { + void scanCancel_ThrowsException() throws InvalidCLIConfigException, IOException, URISyntaxException, CxException, InterruptedException { // Arrange String scanId = "test-scan-id"; diff --git a/src/test/java/com/checkmarx/intellij/unit/commands/TenantSettingTest.java b/src/test/java/com/checkmarx/intellij/unit/commands/TenantSettingTest.java index 255ddad3..5639f00f 100644 --- a/src/test/java/com/checkmarx/intellij/unit/commands/TenantSettingTest.java +++ b/src/test/java/com/checkmarx/intellij/unit/commands/TenantSettingTest.java @@ -3,6 +3,7 @@ import com.checkmarx.ast.wrapper.CxConfig; import com.checkmarx.ast.wrapper.CxException; import com.checkmarx.ast.wrapper.CxWrapper; +import com.checkmarx.intellij.Exceptions.InvalidCLIConfigException; import com.checkmarx.intellij.commands.TenantSetting; import com.checkmarx.intellij.settings.global.CxWrapperFactory; import org.junit.jupiter.api.BeforeEach; @@ -29,7 +30,7 @@ void setUp() { } @Test - void isScanAllowed_ReturnsTrue() throws CxConfig.InvalidCLIConfigException, IOException, URISyntaxException, CxException, InterruptedException { + void isScanAllowed_ReturnsTrue() throws InvalidCLIConfigException, IOException, URISyntaxException, CxException, InterruptedException { // Arrange try (MockedStatic mockedFactory = mockStatic(CxWrapperFactory.class)) { mockedFactory.when(CxWrapperFactory::build).thenReturn(mockWrapper); @@ -45,7 +46,7 @@ void isScanAllowed_ReturnsTrue() throws CxConfig.InvalidCLIConfigException, IOEx } @Test - void isScanAllowed_ReturnsFalse() throws CxConfig.InvalidCLIConfigException, IOException, URISyntaxException, CxException, InterruptedException { + void isScanAllowed_ReturnsFalse() throws InvalidCLIConfigException, IOException, URISyntaxException, CxException, InterruptedException { // Arrange try (MockedStatic mockedFactory = mockStatic(CxWrapperFactory.class)) { mockedFactory.when(CxWrapperFactory::build).thenReturn(mockWrapper); @@ -61,7 +62,7 @@ void isScanAllowed_ReturnsFalse() throws CxConfig.InvalidCLIConfigException, IOE } @Test - void isScanAllowed_ThrowsException() throws CxConfig.InvalidCLIConfigException, IOException, URISyntaxException, CxException, InterruptedException { + void isScanAllowed_ThrowsException() throws InvalidCLIConfigException, IOException, URISyntaxException, CxException, InterruptedException { // Arrange try (MockedStatic mockedFactory = mockStatic(CxWrapperFactory.class)) { mockedFactory.when(CxWrapperFactory::build).thenReturn(mockWrapper); diff --git a/src/test/java/com/checkmarx/intellij/unit/commands/TriageTest.java b/src/test/java/com/checkmarx/intellij/unit/commands/TriageTest.java index 7260a5fd..f9255129 100644 --- a/src/test/java/com/checkmarx/intellij/unit/commands/TriageTest.java +++ b/src/test/java/com/checkmarx/intellij/unit/commands/TriageTest.java @@ -4,6 +4,7 @@ import com.checkmarx.ast.wrapper.CxConfig; import com.checkmarx.ast.wrapper.CxException; import com.checkmarx.ast.wrapper.CxWrapper; +import com.checkmarx.intellij.Exceptions.InvalidCLIConfigException; import com.checkmarx.intellij.commands.Triage; import com.checkmarx.intellij.settings.global.CxWrapperFactory; import org.junit.jupiter.api.BeforeEach; @@ -38,7 +39,7 @@ void setUp() { } @Test - void triageShow_Success() throws CxConfig.InvalidCLIConfigException, IOException, URISyntaxException, CxException, InterruptedException { + void triageShow_Success() throws InvalidCLIConfigException, IOException, URISyntaxException, CxException, InterruptedException { // Arrange UUID projectId = UUID.randomUUID(); String similarityId = "test-similarity-id"; @@ -60,7 +61,7 @@ void triageShow_Success() throws CxConfig.InvalidCLIConfigException, IOException } @Test - void triageShow_ThrowsException() throws CxConfig.InvalidCLIConfigException, IOException, URISyntaxException, CxException, InterruptedException { + void triageShow_ThrowsException() throws InvalidCLIConfigException, IOException, URISyntaxException, CxException, InterruptedException { // Arrange UUID projectId = UUID.randomUUID(); String similarityId = "test-similarity-id"; @@ -78,7 +79,7 @@ void triageShow_ThrowsException() throws CxConfig.InvalidCLIConfigException, IOE } @Test - void triageUpdate_Success() throws CxConfig.InvalidCLIConfigException, IOException, URISyntaxException, CxException, InterruptedException { + void triageUpdate_Success() throws InvalidCLIConfigException, IOException, URISyntaxException, CxException, InterruptedException { // Arrange UUID projectId = UUID.randomUUID(); String similarityId = "test-similarity-id"; @@ -100,7 +101,7 @@ void triageUpdate_Success() throws CxConfig.InvalidCLIConfigException, IOExcepti } @Test - void triageUpdate_ThrowsException() throws CxConfig.InvalidCLIConfigException, IOException, URISyntaxException, CxException, InterruptedException { + void triageUpdate_ThrowsException() throws InvalidCLIConfigException, IOException, URISyntaxException, CxException, InterruptedException { // Arrange UUID projectId = UUID.randomUUID(); String similarityId = "test-similarity-id";