Search in sources :

Example 36 with ScanResults

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

the class SastScanner method cxParseResults.

public void cxParseResults(ScanRequest request, File file) throws ExitThrowable {
    try {
        ScanResults results = cxService.getReportContent(file, request.getFilter());
        resultsService.processResults(request, results, scanDetails);
        if (flowProperties.isBreakBuild() && results != null && results.getXIssues() != null && !results.getXIssues().isEmpty()) {
            log.error(ERROR_BREAK_MSG);
            exit(ExitCode.BUILD_INTERRUPTED);
        }
    } catch (MachinaException | CheckmarxException e) {
        log.error("Error occurred while processing results file", e);
        exit(3);
    }
}
Also used : ScanResults(com.checkmarx.sdk.dto.ScanResults) MachinaException(com.checkmarx.flow.exception.MachinaException) CheckmarxException(com.checkmarx.sdk.exception.CheckmarxException)

Example 37 with ScanResults

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

the class OsaScannerService method cxOsaParseResults.

public void cxOsaParseResults(ScanRequest request, File file, File libs) throws ExitThrowable {
    try {
        List<Filter> simpleFilters = Optional.ofNullable(request).map(ScanRequest::getFilter).map(FilterConfiguration::getSastFilters).map(EngineFilterConfiguration::getSimpleFilters).orElse(null);
        ScanResults results = cxService.getOsaReportContent(file, libs, simpleFilters);
        resultsService.processResults(request, results, scanDetails);
        if (flowProperties.isBreakBuild() && results != null && results.getXIssues() != null && !results.getXIssues().isEmpty()) {
            log.error(ERROR_BREAK_MSG);
            exit(ExitCode.BUILD_INTERRUPTED);
        }
    } catch (MachinaException | CheckmarxException e) {
        log.error("Error occurred while processing results file(s)", e);
        exit(3);
    }
}
Also used : Filter(com.checkmarx.sdk.dto.sast.Filter) ScanResults(com.checkmarx.sdk.dto.ScanResults) MachinaException(com.checkmarx.flow.exception.MachinaException) CheckmarxException(com.checkmarx.sdk.exception.CheckmarxException) EngineFilterConfiguration(com.checkmarx.sdk.dto.filtering.EngineFilterConfiguration) FilterConfiguration(com.checkmarx.sdk.dto.filtering.FilterConfiguration)

Example 38 with ScanResults

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

the class ResultsService method publishCombinedResults.

@Async("scanRequest")
public CompletableFuture<ScanResults> publishCombinedResults(ScanRequest scanRequest, ScanResults scanResults) {
    try {
        CompletableFuture<ScanResults> future = new CompletableFuture<>();
        if (scanResults.getProjectId() != null) {
            Integer projectId = Integer.parseInt(scanResults.getProjectId());
            if (projectId != UNKNOWN_INT) {
                logGetResultsJsonLogger(scanRequest, scanResults.getSastScanId(), scanResults);
                sendEmailNotification(scanRequest, scanResults);
                processResults(scanRequest, scanResults, new ScanDetails(projectId, scanResults.getSastScanId(), null));
                logScanDetails(scanRequest, projectId, scanResults);
            } else {
                processResults(scanRequest, scanResults, new ScanDetails(null, scanResults.getSastScanId(), null));
            }
        } else {
            processResults(scanRequest, scanResults, new ScanDetails(null, scanResults.getSastScanId(), null));
        }
        future.complete(scanResults);
        log.info("Finished processing the request");
        return future;
    } catch (Exception e) {
        log.error("Error occurred while processing results.", e);
        CompletableFuture<ScanResults> x = new CompletableFuture<>();
        x.completeExceptionally(e);
        return x;
    }
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) ScanResults(com.checkmarx.sdk.dto.ScanResults) ScanDetails(com.checkmarx.flow.dto.ScanDetails) InvalidCredentialsException(com.checkmarx.flow.exception.InvalidCredentialsException) CheckmarxException(com.checkmarx.sdk.exception.CheckmarxException) RestClientException(com.atlassian.jira.rest.client.api.RestClientException) JiraClientException(com.checkmarx.flow.exception.JiraClientException) JiraClientRunTimeException(com.checkmarx.flow.exception.JiraClientRunTimeException) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) MachinaRuntimeException(com.checkmarx.flow.exception.MachinaRuntimeException) MachinaException(com.checkmarx.flow.exception.MachinaException) Async(org.springframework.scheduling.annotation.Async)

Example 39 with ScanResults

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

the class GitHubCommentsASTSteps method getASTResults.

@And("doing get results operation on scan with {int} {int} {int} {int} results")
public void getASTResults(int high, int medium, int low, int info) throws InterruptedException {
    try {
        if (scannerType.equalsIgnoreCase(AST)) {
            scanResultsToInject = createFakeASTScanResults(high, medium, low);
            addFlowSummaryToResults(high, medium, low, info);
        }
        if (scannerType.equalsIgnoreCase(AST_SCA)) {
            scanResultsToInject = createFakeSCAScanResults(high, medium, low);
            ScanResults astScanResults = createFakeASTScanResults(high, medium, low);
            scanResultsToInject.setAstResults(astScanResults.getAstResults());
            addFlowSummaryToResults(high * 2, medium * 2, low * 2, info * 2);
        }
        ScanRequest scanRequest = createScanRequest();
        CompletableFuture<ScanResults> task = resultsService.processScanResultsAsync(scanRequest, PROJECT_ID, SCAN_ID, null, null);
        task.get(1, TimeUnit.MINUTES);
    } catch (MachinaException | ExecutionException | TimeoutException e) {
        String message = "Error processing scan results.";
        log.error(message, e);
        Assert.fail(message);
    }
}
Also used : ScanRequest(com.checkmarx.flow.dto.ScanRequest) ScanResults(com.checkmarx.sdk.dto.ScanResults) MachinaException(com.checkmarx.flow.exception.MachinaException) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException) And(io.cucumber.java.en.And)

Example 40 with ScanResults

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

the class CommentScriptSteps method setMockers.

@Before("@ConfigureSastComment")
public void setMockers() throws CheckmarxException {
    when(cxClientMock.getScanIdOfExistingScanIfExists(anyInt())).thenReturn(-1);
    when(cxClientMock.createScan(any(), anyString())).thenAnswer(invocation -> {
        commentMessageFromRequest = invocation.getArgument(1);
        return null;
    });
    when(cxClientMock.getReportContentByScanId(nullable(Integer.class), any())).thenReturn(new ScanResults());
    when(sastScanner.getScannerClient()).thenReturn(cxClientMock);
    when(sastScanner.getScanRequestConverter()).thenReturn(scanRequestConverterMock);
    when(sastScanner.getScanComment(any())).thenCallRealMethod();
    when(sastScanner.getCxPropertiesBase()).thenReturn(cxProperties);
    when(sastScanner.isEnabled()).thenReturn(true);
    when(sastScanner.scan(any())).thenCallRealMethod();
    CxScanParams cxScanParams = new CxScanParams();
    cxScanParams.setProjectId(1);
    when(scanRequestConverterMock.toScanParams(any())).thenReturn(cxScanParams);
    cxProperties.setProjectScript(EMPTY_STRING);
    flowProperties.setBugTracker(BugTracker.Type.NONE.toString());
    commentMessageFromRequest = EMPTY_STRING;
    branchName = EMPTY_STRING;
}
Also used : CxScanParams(com.checkmarx.sdk.dto.cx.CxScanParams) ScanResults(com.checkmarx.sdk.dto.ScanResults) Before(io.cucumber.java.Before)

Aggregations

ScanResults (com.checkmarx.sdk.dto.ScanResults)58 MachinaException (com.checkmarx.flow.exception.MachinaException)17 ScanRequest (com.checkmarx.flow.dto.ScanRequest)16 CheckmarxException (com.checkmarx.sdk.exception.CheckmarxException)14 When (io.cucumber.java.en.When)9 MachinaRuntimeException (com.checkmarx.flow.exception.MachinaRuntimeException)6 CxScanSummary (com.checkmarx.sdk.dto.cx.CxScanSummary)6 FilterConfiguration (com.checkmarx.sdk.dto.filtering.FilterConfiguration)6 ExecutionException (java.util.concurrent.ExecutionException)5 TimeoutException (java.util.concurrent.TimeoutException)5 BugTracker (com.checkmarx.flow.dto.BugTracker)4 ScanParams (com.checkmarx.sdk.dto.ast.ScanParams)4 Filter (com.checkmarx.sdk.dto.sast.Filter)4 Test (org.junit.Test)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 JiraClientException (com.checkmarx.flow.exception.JiraClientException)3 CxScanParams (com.checkmarx.sdk.dto.cx.CxScanParams)3 Finding (com.checkmarx.sdk.dto.sca.report.Finding)3 Package (com.checkmarx.sdk.dto.sca.report.Package)3 IOException (java.io.IOException)3