Search in sources :

Example 1 with ControllerRequest

use of com.checkmarx.flow.dto.ControllerRequest in project cx-flow by checkmarx-ltd.

the class ConfigurationOverrider method overrideFilters.

private void overrideFilters(FlowOverride flowOverride, ScanRequest request, Map<String, String> overrideReport) {
    Optional.ofNullable(flowOverride.getFilters()).ifPresent(override -> {
        FilterFactory filterFactory = new FilterFactory();
        ControllerRequest controllerRequest = new ControllerRequest(override.getSeverity(), override.getCwe(), override.getCategory(), override.getStatus(), override.getState());
        FilterConfiguration filterConfig = filterFactory.getFilter(controllerRequest, null);
        request.setFilter(filterConfig);
        String filterDescr;
        List<Filter> simpleFilters = Optional.ofNullable(filterConfig).map(FilterConfiguration::getSastFilters).map(EngineFilterConfiguration::getSimpleFilters).orElse(null);
        if (CollectionUtils.isNotEmpty(simpleFilters)) {
            filterDescr = simpleFilters.stream().map(Object::toString).collect(Collectors.joining(","));
        } else {
            filterDescr = "EMPTY";
        }
        overrideReport.put("filters", filterDescr);
    });
}
Also used : Filter(com.checkmarx.sdk.dto.sast.Filter) EngineFilterConfiguration(com.checkmarx.sdk.dto.filtering.EngineFilterConfiguration) FilterConfiguration(com.checkmarx.sdk.dto.filtering.FilterConfiguration) ControllerRequest(com.checkmarx.flow.dto.ControllerRequest)

Example 2 with ControllerRequest

use of com.checkmarx.flow.dto.ControllerRequest in project cx-flow by checkmarx-ltd.

the class ConfigurationOverrider method overrideScanRequestProperties.

/**
 * Override scan request details as per file/blob (MachinaOverride)
 */
public ScanRequest overrideScanRequestProperties(FlowOverride override, ScanRequest request) {
    scaConfigOverrider.initScaConfig(request);
    if (override == null) {
        return request;
    }
    BugTracker bt = request.getBugTracker();
    /*Override only applicable to Simple JIRA bug*/
    if (request.getBugTracker().getType().equals(BugTracker.Type.JIRA) && override.getJira() != null) {
        overrideJiraBugProperties(override, bt);
    }
    request.setBugTracker(bt);
    if (!ScanUtils.empty(override.getApplication())) {
        request.setApplication(override.getApplication());
    }
    if (!ScanUtils.empty(override.getBranches())) {
        request.setActiveBranches(override.getBranches());
    }
    List<String> emails = override.getEmails();
    if (emails != null) {
        if (emails.isEmpty()) {
            request.setEmail(null);
        } else {
            request.setEmail(emails);
        }
    }
    FlowOverride.Filters filtersObj = override.getFilters();
    if (filtersObj != null) {
        FilterFactory filterFactory = new FilterFactory();
        ControllerRequest controllerRequest = new ControllerRequest(filtersObj.getSeverity(), filtersObj.getCwe(), filtersObj.getCategory(), filtersObj.getStatus(), filtersObj.getState());
        FilterConfiguration filter = filterFactory.getFilter(controllerRequest, null);
        request.setFilter(filter);
    }
    return request;
}
Also used : EngineFilterConfiguration(com.checkmarx.sdk.dto.filtering.EngineFilterConfiguration) FilterConfiguration(com.checkmarx.sdk.dto.filtering.FilterConfiguration) BugTracker(com.checkmarx.flow.dto.BugTracker) ControllerRequest(com.checkmarx.flow.dto.ControllerRequest) FlowOverride(com.checkmarx.flow.dto.FlowOverride)

Example 3 with ControllerRequest

use of com.checkmarx.flow.dto.ControllerRequest in project cx-flow by checkmarx-ltd.

the class GitHubTestUtils method callController.

/**
 * Executes a controller method that corresponds to eventType.
 * No parameter overrides are passed to the call besides project name.
 */
public void callController(GitHubController controller, EventType eventType, @Nullable String projectNameOverride) {
    String body = loadWebhookRequestBody(eventType);
    String signature = createSignature(body);
    ControllerRequest request = ControllerRequest.builder().project(projectNameOverride).build();
    if (eventType == EventType.PULL_REQUEST) {
        controller.pullRequest(body, signature, null, request);
    } else {
        controller.pushRequest(body, signature, null, request);
    }
}
Also used : ControllerRequest(com.checkmarx.flow.dto.ControllerRequest)

Example 4 with ControllerRequest

use of com.checkmarx.flow.dto.ControllerRequest in project cx-flow by checkmarx-ltd.

the class UpdatePullRequestCommentsSteps method buildGitHubPullRequest.

public void buildGitHubPullRequest() {
    PullEvent pullEvent = new PullEvent();
    Repository repo = new Repository();
    repo.setName("vb_test_udi");
    repo.setCloneUrl(gitHubProperties.getUrl());
    Owner owner = new Owner();
    owner.setName("");
    owner.setLogin("cxflowtestuser");
    Repo r = new Repo();
    r.setOwner(owner);
    repo.setOwner(owner);
    pullEvent.setRepository(repo);
    pullEvent.setAction("opened");
    PullRequest pullRequest = new PullRequest();
    pullRequest.setIssueUrl("");
    Head headBranch = new Head();
    headBranch.setRef(branchGitHub);
    headBranch.setRepo(r);
    pullRequest.setHead(headBranch);
    pullRequest.setBase(new Base());
    pullRequest.setStatusesUrl("");
    pullRequest.setIssueUrl(GITHUB_PR_BASE_URL + "/issues/" + GITHUB_PR_ID);
    pullEvent.setPullRequest(pullRequest);
    try {
        String pullEventStr = mapper.writeValueAsString(pullEvent);
        ControllerRequest controllerRequest = new ControllerRequest();
        controllerRequest.setApplication("VB");
        controllerRequest.setBranch(Collections.singletonList(branchGitHub));
        controllerRequest.setProject("VB");
        controllerRequest.setTeam("\\CxServer\\SP");
        controllerRequest.setPreset("default");
        controllerRequest.setIncremental(false);
        gitHubControllerSpy.pullRequest(pullEventStr, "SIGNATURE", "CX", controllerRequest);
    } catch (JsonProcessingException e) {
        fail("Unable to parse " + pullEvent);
    }
}
Also used : Repository(com.checkmarx.flow.dto.github.Repository) PullEvent(com.checkmarx.flow.dto.github.PullEvent) ControllerRequest(com.checkmarx.flow.dto.ControllerRequest) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 5 with ControllerRequest

use of com.checkmarx.flow.dto.ControllerRequest in project cx-flow by checkmarx-ltd.

the class UpdatePullRequestCommentsSteps method buildADOPullRequestEvent.

public void buildADOPullRequestEvent() {
    com.checkmarx.flow.dto.azure.PullEvent pullEvent = new com.checkmarx.flow.dto.azure.PullEvent();
    pullEvent.setEventType("git.pullrequest.updated");
    pullEvent.setId("4519989c-c157-4bf8-9651-e94b8d0fca27");
    pullEvent.setSubscriptionId("25aa3b80-54ed-4b26-976a-b74f94940852");
    pullEvent.setPublisherId("tfs");
    Project_ project = new Project_();
    project.setId("3172109f-8bcb-4f21-a8f7-4f94d4a825b0");
    project.setBaseUrl("https://dev.azure.com/OrgName/");
    ResourceContainers resourceContainers = new ResourceContainers();
    resourceContainers.setProject(project);
    pullEvent.setResourceContainers(resourceContainers);
    Resource resource = new Resource();
    resource.setStatus("active");
    resource.setSourceRefName("refs/heads/master");
    resource.setTargetRefName("refs/heads/udi-tests-2");
    resource.setUrl("https://dev.azure.com/CxNamespace/d50fc6e5-a5ab-4123-9bc9-ccb756c0bf16/_apis/git/repositories/a89a9d2f-ab67-4bda-9c56-a571224c2c66/pullRequests/" + ADO_PR_ID);
    com.checkmarx.flow.dto.azure.Repository repo = new com.checkmarx.flow.dto.azure.Repository();
    repo.setId("a89a9d2f-ab67-4bda-9c56-a571224c2c66");
    repo.setName("AdoPullRequestTests");
    repo.setUrl("https://dev.azure.com/CxNamespace/d50fc6e5-a5ab-4123-9bc9-ccb756c0bf16/_apis/git/repositories/a89a9d2f-ab67-4bda-9c56-a571224c2c66");
    repo.setRemoteUrl("https://CxNamespace@dev.azure.com/CxNamespace/AdoPullRequestTests/_git/AdoPullRequestTests");
    repo.setSshUrl("git@ssh.dev.azure.com:v3/CxNamespace/AdoPullRequestTests/AdoPullRequestTests");
    repo.setWebUrl("https://dev.azure.com/CxNamespace/AdoPullRequestTests/_git/AdoPullRequestTests");
    Project pr = new Project();
    pr.setId("d50fc6e5-a5ab-4123-9bc9-ccb756c0bf16");
    pr.setName("AdoPullRequestTests");
    repo.setProject(pr);
    resource.setRepository(repo);
    pullEvent.setResource(resource);
    ControllerRequest controllerRequest = new ControllerRequest();
    controllerRequest.setProject("AdoPullRequestTests-master");
    controllerRequest.setTeam("\\CxServer\\SP");
    AdoDetailsRequest adoRequest = new AdoDetailsRequest();
    adoControllerSpy.pullRequest(pullEvent, "Basic Y3hmbG93OjEyMzQ=", null, controllerRequest, adoRequest);
}
Also used : PullEvent(com.checkmarx.flow.dto.github.PullEvent) ControllerRequest(com.checkmarx.flow.dto.ControllerRequest) Repository(com.checkmarx.flow.dto.github.Repository) com.checkmarx.flow.dto.azure(com.checkmarx.flow.dto.azure)

Aggregations

ControllerRequest (com.checkmarx.flow.dto.ControllerRequest)15 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)7 Repository (com.checkmarx.flow.dto.github.Repository)3 FilterConfiguration (com.checkmarx.sdk.dto.filtering.FilterConfiguration)3 BugTracker (com.checkmarx.flow.dto.BugTracker)2 FlowOverride (com.checkmarx.flow.dto.FlowOverride)2 com.checkmarx.flow.dto.azure (com.checkmarx.flow.dto.azure)2 PullEvent (com.checkmarx.flow.dto.github.PullEvent)2 EngineFilterConfiguration (com.checkmarx.sdk.dto.filtering.EngineFilterConfiguration)2 ScanRequest (com.checkmarx.flow.dto.ScanRequest)1 LastCommit (com.checkmarx.flow.dto.gitlab.LastCommit)1 MergeEvent (com.checkmarx.flow.dto.gitlab.MergeEvent)1 Project (com.checkmarx.flow.dto.gitlab.Project)1 PushEvent (com.checkmarx.flow.dto.gitlab.PushEvent)1 Repository (com.checkmarx.flow.dto.gitlab.Repository)1 ShardSession (com.checkmarx.sdk.ShardManager.ShardSession)1 ScanResults (com.checkmarx.sdk.dto.ScanResults)1 Filter (com.checkmarx.sdk.dto.sast.Filter)1