Search in sources :

Example 1 with FilterValidator

use of com.checkmarx.sdk.service.FilterValidator in project checkmarx-spring-boot-java-sdk by checkmarx-ltd.

the class FilterValidatorTest method verifyScriptResult.

private static void verifyScriptResult(Script script, String severity, String status, String state, String name, String cweId, boolean expectedResult) {
    ResultType finding = createFinding(status, state);
    QueryType findingGroup = createFindingGroup(severity, name, cweId);
    EngineFilterConfiguration filterConfiguration = createFilterConfiguration(script);
    FilterValidator validator = new FilterValidator();
    FilterInputFactory filterInputFactory = new FilterInputFactory(new CxProperties());
    FilterInput filterInput = filterInputFactory.createFilterInputForCxSast(findingGroup, finding);
    boolean actualResult = validator.passesFilter(filterInput, filterConfiguration);
    assertEquals(expectedResult, actualResult, "Unexpected script filtering result.");
}
Also used : FilterInput(com.checkmarx.sdk.dto.filtering.FilterInput) FilterInputFactory(com.checkmarx.sdk.service.FilterInputFactory) CxProperties(com.checkmarx.sdk.config.CxProperties) ResultType(com.checkmarx.sdk.dto.cx.xml.ResultType) EngineFilterConfiguration(com.checkmarx.sdk.dto.filtering.EngineFilterConfiguration) QueryType(com.checkmarx.sdk.dto.cx.xml.QueryType) FilterValidator(com.checkmarx.sdk.service.FilterValidator)

Example 2 with FilterValidator

use of com.checkmarx.sdk.service.FilterValidator in project checkmarx-spring-boot-java-sdk by checkmarx-ltd.

the class FilterValidatorTest method validateExpectedError.

private void validateExpectedError(String scriptWithUnknownObject) {
    Script script = parse(scriptWithUnknownObject);
    QueryType findingGroup = createFindingGroup(SEVERITY_LOW, NAME1, CWE1);
    ResultType finding = createFinding(STATUS_NEW, STATE_URGENT_ID);
    EngineFilterConfiguration filterConfiguration = createFilterConfiguration(script);
    FilterValidator validator = new FilterValidator();
    try {
        FilterInputFactory filterInputFactory = new FilterInputFactory(new CxProperties());
        FilterInput filterInput = filterInputFactory.createFilterInputForCxSast(findingGroup, finding);
        validator.passesFilter(filterInput, filterConfiguration);
    } catch (Exception e) {
        assertTrue(e instanceof CheckmarxRuntimeException, String.format("Expected %s to be thrown.", CheckmarxRuntimeException.class));
        assertTrue(e.getCause() instanceof GroovyRuntimeException, String.format("Expected exception cause to be %s", GroovyRuntimeException.class));
    }
}
Also used : Script(groovy.lang.Script) FilterInput(com.checkmarx.sdk.dto.filtering.FilterInput) FilterInputFactory(com.checkmarx.sdk.service.FilterInputFactory) GroovyRuntimeException(groovy.lang.GroovyRuntimeException) CxProperties(com.checkmarx.sdk.config.CxProperties) CheckmarxRuntimeException(com.checkmarx.sdk.exception.CheckmarxRuntimeException) ResultType(com.checkmarx.sdk.dto.cx.xml.ResultType) EngineFilterConfiguration(com.checkmarx.sdk.dto.filtering.EngineFilterConfiguration) QueryType(com.checkmarx.sdk.dto.cx.xml.QueryType) FilterValidator(com.checkmarx.sdk.service.FilterValidator) GroovyRuntimeException(groovy.lang.GroovyRuntimeException) CheckmarxRuntimeException(com.checkmarx.sdk.exception.CheckmarxRuntimeException)

Example 3 with FilterValidator

use of com.checkmarx.sdk.service.FilterValidator in project checkmarx-spring-boot-java-sdk by checkmarx-ltd.

the class FilterValidatorTest method verifySimpleFilterResult.

private static void verifySimpleFilterResult(List<Filter> filters, String severity, String status, String state, String name, String cweId, boolean expectedResult) {
    ResultType finding = createFinding(status, state);
    QueryType findingGroup = createFindingGroup(severity, name, cweId);
    FilterValidator filterValidator = new FilterValidator();
    EngineFilterConfiguration filterConfiguration = EngineFilterConfiguration.builder().simpleFilters(filters).build();
    FilterInputFactory filterInputFactory = new FilterInputFactory(new CxProperties());
    FilterInput filterInput = filterInputFactory.createFilterInputForCxSast(findingGroup, finding);
    boolean passes = filterValidator.passesFilter(filterInput, filterConfiguration);
    assertEquals(expectedResult, passes, "Unexpected simple filtering result.");
}
Also used : FilterInput(com.checkmarx.sdk.dto.filtering.FilterInput) FilterInputFactory(com.checkmarx.sdk.service.FilterInputFactory) CxProperties(com.checkmarx.sdk.config.CxProperties) ResultType(com.checkmarx.sdk.dto.cx.xml.ResultType) EngineFilterConfiguration(com.checkmarx.sdk.dto.filtering.EngineFilterConfiguration) QueryType(com.checkmarx.sdk.dto.cx.xml.QueryType) FilterValidator(com.checkmarx.sdk.service.FilterValidator)

Example 4 with FilterValidator

use of com.checkmarx.sdk.service.FilterValidator in project checkmarx-spring-boot-java-sdk by checkmarx-ltd.

the class CxGoFilterValidatorTest method verifySimpleFilterResult.

private static void verifySimpleFilterResult(List<Filter> filters, String severity, String status, String state, String category, String cweId, boolean expectedResult) {
    FilterInput finding = createFilterInput(severity, category, status, state, cweId);
    FilterValidator filterValidator = new FilterValidator();
    FilterConfiguration filterConfiguration = FilterConfiguration.fromSimpleFilters(filters);
    boolean passes = filterValidator.passesFilter(finding, filterConfiguration.getSastFilters());
    assertEquals(expectedResult, passes, "Unexpected simple filtering result.");
}
Also used : FilterValidator(com.checkmarx.sdk.service.FilterValidator)

Example 5 with FilterValidator

use of com.checkmarx.sdk.service.FilterValidator in project checkmarx-spring-boot-java-sdk by checkmarx-ltd.

the class CxGoFilterValidatorTest method validateExpectedError.

private void validateExpectedError(String scriptWithRuntimeError) {
    Script script = parse(scriptWithRuntimeError);
    FilterInput finding = createFilterInput(SEVERITY_LOW, CATEGORY1, STATUS_NEW, STATE_URGENT_NAME, CWE1);
    EngineFilterConfiguration filterConfiguration = createFilterConfiguration(script);
    FilterValidator validator = new FilterValidator();
    try {
        validator.passesFilter(finding, filterConfiguration);
    } catch (Exception e) {
        assertTrue(e instanceof CheckmarxRuntimeException, String.format("Expected %s to be thrown.", CheckmarxRuntimeException.class));
        assertTrue(e.getCause() instanceof GroovyRuntimeException, String.format("Expected exception cause to be %s", GroovyRuntimeException.class));
    }
}
Also used : Script(groovy.lang.Script) GroovyRuntimeException(groovy.lang.GroovyRuntimeException) CheckmarxRuntimeException(com.checkmarx.sdk.exception.CheckmarxRuntimeException) FilterValidator(com.checkmarx.sdk.service.FilterValidator) GroovyRuntimeException(groovy.lang.GroovyRuntimeException) CheckmarxRuntimeException(com.checkmarx.sdk.exception.CheckmarxRuntimeException)

Aggregations

FilterValidator (com.checkmarx.sdk.service.FilterValidator)7 CxProperties (com.checkmarx.sdk.config.CxProperties)3 QueryType (com.checkmarx.sdk.dto.cx.xml.QueryType)3 ResultType (com.checkmarx.sdk.dto.cx.xml.ResultType)3 EngineFilterConfiguration (com.checkmarx.sdk.dto.filtering.EngineFilterConfiguration)3 FilterInput (com.checkmarx.sdk.dto.filtering.FilterInput)3 FilterInputFactory (com.checkmarx.sdk.service.FilterInputFactory)3 CheckmarxRuntimeException (com.checkmarx.sdk.exception.CheckmarxRuntimeException)2 GroovyRuntimeException (groovy.lang.GroovyRuntimeException)2 Script (groovy.lang.Script)2 Filter (com.checkmarx.sdk.dto.sast.Filter)1