diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3ba325e2..e4b72b4d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,6 +21,5 @@ jobs: CX_CLIENT_SECRET: ${{ secrets.CX_CLIENT_SECRET}} CX_BASE_URI: ${{ secrets.CX_BASE_URI }} CX_TENANT: ${{ secrets.CX_TENANT }} - CX_SCANID: ${{ secrets.SCANID }} CX_APIKEY: ${{ secrets.CX_APIKEY }} run: npm test \ No newline at end of file diff --git a/checkmarx-ast-cli.version b/checkmarx-ast-cli.version index 2ca0cc30..542a214a 100644 --- a/checkmarx-ast-cli.version +++ b/checkmarx-ast-cli.version @@ -1 +1 @@ -2.0.60 +2.0.63 diff --git a/jest.config.js b/jest.config.js index 1b6db32f..8d09a644 100644 --- a/jest.config.js +++ b/jest.config.js @@ -45,9 +45,9 @@ module.exports = { coverageThreshold: { "global": { "branches": 70, - "functions": 90, - "lines": 90, - "statements": 90 + "functions": 80, + "lines": 80, + "statements": 80 } }, coveragePathIgnorePatterns: ['/node_modules/', '\\.json$', '/__tests__/', '/stories/', '/\\.storybook/'], diff --git a/package.json b/package.json index bfce0552..b65e4b79 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "postbuild": "copyfiles -u 1 src/main/wrapper/resources/cx* dist/;copyfiles -u 1 src/tests/data/* dist/;", "lint": "eslint . --ext .ts", "lint-and-fix": "eslint . --ext .ts --fix", - "test": "copyfiles -u 1 src/tests/data/* dist/; tsc && jest --runInBand --coverage" + "test": "copyfiles -u 1 src/tests/data/* dist/; tsc && jest" }, "repository": "https://github.com/CheckmarxDev/ast-cli-javascript-wrapper.git", "author": "Jay Nanduri", diff --git a/src/main/wrapper/CxWrapper.ts b/src/main/wrapper/CxWrapper.ts index b6cb84ad..7abb7794 100644 --- a/src/main/wrapper/CxWrapper.ts +++ b/src/main/wrapper/CxWrapper.ts @@ -237,8 +237,10 @@ export class CxWrapper { commands.push(...this.initializeCommands(true)); const exec = new ExecutionService(); const response = await exec.executeCommands(this.config.pathToExecutable, commands, CxConstants.BFL_TYPE); - const bflNodeIndex = this.getIndexOfBflNode(response.payload, resultNodes) - response.payload[0] = bflNodeIndex; + if (response) { + const bflNodeIndex = this.getIndexOfBflNode(response.payload, resultNodes) + response.payload[0] = bflNodeIndex; + } return response; } @@ -356,8 +358,12 @@ export class CxWrapper { } getIndexOfBflNode(bflNodes: CxBFL[], resultNodes: any[]): number { - const bflNodeNotFound = -1; + + if (!bflNodes) { + return bflNodeNotFound + } + for (const bflNode of bflNodes) { for (const resultNode of resultNodes) { diff --git a/src/main/wrapper/resources/cx-linux b/src/main/wrapper/resources/cx-linux index 575c54d0..17cea76d 100755 Binary files a/src/main/wrapper/resources/cx-linux and b/src/main/wrapper/resources/cx-linux differ diff --git a/src/main/wrapper/resources/cx-mac b/src/main/wrapper/resources/cx-mac index f20862e8..ace60e2f 100755 Binary files a/src/main/wrapper/resources/cx-mac and b/src/main/wrapper/resources/cx-mac differ diff --git a/src/main/wrapper/resources/cx.exe b/src/main/wrapper/resources/cx.exe index a6773345..e596b955 100755 Binary files a/src/main/wrapper/resources/cx.exe and b/src/main/wrapper/resources/cx.exe differ diff --git a/src/tests/BaseTest.ts b/src/tests/BaseTest.ts index 46fa0eb0..82c7e7c7 100644 --- a/src/tests/BaseTest.ts +++ b/src/tests/BaseTest.ts @@ -16,7 +16,6 @@ export class BaseTest { this.clientSecret = process.env["CX_CLIENT_SECRET"]; this.tenant = process.env["CX_TENANT"]; this.apiKey = process.env["CX_APIKEY"]; - this.scanId = process.env["CX_SCANID"]; this.additionalParameters = "--debug" if (process.env["PATH_TO_EXECUTABLE"] !== null && process.env["PATH_TO_EXECUTABLE"] !== undefined) { this.pathToExecutable = process.env["PATH_TO_EXECUTABLE"]; diff --git a/src/tests/PredicateTest.test.ts b/src/tests/PredicateTest.test.ts index daa6a5bf..002834bd 100644 --- a/src/tests/PredicateTest.test.ts +++ b/src/tests/PredicateTest.test.ts @@ -2,30 +2,36 @@ import {CxWrapper} from '../main/wrapper/CxWrapper'; import {CxCommandOutput} from "../main/wrapper/CxCommandOutput"; import {BaseTest} from "./BaseTest"; import CxResult from '../main/results/CxResult'; -import { CxConstants } from '../main/wrapper/CxConstants'; +import {CxConstants} from '../main/wrapper/CxConstants'; -describe("Triage cases",() => { +describe("Triage cases", () => { const cxScanConfig = new BaseTest(); - it('TriageShow Successful case', async () => { + it('Triage Successful case', async () => { const auth = new CxWrapper(cxScanConfig); - const scan = (await auth.scanShow(cxScanConfig.scanId)).payload.pop(); - const results = await auth.getResultsList(cxScanConfig.scanId) - const result: CxResult = results.payload.find(res => res.type == CxConstants.SAST) - const cxCommandOutput: CxCommandOutput = await auth.triageShow(scan.projectID, result.similarityId, result.type); - - expect(cxCommandOutput.exitCode).toEqual(0); - }) + const scanList: CxCommandOutput = await auth.scanList("statuses=Completed"); + let scan, output; + while (!output && scanList && scanList.payload && scanList.payload.length > 0) { + scan = scanList.payload.pop() + console.log("Triage Successful case - ScanId " + scan.id) + output = await auth.getResultsList(scan.id) + if (output.status == "Error in the json file.") { + output = undefined; + } + } - it('TriageUpdate Successful case', async () => { - const auth = new CxWrapper(cxScanConfig); - const scan = (await auth.scanShow(cxScanConfig.scanId)).payload.pop(); - const results = await auth.getResultsList(cxScanConfig.scanId) - const result: CxResult = results.payload.find(res => res.type == CxConstants.SAST) + const result: CxResult = output.payload.find(res => res.type == CxConstants.SAST) + + const cxShow: CxCommandOutput = await auth.triageShow(scan.projectID, result.similarityId, result.type); + + expect(cxShow.exitCode).toEqual(0); - const cxCommandOutput: CxCommandOutput = await auth.triageUpdate(scan.projectID, result.similarityId, result.type, CxConstants.STATE_CONFIRMED, "Edited via JavascriptWrapper", result.severity.toLowerCase() == "high" ? CxConstants.SEVERITY_MEDIUM : CxConstants.SEVERITY_HIGH); + const cxUpdate: CxCommandOutput = await + auth.triageUpdate(scan.projectID, result.similarityId, result.type, result.state, + "Edited via JavascriptWrapper", + result.severity.toLowerCase() == "high" ? CxConstants.SEVERITY_MEDIUM : CxConstants.SEVERITY_HIGH); - expect(cxCommandOutput.exitCode).toEqual(0); - }) + expect(cxUpdate.exitCode).toEqual(0); + }); }); \ No newline at end of file diff --git a/src/tests/ResultTest.test.ts b/src/tests/ResultTest.test.ts index b53261e4..98a9af86 100644 --- a/src/tests/ResultTest.test.ts +++ b/src/tests/ResultTest.test.ts @@ -2,36 +2,38 @@ import {CxWrapper} from '../main/wrapper/CxWrapper'; import {CxCommandOutput} from "../main/wrapper/CxCommandOutput"; import {BaseTest} from "./BaseTest"; import * as fs from "fs"; -import { CxConstants } from '../main/wrapper/CxConstants'; -import CxResult from '../main/results/CxResult'; describe("Results cases",() => { const cxScanConfig = new BaseTest(); it('Result Test Successful case', async () => { const auth = new CxWrapper(cxScanConfig); - const cxCommandOutput: CxCommandOutput = await auth.scanList(""); + const cxCommandOutput: CxCommandOutput = await auth.scanList("statuses=Completed"); const sampleId = cxCommandOutput.payload.pop().id; auth.getResults(sampleId,"json","jsonList", ".").then(() => { fileExists("./jsonList.json").then(file => expect(file).toBe(true)); - }); - }); it('Result List Successful case', async () => { const auth = new CxWrapper(cxScanConfig); - const cxCommandOutput: CxCommandOutput = await auth.scanList(""); - console.log(JSON.stringify(cxCommandOutput)); - const sampleId = cxCommandOutput.payload.pop().id; - const written = await auth.getResultsList(sampleId); - expect(written.status).toBeUndefined(); - expect(written.payload.length).toBeGreaterThanOrEqual(0); + const scanList: CxCommandOutput = await auth.scanList("statuses=Completed"); + let output; + while (!output && scanList && scanList.payload && scanList.payload.length > 0) { + const scanId = scanList.payload.pop().id; + console.log("Triage Successful case - ScanId " + scanId); + output = await auth.getResultsList(scanId); + if (output.status == "Error in the json file.") { + output = undefined; + } + } + expect(output.status).toBeUndefined(); + expect(output.payload.length).toBeGreaterThanOrEqual(0); }); it('Result summary html file generation successful case', async () => { const auth = new CxWrapper(cxScanConfig); - const cxCommandOutput: CxCommandOutput = await auth.scanList(""); + const cxCommandOutput: CxCommandOutput = await auth.scanList("statuses=Completed"); const sampleId = cxCommandOutput.payload.pop().id; await auth.getResults(sampleId,"summaryHTML","test", "."); const file = await fileExists("./test.html"); @@ -40,7 +42,7 @@ describe("Results cases",() => { it('Result summary html string successful case', async () => { const auth = new CxWrapper(cxScanConfig); - const cxCommandOutput: CxCommandOutput = await auth.scanList(""); + const cxCommandOutput: CxCommandOutput = await auth.scanList("statuses=Completed"); const sampleId = cxCommandOutput.payload.pop().id; const written = await auth.getResultsSummary(sampleId); expect(written.payload.length).toBeGreaterThan(0); @@ -51,18 +53,6 @@ describe("Results cases",() => { const cxCommandOutput: CxCommandOutput = await auth.codeBashingList("79","PHP","Reflected XSS All Clients"); expect(cxCommandOutput.payload.length).toBeGreaterThan(0); }); - - it('Result bfl successful case', async () => { - const auth = new CxWrapper(cxScanConfig); - console.log("ScanID : " + cxScanConfig.scanId) - const results = await auth.getResultsList(cxScanConfig.scanId) - const result: CxResult = results.payload.find(res => res.type == CxConstants.SAST) - const data = result.data - const queryId = data.queryId - console.log("QueryID :" + result.data.queryId) - const cxCommandOutput: CxCommandOutput = await auth.getResultsBfl(cxScanConfig.scanId, queryId, data.nodes); - expect(cxCommandOutput.payload.length).toBeGreaterThanOrEqual(-1); - }); }); const fileExists = (file:string) => {