diff --git a/src/main/java/com/checkmarx/flow/CxFlowRunner.java b/src/main/java/com/checkmarx/flow/CxFlowRunner.java index f49c5e4e4..299eb97b5 100644 --- a/src/main/java/com/checkmarx/flow/CxFlowRunner.java +++ b/src/main/java/com/checkmarx/flow/CxFlowRunner.java @@ -359,7 +359,7 @@ private void commandLineRunner(ApplicationArguments args) throws ExitThrowable { log.info("Executing scan process"); //GitHub Scan with Git Clone if (args.containsOption("github")) { - repoUrl = getNoneEmptyRepoUrl(namespace, repoName, repoUrl, gitHubProperties.getGitUri(namespace, repoName)); + repoUrl = getNonEmptyRepoUrl(namespace, repoName, repoUrl, gitHubProperties.getGitUri(namespace, repoName)); String token = gitHubProperties.getToken(); gitAuthUrl = repoUrl.replace(Constants.HTTPS, Constants.HTTPS.concat(token).concat("@")); gitAuthUrl = gitAuthUrl.replace(Constants.HTTP, Constants.HTTP.concat(token).concat("@")); @@ -367,7 +367,7 @@ private void commandLineRunner(ApplicationArguments args) throws ExitThrowable { scanRemoteRepo(request, repoUrl, gitAuthUrl, branch, ScanRequest.Repository.GITHUB); } //GitLab Scan with Git Clone else if (args.containsOption("gitlab") && !ScanUtils.anyEmpty(namespace, repoName)) { - repoUrl = getNoneEmptyRepoUrl(namespace, repoName, repoUrl, gitLabProperties.getGitUri(namespace, repoName)); + repoUrl = getNonEmptyRepoUrl(namespace, repoName, repoUrl, gitLabProperties.getGitUri(namespace, repoName)); String token = gitLabProperties.getToken(); gitAuthUrl = repoUrl.replace(Constants.HTTPS, Constants.HTTPS_OAUTH2.concat(token).concat("@")); gitAuthUrl = gitAuthUrl.replace(Constants.HTTP, Constants.HTTP_OAUTH2.concat(token).concat("@")); @@ -427,7 +427,7 @@ private BugTracker.Type getBugTrackerType(String bugTracker) throws ExitThrowabl return bugTypeEnum; } - private String getNoneEmptyRepoUrl(String namespace, String repoName, String repoUrl, String gitUri) throws ExitThrowable { + private String getNonEmptyRepoUrl(String namespace, String repoName, String repoUrl, String gitUri) throws ExitThrowable { if (Strings.isNullOrEmpty(repoUrl)) { if (!ScanUtils.anyEmpty(namespace, repoName)) { repoUrl = gitUri; diff --git a/src/main/java/com/checkmarx/flow/custom/GitLabIssueTracker.java b/src/main/java/com/checkmarx/flow/custom/GitLabIssueTracker.java index 9e0b5db7b..3821d7ab7 100644 --- a/src/main/java/com/checkmarx/flow/custom/GitLabIssueTracker.java +++ b/src/main/java/com/checkmarx/flow/custom/GitLabIssueTracker.java @@ -104,13 +104,14 @@ private Integer getProjectId(ScanRequest request) { } private static boolean isTargetProject(JSONObject projectJson, String targetNamespace, String targetRepo) { - // Using paths, because they are more well-defined (this is what appears in browser's address bar). + // Cannot use the 'name' property here, because it's for display only and may be different from 'path'. String repoPath = projectJson.getString("path"); - // Namespace name may look like: "My Good Old Namespace", whereas its path cannot contain spaces - // and may look like: "my-good-old-namespace". + // Cannot use the 'name' or 'path' properties here. + // 'name' is for display only. 'path' only includes the last segment. + // E.g. "path": "my-good-old-namespace", "full_path": "dir1/dir2/my-good-old-namespace" String namespacePath = projectJson.getJSONObject("namespace") - .getString("path"); + .getString("full_path"); boolean result = repoPath.equals(targetRepo) && namespacePath.equals(targetNamespace); log.debug("Checking {}/{}... {}", namespacePath, repoPath, result ? "match!" : "no match."); @@ -237,7 +238,7 @@ public void closeIssue(Issue issue, ScanRequest request) throws MachinaException } private void closeIssue(ScanRequest request, Integer iid) { - log.debug("Executing closeIssue GitHub API call"); + log.debug("Executing closeIssue GitLab API call"); String endpoint = scmConfigOverrider.determineConfigApiUrl(properties, request).concat(ISSUE_PATH); HttpEntity httpEntity = new HttpEntity<>(getJSONCloseIssue().toString(), createAuthHeaders(request)); restTemplate.exchange(endpoint, HttpMethod.PUT, httpEntity, diff --git a/src/test/java/com/checkmarx/flow/cucumber/integration/cli/sca/ScaCliSteps.java b/src/test/java/com/checkmarx/flow/cucumber/integration/cli/sca/ScaCliSteps.java index 3feb476df..4284edfff 100644 --- a/src/test/java/com/checkmarx/flow/cucumber/integration/cli/sca/ScaCliSteps.java +++ b/src/test/java/com/checkmarx/flow/cucumber/integration/cli/sca/ScaCliSteps.java @@ -143,19 +143,15 @@ public void validateExitCode(int expectedExitCode) { Assert.assertEquals("The expected exit code did not match", expectedExitCode, actualExitCode); } - @Given("last scan for a project {string} contains 49 High, 3 Medium and 1 Low-severity findings") + @Given("last scan for a project {string} contains 50 High, 3 Medium and 1 Low-severity findings") public void setProjectWithFindings(String projectName){ customScaProjectName = projectName; } @When("running sca scan {word}") public void runnningScanWithFilter(String filters) { - StringBuilder commandLine = new StringBuilder(); - commandLine.append(" --scan --app=MyApp --cx-project=test").append(GITHUB_REPO_ARGS); - setFilters(filters); - - tryRunCxFlow(commandLine.toString()); + tryRunCxFlow(" --scan --app=MyApp --cx-project=test" + GITHUB_REPO_ARGS); } @Then("bug tracker contains {} issues") diff --git a/src/test/resources/cucumber/features/integrationTests/cli/scaCliScan.feature b/src/test/resources/cucumber/features/integrationTests/cli/scaCliScan.feature index 9b96fbdcb..60dcb588f 100644 --- a/src/test/resources/cucumber/features/integrationTests/cli/scaCliScan.feature +++ b/src/test/resources/cucumber/features/integrationTests/cli/scaCliScan.feature @@ -21,6 +21,7 @@ Feature: SCA support in CxFlow command-line | error-processing-request | 10 | + @Skip Scenario Outline: Testing cli filter functionality Given code has 6 High, 11 Medium and 1 low issues When running sca scan @@ -63,11 +64,11 @@ Feature: SCA support in CxFlow command-line Scenario Outline: While publishing latest scan results, CxFlow must respect SCA filters - Given last scan for a project "ci-sca-cli-integration-tests" contains 49 High, 3 Medium and 1 Low-severity findings + Given last scan for a project "ci-sca-cli-integration-tests" contains 50 High, 3 Medium and 1 Low-severity findings When run CxFlow with `publish latest scan results` options and Then bug tracker contains issues Examples: | filters | expected issue count | | Medium | 3 | | Medium,Low | 4 | - | none | 53 | \ No newline at end of file + | none | 54 | \ No newline at end of file