Search in sources :

Example 11 with CxScanParams

use of com.checkmarx.sdk.dto.cx.CxScanParams 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)

Example 12 with CxScanParams

use of com.checkmarx.sdk.dto.cx.CxScanParams in project checkmarx-spring-boot-java-sdk by checkmarx-ltd.

the class GoScanner method extractTeamId.

private String extractTeamId(String teamPath, String clientSecret) throws CheckmarxException {
    String[] buTokens = teamPath.split(Pattern.quote("\\"));
    OdNavigationTree navTree = getNavigationTree(clientSecret);
    LinkedHashMap<String, ArrayList<Object>> navTreeData = (LinkedHashMap) navTree.getAdditionalProperties().get("data");
    ArrayList<LinkedHashMap<String, LinkedHashMap<String, Object>>> tree = (ArrayList) navTreeData.get("tree");
    int i = 1;
    String token = buTokens[i++];
    for (LinkedHashMap<String, LinkedHashMap<String, Object>> item : tree) {
        Object o = item.get("id");
        Integer id = (Integer) o;
        o = item.get("title");
        String title = (String) o;
        title = title.trim();
        o = item.get("children");
        ArrayList<Object> children = (ArrayList<Object>) o;
        if (title.equals(token)) {
            if (i == buTokens.length) {
                CxScanParams csp = getScanProbeByTeam(id.toString());
                csp.setTeamName(teamPath);
                return id.toString();
            } else {
                return searchTreeChildren(teamPath, buTokens, i, children);
            }
        }
    }
    return UNKNOWN;
}
Also used : CxScanParams(com.checkmarx.sdk.dto.cx.CxScanParams) JSONObject(org.json.JSONObject)

Example 13 with CxScanParams

use of com.checkmarx.sdk.dto.cx.CxScanParams in project checkmarx-spring-boot-java-sdk by checkmarx-ltd.

the class CxServiceIT method createScan.

@Test
public void createScan() {
    log.info("Creating scan");
    login();
    try {
        CxScanParams params = new CxScanParams().withSourceType(CxScanParams.Type.GIT).withGitUrl("https://github.com/Custodela/Riches.git").withBranch("refs/heads/master").withProjectName("CxSBSDK-IT");
        // .withProjectName("Riches");
        // String teamId = service.getTeamId(properties.getTeam());
        Integer id = service.createScan(params, "Automated Comment");
        assertNotNull(id);
        assertTrue(id > 0);
    } catch (CheckmarxException e) {
        fail("Unexpected CheckmarxException");
    }
}
Also used : CxScanParams(com.checkmarx.sdk.dto.cx.CxScanParams) CheckmarxException(com.checkmarx.sdk.exception.CheckmarxException) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 14 with CxScanParams

use of com.checkmarx.sdk.dto.cx.CxScanParams in project checkmarx-spring-boot-java-sdk by checkmarx-ltd.

the class CxRepoFileHelper method getScaClonedRepoFolderPath.

public String getScaClonedRepoFolderPath(String repoUrlWithAuth, List<String> excludeFiles, String branch) throws CheckmarxException {
    CxScanParams cxScanParams = prepareScanParamsToCloneRepo(repoUrlWithAuth, excludeFiles, branch);
    File pathFile = null;
    try {
        pathFile = gitCloneAndRunPostCloneScript(cxScanParams);
    } catch (GitAPIException | URISyntaxException e) {
        log.error(ExceptionUtils.getRootCauseMessage(e));
        throw new CheckmarxException("Unable to clone Git Url.");
    }
    return pathFile.getAbsolutePath();
}
Also used : CxScanParams(com.checkmarx.sdk.dto.cx.CxScanParams) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) CheckmarxException(com.checkmarx.sdk.exception.CheckmarxException) URISyntaxException(java.net.URISyntaxException) File(java.io.File)

Aggregations

CxScanParams (com.checkmarx.sdk.dto.cx.CxScanParams)14 CheckmarxException (com.checkmarx.sdk.exception.CheckmarxException)4 Test (org.junit.Test)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 ScanResults (com.checkmarx.sdk.dto.ScanResults)3 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)3 Ignore (org.junit.Ignore)3 GitHubRepoUnavailableException (com.checkmarx.flow.exception.GitHubRepoUnavailableException)2 MachinaException (com.checkmarx.flow.exception.MachinaException)2 FilterConfiguration (com.checkmarx.sdk.dto.filtering.FilterConfiguration)2 Filter (com.checkmarx.sdk.dto.sast.Filter)2 JSONObject (org.json.JSONObject)2 ScanReport (com.checkmarx.flow.dto.report.ScanReport)1 MachinaRuntimeException (com.checkmarx.flow.exception.MachinaRuntimeException)1 Before (io.cucumber.java.Before)1 File (java.io.File)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 CompletableFuture (java.util.concurrent.CompletableFuture)1