Search in sources :

Example 1 with CheckmarxRuntimeException

use of com.checkmarx.sdk.exception.CheckmarxRuntimeException 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 2 with CheckmarxRuntimeException

use of com.checkmarx.sdk.exception.CheckmarxRuntimeException in project checkmarx-spring-boot-java-sdk by checkmarx-ltd.

the class GoScanner method getScanDetails.

public Scan getScanDetails(Integer scanId) throws CheckmarxException {
    HttpEntity httpEntity = new HttpEntity<>(authClient.createAuthHeaders());
    try {
        log.debug("Retrieving scan with id {}", scanId);
        ResponseEntity<Scan> response = restTemplate.exchange(cxGoProperties.getUrl().concat(SCAN), HttpMethod.GET, httpEntity, Scan.class, scanId);
        return Optional.ofNullable(response.getBody()).orElseThrow(() -> new CheckmarxRuntimeException("Scan details response body is missing."));
    } catch (HttpStatusCodeException e) {
        log.error("Error occurred while retrieving the scan with id {}", scanId);
        log.error(ExceptionUtils.getStackTrace(e));
        throw new CheckmarxException("Error occurred while retrieving the scan with id".concat(Integer.toString(scanId)));
    }
}
Also used : HttpEntity(org.springframework.http.HttpEntity) CheckmarxException(com.checkmarx.sdk.exception.CheckmarxException) CheckmarxRuntimeException(com.checkmarx.sdk.exception.CheckmarxRuntimeException) HttpStatusCodeException(org.springframework.web.client.HttpStatusCodeException)

Example 3 with CheckmarxRuntimeException

use of com.checkmarx.sdk.exception.CheckmarxRuntimeException in project checkmarx-spring-boot-java-sdk by checkmarx-ltd.

the class FilterValidator method passesScriptedFilter.

private static boolean passesScriptedFilter(FilterInput finding, EngineFilterConfiguration filterConfiguration) {
    Script script = filterConfiguration.getScriptedFilter().getScript();
    Binding binding = new Binding();
    binding.setVariable(INPUT_VARIABLE_NAME, finding);
    script.setBinding(binding);
    Object rawResult = null;
    try {
        rawResult = script.run();
    } catch (GroovyRuntimeException e) {
        rethrowWithDetailedMessage(e);
    } catch (Exception e) {
        throw new CheckmarxRuntimeException("An unexpected error has occurred while executing the filter script.", e);
    }
    if (rawResult instanceof Boolean) {
        return (boolean) rawResult;
    } else {
        throw new CheckmarxRuntimeException("Filtering script must return a boolean value.");
    }
}
Also used : Binding(groovy.lang.Binding) Script(groovy.lang.Script) GroovyRuntimeException(groovy.lang.GroovyRuntimeException) CheckmarxRuntimeException(com.checkmarx.sdk.exception.CheckmarxRuntimeException) GroovyRuntimeException(groovy.lang.GroovyRuntimeException) CheckmarxRuntimeException(com.checkmarx.sdk.exception.CheckmarxRuntimeException) ParseException(java.text.ParseException)

Example 4 with CheckmarxRuntimeException

use of com.checkmarx.sdk.exception.CheckmarxRuntimeException 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

CheckmarxRuntimeException (com.checkmarx.sdk.exception.CheckmarxRuntimeException)4 GroovyRuntimeException (groovy.lang.GroovyRuntimeException)3 Script (groovy.lang.Script)3 FilterValidator (com.checkmarx.sdk.service.FilterValidator)2 CxProperties (com.checkmarx.sdk.config.CxProperties)1 QueryType (com.checkmarx.sdk.dto.cx.xml.QueryType)1 ResultType (com.checkmarx.sdk.dto.cx.xml.ResultType)1 EngineFilterConfiguration (com.checkmarx.sdk.dto.filtering.EngineFilterConfiguration)1 FilterInput (com.checkmarx.sdk.dto.filtering.FilterInput)1 CheckmarxException (com.checkmarx.sdk.exception.CheckmarxException)1 FilterInputFactory (com.checkmarx.sdk.service.FilterInputFactory)1 Binding (groovy.lang.Binding)1 ParseException (java.text.ParseException)1 HttpEntity (org.springframework.http.HttpEntity)1 HttpStatusCodeException (org.springframework.web.client.HttpStatusCodeException)1