Skip to content

Commit

Permalink
Fixed incorrect search behavior for GitLab projects with multi-segmen…
Browse files Browse the repository at this point in the history
…t namespace path.
  • Loading branch information
alex-ko-dev committed Oct 1, 2020
1 parent e284144 commit e04f7be
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
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

0 comments on commit e04f7be

Please sign in to comment.