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

Fixed incorrect search behavior for GitLab projects #435

Merged
merged 2 commits into from
Oct 4, 2020
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
6 changes: 3 additions & 3 deletions src/main/java/com/checkmarx/flow/CxFlowRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -359,15 +359,15 @@ 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("@"));

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("@"));
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/com/checkmarx/flow/custom/GitLabIssueTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down Expand Up @@ -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<String> httpEntity = new HttpEntity<>(getJSONCloseIssue().toString(), createAuthHeaders(request));
restTemplate.exchange(endpoint, HttpMethod.PUT, httpEntity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <filter>
Expand Down Expand Up @@ -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 <filters>
Then bug tracker contains <expected issue count> issues
Examples:
| filters | expected issue count |
| Medium | 3 |
| Medium,Low | 4 |
| none | 53 |
| none | 54 |