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));
}
}
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)));
}
}
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.");
}
}
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));
}
}
Aggregations