Search in sources :

Example 6 with Filter

use of com.checkmarx.sdk.dto.sast.Filter in project checkmarx-spring-boot-java-sdk by checkmarx-ltd.

the class FilterValidatorTest method passesFilter_allSimpleFilters.

@Test
public void passesFilter_allSimpleFilters() {
    Filter severity = Filter.builder().type(Filter.Type.SEVERITY).value(SEVERITY_HIGH).build();
    Filter cwe = Filter.builder().type(Filter.Type.CWE).value(CWE1).build();
    Filter type = Filter.builder().type(Filter.Type.TYPE).value(NAME1).build();
    Filter status = Filter.builder().type(Filter.Type.STATUS).value(STATUS_NEW).build();
    // Using state name to init the filter, and a corresponding state ID while creating a finding.
    Filter state = Filter.builder().type(Filter.Type.STATE).value(STATE_URGENT_NAME).build();
    List<Filter> filters = Arrays.asList(severity, cwe, type, status, state);
    verifySimpleFilterResult(filters, SEVERITY_HIGH, STATUS_NEW, STATE_URGENT_ID, NAME1, CWE1, true);
    verifySimpleFilterResult(filters, SEVERITY_MEDIUM, STATUS_NEW, STATE_URGENT_ID, NAME1, CWE1, false);
    verifySimpleFilterResult(filters, SEVERITY_HIGH, STATUS_RECURRENT, STATE_URGENT_ID, NAME1, CWE1, false);
    verifySimpleFilterResult(filters, SEVERITY_HIGH, STATUS_NEW, STATE_VERIFY_ID, NAME1, CWE1, false);
    verifySimpleFilterResult(filters, SEVERITY_HIGH, STATUS_NEW, STATE_URGENT_ID, NAME2, CWE1, false);
    verifySimpleFilterResult(filters, SEVERITY_HIGH, STATUS_NEW, STATE_URGENT_ID, NAME1, CWE2, false);
}
Also used : Filter(com.checkmarx.sdk.dto.sast.Filter) ScriptedFilter(com.checkmarx.sdk.dto.filtering.ScriptedFilter) Test(org.junit.Test)

Example 7 with Filter

use of com.checkmarx.sdk.dto.sast.Filter in project checkmarx-spring-boot-java-sdk by checkmarx-ltd.

the class CxGoServiceIT method completeScanFlow.

@Test
// works only on Windows
@Ignore
public void completeScanFlow() throws CheckmarxException {
    login();
    if (StringUtils.isNotEmpty(properties.getClientSecret())) {
        String teamId = service.getTeamId(properties.getTeam());
        Integer projectId = service.getProjectId(teamId, GO_PROJECT_NAME);
        CxScanParams params = new CxScanParams();
        params.setProjectName(GO_PROJECT_NAME);
        params.setTeamId(teamId);
        params.setProjectId(projectId);
        params.setGitUrl("https://github.com/Custodela/Riches.git");
        params.setBranch("refs/heads/master");
        params.setSourceType(CxScanParams.Type.GIT);
        // run the scan and wait for it to finish
        Integer x = service.createScan(params, "CxFlow Scan");
        service.waitForScanCompletion(x);
        FilterConfiguration filterConfiguration = FilterConfiguration.fromSimpleFilters(Collections.singletonList(new Filter(Filter.Type.SEVERITY, "High")));
        // generate the results
        ScanResults results = service.getReportContentByScanId(x, filterConfiguration);
        assertNotNull(results);
    }
}
Also used : CxScanParams(com.checkmarx.sdk.dto.cx.CxScanParams) Filter(com.checkmarx.sdk.dto.sast.Filter) ScanResults(com.checkmarx.sdk.dto.ScanResults) FilterConfiguration(com.checkmarx.sdk.dto.filtering.FilterConfiguration) Ignore(org.junit.Ignore) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 8 with Filter

use of com.checkmarx.sdk.dto.sast.Filter in project checkmarx-spring-boot-java-sdk by checkmarx-ltd.

the class CxServiceIT method getReportContent.

@Test
public void getReportContent() {
    try {
        List<Filter> filters = new ArrayList<>();
        filters.add(new Filter(Filter.Type.SEVERITY, "High"));
        FilterConfiguration filterConfiguration = FilterConfiguration.fromSimpleFilters(filters);
        ScanResults results = service.getLatestScanResults(properties.getTeam(), "Riches", filterConfiguration);
        assertNotNull(results);
    } catch (CheckmarxException e) {
        fail("Unexpected CheckmarxException");
    }
}
Also used : Filter(com.checkmarx.sdk.dto.sast.Filter) ScanResults(com.checkmarx.sdk.dto.ScanResults) CheckmarxException(com.checkmarx.sdk.exception.CheckmarxException) ArrayList(java.util.ArrayList) FilterConfiguration(com.checkmarx.sdk.dto.filtering.FilterConfiguration) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 9 with Filter

use of com.checkmarx.sdk.dto.sast.Filter in project checkmarx-spring-boot-java-sdk by checkmarx-ltd.

the class CxServiceIT method completeScanFlow.

@Test
@Ignore("Stable environment required")
public void completeScanFlow() throws CheckmarxException {
    final String PROJECT_NAME = "my-project-name";
    final String GIT_REPO_URL = "https://github.com/my-organization/my-repo.git";
    final String BRANCH_NAME = "refs/heads/develop";
    String teamId = service.getTeamId(properties.getTeam());
    Integer projectId = service.getProjectId(teamId, PROJECT_NAME);
    CxScanParams params = new CxScanParams();
    params.setProjectName(PROJECT_NAME);
    params.setTeamId(teamId);
    params.setProjectId(projectId);
    params.setGitUrl(GIT_REPO_URL);
    params.setBranch(BRANCH_NAME);
    params.setSourceType(CxScanParams.Type.GIT);
    // run the scan and wait for it to finish
    Integer x = service.createScan(params, "CxSDK Scan");
    service.waitForScanCompletion(x);
    List<Filter> highSeverityOnly = Collections.singletonList(new Filter(Filter.Type.SEVERITY, "High"));
    FilterConfiguration filterConfiguration = FilterConfiguration.fromSimpleFilters(highSeverityOnly);
    // generate the results
    ScanResults results = service.getReportContentByScanId(x, filterConfiguration);
    assertNotNull(results);
}
Also used : CxScanParams(com.checkmarx.sdk.dto.cx.CxScanParams) Filter(com.checkmarx.sdk.dto.sast.Filter) ScanResults(com.checkmarx.sdk.dto.ScanResults) FilterConfiguration(com.checkmarx.sdk.dto.filtering.FilterConfiguration) Ignore(org.junit.Ignore) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 10 with Filter

use of com.checkmarx.sdk.dto.sast.Filter in project checkmarx-spring-boot-java-sdk by checkmarx-ltd.

the class FilterValidator method groupFilterValuesByFilterType.

private static Map<Filter.Type, List<String>> groupFilterValuesByFilterType(List<Filter> filters) {
    // First prepare an empty list for each Filter.Type enum member.
    Map<Filter.Type, List<String>> valuesByType = Arrays.stream(Filter.Type.values()).collect(Collectors.toMap(Function.identity(), filterType -> new ArrayList<>()));
    // Populate the lists using the provided filters.
    for (Filter filter : filters) {
        List<String> targetList = valuesByType.get(filter.getType());
        String safeValue = StringUtils.defaultString(filter.getValue());
        targetList.add(safeValue.toUpperCase(Locale.ROOT));
    }
    return valuesByType;
}
Also used : Arrays(java.util.Arrays) GroovyRuntimeException(groovy.lang.GroovyRuntimeException) Filter(com.checkmarx.sdk.dto.sast.Filter) EngineFilterConfiguration(com.checkmarx.sdk.dto.filtering.EngineFilterConfiguration) Script(groovy.lang.Script) NotNull(javax.validation.constraints.NotNull) Field(java.lang.reflect.Field) StringUtils(org.apache.commons.lang3.StringUtils) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) CollectionUtils(org.apache.commons.collections4.CollectionUtils) NumberFormat(java.text.NumberFormat) ArrayList(java.util.ArrayList) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) CheckmarxRuntimeException(com.checkmarx.sdk.exception.CheckmarxRuntimeException) Service(org.springframework.stereotype.Service) Locale(java.util.Locale) Map(java.util.Map) FilterInput(com.checkmarx.sdk.dto.filtering.FilterInput) Binding(groovy.lang.Binding) ParseException(java.text.ParseException) Filter(com.checkmarx.sdk.dto.sast.Filter) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

Filter (com.checkmarx.sdk.dto.sast.Filter)19 FilterConfiguration (com.checkmarx.sdk.dto.filtering.FilterConfiguration)6 ScanResults (com.checkmarx.sdk.dto.ScanResults)5 Test (org.junit.Test)4 EngineFilterConfiguration (com.checkmarx.sdk.dto.filtering.EngineFilterConfiguration)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 CxScanParams (com.checkmarx.sdk.dto.cx.CxScanParams)2 CheckmarxException (com.checkmarx.sdk.exception.CheckmarxException)2 Given (io.cucumber.java.en.Given)2 Then (io.cucumber.java.en.Then)2 ArrayList (java.util.ArrayList)2 Function (java.util.function.Function)2 Collectors (java.util.stream.Collectors)2 Slf4j (lombok.extern.slf4j.Slf4j)2 Ignore (org.junit.Ignore)2 Issue (com.atlassian.jira.rest.client.api.domain.Issue)1 SearchResult (com.atlassian.jira.rest.client.api.domain.SearchResult)1 CxFlowApplication (com.checkmarx.flow.CxFlowApplication)1 FlowProperties (com.checkmarx.flow.config.FlowProperties)1 RepoProperties (com.checkmarx.flow.config.RepoProperties)1