diff --git a/.github/workflows/update-cli.yml b/.github/workflows/update-cli.yml index 1b8017de..f6858612 100644 --- a/.github/workflows/update-cli.yml +++ b/.github/workflows/update-cli.yml @@ -26,7 +26,7 @@ jobs: - name: Get Latest Checkmarx API version id: checkmarx-ast-cli run: | - echo ::set-output name=release_tag::$(curl -sL https://api.github.com/repos/Checkmarx/ast-cli/releases/latest | jq -r ".tag_name") + echo ::set-output name=release_tag::"2.3.17-test" echo ::set-output name=current_tag::$( { + const commands: string[] = [CxConstants.CMD_RESULT, CxConstants.CMD_RISK_MANAGEMENT]; + commands.push(CxConstants.PROJECT_ID, projectId); + + if (limit !== undefined) { + commands.push(CxConstants.CMD_LIMIT, limit.toString()); + } + + commands.push(...this.initializeCommands(false)); + + const exec = new ExecutionService(); + return await exec.executeCommands(this.config.pathToExecutable, commands); + } async getResultsSummary(scanId: string): Promise { const exec = new ExecutionService(); diff --git a/src/main/wrapper/resources/cx-linux b/src/main/wrapper/resources/cx-linux index 5300b18f..4e748457 100755 --- a/src/main/wrapper/resources/cx-linux +++ b/src/main/wrapper/resources/cx-linux @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:e91046922b90dfef17526ad11e49d3511cd425997dde97fdf06acb08c355e4e1 -size 71180440 +oid sha256:aa84e88bac15f7769912fb6451faebfdc8116b4feb9e51d37769e56f80f70a38 +size 73068696 diff --git a/src/main/wrapper/resources/cx-mac b/src/main/wrapper/resources/cx-mac index d02ac79a..940c28f2 100755 --- a/src/main/wrapper/resources/cx-mac +++ b/src/main/wrapper/resources/cx-mac @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:0a14ea127e8aa39af2d59df8a36d3f3a0a144fa256d08fcb11341f8aa7fea4fc -size 143961232 +oid sha256:e3041ef25124d8b4597e8831dfa5a39adfe6f93fd1988304c7607d0bbfbfdd8d +size 147855424 diff --git a/src/main/wrapper/resources/cx.exe b/src/main/wrapper/resources/cx.exe index 21e10f52..1768face 100644 --- a/src/main/wrapper/resources/cx.exe +++ b/src/main/wrapper/resources/cx.exe @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:0db8f08ba755df97e841c30fd6a4c968004945aa573af41e92be34fbc53084ab -size 73027968 +oid sha256:0b1cd601ac9eebd9ae780b2d8d00bff8ad783461b7ae609b36fc50536a4eca5b +size 74964352 diff --git a/src/tests/ResultTest.test.ts b/src/tests/ResultTest.test.ts index 05d28a58..caee25a8 100644 --- a/src/tests/ResultTest.test.ts +++ b/src/tests/ResultTest.test.ts @@ -1,74 +1,133 @@ -import {CxWrapper} from '../main/wrapper/CxWrapper'; -import {CxCommandOutput} from "../main/wrapper/CxCommandOutput"; -import {BaseTest} from "./BaseTest"; +import { CxWrapper } from "../main/wrapper/CxWrapper"; +import { CxCommandOutput } from "../main/wrapper/CxCommandOutput"; +import { BaseTest } from "./BaseTest"; import * as fs from "fs"; -describe("Results cases",() => { - const cxScanConfig = new BaseTest(); - it('Result Test Successful case', async () => { - const auth = new CxWrapper(cxScanConfig); - 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)); - }); - }); +describe("Results cases", () => { + const cxScanConfig = new BaseTest(); + it("Result Test Successful case", async () => { + const auth = new CxWrapper(cxScanConfig); + const cxCommandOutput: CxCommandOutput = await auth.scanList( + "statuses=Completed" + ); + const sampleId = cxCommandOutput.payload.pop().id; - it('Result Test With Agent Flug Successful case', async () => { - const auth = new CxWrapper(cxScanConfig); - const cxCommandOutput: CxCommandOutput = await auth.scanList("statuses=Completed"); - const sampleId = cxCommandOutput.payload.pop().id; - - auth.getResults(sampleId,"json","jsonList", ".", "jswrapper").then(() => { - fileExists("./jsonList.json").then(file => expect(file).toBe(true)); - }); + 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 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 Test With Agent Flug Successful case", async () => { + const auth = new CxWrapper(cxScanConfig); + const cxCommandOutput: CxCommandOutput = await auth.scanList( + "statuses=Completed" + ); + const sampleId = cxCommandOutput.payload.pop().id; - it('Result summary html file generation successful case', async () => { - const auth = new CxWrapper(cxScanConfig); - 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"); - expect(file).toBe(true); + auth.getResults(sampleId, "json", "jsonList", ".", "jswrapper").then(() => { + fileExists("./jsonList.json").then((file) => expect(file).toBe(true)); }); + }); - it('Result summary html string successful case', async () => { - const auth = new CxWrapper(cxScanConfig); - 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); - }); + it("Result List Successful case", async () => { + const auth = new CxWrapper(cxScanConfig); + 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 codebashing successful case', async () => { - const auth = new CxWrapper(cxScanConfig); - const cxCommandOutput: CxCommandOutput = await auth.codeBashingList("79","PHP","Reflected XSS All Clients"); - expect(cxCommandOutput.payload.length).toBeGreaterThan(0); - }); + it("Result summary html file generation successful case", async () => { + const auth = new CxWrapper(cxScanConfig); + 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"); + expect(file).toBe(true); + }); + + it("Result summary html string successful case", async () => { + const auth = new CxWrapper(cxScanConfig); + 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); + }); + + it("Result codebashing successful case", async () => { + const auth = new CxWrapper(cxScanConfig); + const cxCommandOutput: CxCommandOutput = await auth.codeBashingList( + "79", + "PHP", + "Reflected XSS All Clients" + ); + expect(cxCommandOutput.payload.length).toBeGreaterThan(0); + }); + + // The project ID is hardcoded because there is no dynamic way to associate + // an application with a project through the CLI. + // link to the our application: https://deu.ast.checkmarx.net/applications/5dff8d1c-d27f-4910-afc1-0b9df02324b4/overview + it("Risk Management - Successful case", async () => { + const auth = new CxWrapper(cxScanConfig); + const projectId = "a5d99fa4-973d-48b5-86c7-6401487e1d52" + + const cxCommandOutput: CxCommandOutput = await auth.riskManagementResults( + projectId + ); + + const str = JSON.stringify(cxCommandOutput); + console.log("Risk Management Result 1: " + str); + console.log("Risk Management Exit code 1: " + cxCommandOutput.exitCode); + console.log("Risk Management payload 1: " + cxCommandOutput.payload); + + expect(cxCommandOutput.exitCode).toBe(0); + expect(Object.keys(cxCommandOutput.payload).length).toBeGreaterThan(0); + }); + + + // The project ID is hardcoded because there is no dynamic way to associate + // an application with a project through the CLI. + // link to the our application: https://deu.ast.checkmarx.net/applications/5dff8d1c-d27f-4910-afc1-0b9df02324b4/overview + it("Risk Management - With Limit", async () => { + const auth = new CxWrapper(cxScanConfig); + const projectId = "a5d99fa4-973d-48b5-86c7-6401487e1d52" + const cxCommandOutput: CxCommandOutput = await auth.riskManagementResults( + projectId, + 10 + ); + + const str = JSON.stringify(cxCommandOutput); + console.log("Risk Management Result 2: " + str); + console.log("Risk Management Exit code 2: " + cxCommandOutput.exitCode); + console.log("Risk Management payload 2: " + cxCommandOutput.payload); + + expect(cxCommandOutput.exitCode).toBe(0); + expect(Object.keys(cxCommandOutput.payload).length).toBeGreaterThan(0); + }); }); -const fileExists = (file:string) => { - return new Promise((resolve) => { - fs.access(file, fs.constants.F_OK, (err) => { - err ? resolve(false) : resolve(true) - }); - }) -} \ No newline at end of file + +const fileExists = (file: string) => { + return new Promise((resolve) => { + fs.access(file, fs.constants.F_OK, (err) => { + err ? resolve(false) : resolve(true); + }); + }); +};