Search in sources :

Example 1 with JsonLoggerTestUtils

use of com.checkmarx.flow.cucumber.common.JsonLoggerTestUtils in project cx-flow by checkmarx-ltd.

the class ScanSteps method verifyJsonLoggerAndScanStatus.

@And("output json logger will have Scan request {string} and scan status will be {string}")
public void verifyJsonLoggerAndScanStatus(String repoUrl, String scanStatus) {
    JsonLoggerTestUtils testUtils = new JsonLoggerTestUtils();
    JsonNode node;
    try {
        // AnalyticsReport report = testUtils.getReportNode(ScanReport.OPERATION, ScanReport.class);
        node = testUtils.getReportNode(ScanReport.OPERATION);
        if (this.repoType.equals(ScanRequest.Repository.GITHUB)) {
            assertEquals((ScanRequest.Repository.GITHUB.toString()), node.get("repoType").textValue());
            assertEquals(this.branch, node.get("branch").textValue());
            assertEquals(repoUrl, AesEncryptionUtils.decrypt(node.get("repoUrl").textValue().trim()));
        } else {
            assertEquals("NA", node.get("repoType").textValue());
            if (!errorExpected) {
                assertEquals(fileRepo.getPath(), AesEncryptionUtils.decrypt(node.get("repoUrl").textValue().trim()));
            }
        }
        assertTrue(node.get("scanStatus").get("message").textValue().startsWith(scanStatus));
        assertEquals(cxProperties.getIncremental() ? "Inc" : "Full", node.get("scanType").textValue());
        if (!errorExpected) {
            assertNotEquals("NA", node.get("scanId").textValue());
        }
    } catch (IOException | CheckmarxException e) {
        fail(e.getMessage());
    } finally {
        try {
            testUtils.clearLogContents();
            errorExpected = false;
        } catch (Exception e) {
            fail(e.getMessage());
        }
    }
}
Also used : CheckmarxException(com.checkmarx.sdk.exception.CheckmarxException) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonLoggerTestUtils(com.checkmarx.flow.cucumber.common.JsonLoggerTestUtils) CheckmarxException(com.checkmarx.sdk.exception.CheckmarxException) And(io.cucumber.java.en.And)

Example 2 with JsonLoggerTestUtils

use of com.checkmarx.flow.cucumber.common.JsonLoggerTestUtils in project cx-flow by checkmarx-ltd.

the class SCARemoteRepoScanSteps method getReportObject.

private ScanReport getReportObject() throws CheckmarxException, JsonProcessingException {
    JsonLoggerTestUtils utils = new JsonLoggerTestUtils();
    String lastLine = utils.getLastLine();
    ObjectMapper objectMapper = new ObjectMapper();
    JsonNode jsonNode = objectMapper.readTree(lastLine).get(ScanReport.OPERATION);
    if (jsonNode != null) {
        return (ScanReport) utils.getAnalyticsReport(ScanReport.class, objectMapper, jsonNode);
    } else {
        return null;
    }
}
Also used : ScanReport(com.checkmarx.flow.dto.report.ScanReport) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonLoggerTestUtils(com.checkmarx.flow.cucumber.common.JsonLoggerTestUtils) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

JsonLoggerTestUtils (com.checkmarx.flow.cucumber.common.JsonLoggerTestUtils)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ScanReport (com.checkmarx.flow.dto.report.ScanReport)1 CheckmarxException (com.checkmarx.sdk.exception.CheckmarxException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 And (io.cucumber.java.en.And)1