From b4c3b11d8ee07b67a5bee87fc0fbcf1080263c6c Mon Sep 17 00:00:00 2001 From: Rahul Pidde Date: Mon, 21 Apr 2025 15:03:36 +0530 Subject: [PATCH 1/4] Implementation of engine-task --- checkmarx-ast-cli.version | 2 +- src/main/engine/CxEngineListAPI.ts | 24 ++++++++++++++++ src/main/wrapper/CxConstants.ts | 6 ++++ src/main/wrapper/CxWrapper.ts | 13 +++++++++ src/main/wrapper/ExecutionService.ts | 5 ++++ src/tests/EngineTest.test.ts | 43 ++++++++++++++++++++++++++++ 6 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 src/main/engine/CxEngineListAPI.ts create mode 100644 src/tests/EngineTest.test.ts diff --git a/checkmarx-ast-cli.version b/checkmarx-ast-cli.version index d245ee86..1af314a8 100644 --- a/checkmarx-ast-cli.version +++ b/checkmarx-ast-cli.version @@ -1 +1 @@ -2.3.19 +2.3.19-RPDevX-EngineListAPI \ No newline at end of file diff --git a/src/main/engine/CxEngineListAPI.ts b/src/main/engine/CxEngineListAPI.ts new file mode 100644 index 00000000..5c3b2593 --- /dev/null +++ b/src/main/engine/CxEngineListAPI.ts @@ -0,0 +1,24 @@ +export default class CxEngineListAPI { + engineId: string; + engineName: string; + engineApiName: string; + engineApiURL: string; + engineDescription: string; + + static parseEngineApis(resultObject: any): CxEngineListAPI[] { + let engineApiList: CxEngineListAPI[] = []; + if (resultObject instanceof Array) { + engineApiList = resultObject.map((member: any) => { + const engines = new CxEngineListAPI(); + engines.engineId = member.EngineId; + engines.engineApiName = member.EngineName; + engines.engineApiName = member.ApiName; + engines.engineApiURL = member.ApiURL; + engines.engineDescription = member.Description; + return engines; + }); + } + return engineApiList; + } + } + \ No newline at end of file diff --git a/src/main/wrapper/CxConstants.ts b/src/main/wrapper/CxConstants.ts index 49d7643d..fe858dd6 100644 --- a/src/main/wrapper/CxConstants.ts +++ b/src/main/wrapper/CxConstants.ts @@ -29,7 +29,9 @@ export enum CxConstants { SUB_CMD_VALIDATE = "validate", CMD_PROJECT = "project", SUB_CMD_BRANCHES = "branches", + CMD_ENGINES = "engines", CMD_SCAN = "scan", + SUB_CMD_LISTAPI = "list-api", SUB_CMD_SHOW = "show", SUB_CMD_CANCEL = "cancel", SUB_CMD_LIST = "list", @@ -61,6 +63,9 @@ export enum CxConstants { CMD_SAST_CHAT_RESULT_RESULTS_FILE = "--scan-results-file", CMD_SAST_CHAT_RESULT_SOURCE_FILE = "--source-dir", SCAN_INFO_FORMAT = "--scan-info-format", + ENGINE_NAME = "--engine-name", + ENGINE_FORMAT_JSON = "json", + ENGINE_OUTPUT_FORMAT = "--output-format", FORMAT = "--format", FORMAT_JSON = "json", FORMAT_HTML = "html", @@ -85,6 +90,7 @@ export enum CxConstants { FILE_SOURCES = "--file", ADDITONAL_PARAMS = "--additional-params", ENGINE = "--engine", + ENGINE_TYPE = "CxEngines", SCAN_TYPE = "CxScan", SCAN_ASCA = "CxAsca", PROJECT_TYPE = "CxProject", diff --git a/src/main/wrapper/CxWrapper.ts b/src/main/wrapper/CxWrapper.ts index 228554ea..d296bbd8 100644 --- a/src/main/wrapper/CxWrapper.ts +++ b/src/main/wrapper/CxWrapper.ts @@ -101,6 +101,19 @@ export class CxWrapper { return await exec.executeCommands(this.config.pathToExecutable, commands); } + async enginesApiList(engineName:string | null = "",engineOutputFormat:string | null = "json"): Promise { + const commands: string[] = [CxConstants.CMD_ENGINES, CxConstants.SUB_CMD_LISTAPI]; + commands.push(...this.initializeCommands(false)); + if(engineName != "") { + commands.push(CxConstants.ENGINE_NAME); + commands.push(engineName) + } + commands.push(CxConstants.ENGINE_OUTPUT_FORMAT); + commands.push(engineOutputFormat); + const exec = new ExecutionService(); + return await exec.executeCommands(this.config.pathToExecutable, commands); + } + async scanCreate(params: ParamTypeMap): Promise { const commands: string[] = [CxConstants.CMD_SCAN, CxConstants.SUB_CMD_CREATE]; commands.push(...this.initializeCommands(false)); diff --git a/src/main/wrapper/ExecutionService.ts b/src/main/wrapper/ExecutionService.ts index 65443950..5d0a25f1 100644 --- a/src/main/wrapper/ExecutionService.ts +++ b/src/main/wrapper/ExecutionService.ts @@ -23,6 +23,7 @@ import CxScaRealTime from "../scaRealtime/CxScaRealTime"; import CxChat from "../chat/CxChat"; import CxMask from "../mask/CxMask"; import CxAsca from "../asca/CxAsca"; +import CxEngineListAPI from "../engine/CxEngineListAPI"; let skipValue = false; const fileSourceFlag = "--file-source" @@ -201,6 +202,10 @@ export class ExecutionService { const scans = CxScan.parseProject(resultObject); cxCommandOutput.payload = scans; break; + case CxConstants.ENGINE_TYPE: + const engines = CxEngineListAPI.parseEngineApis(resultObject); + cxCommandOutput.payload = engines; + break; case CxConstants.SCAN_ASCA: const asca = CxAsca.parseScan(resultObject); cxCommandOutput.payload = [asca]; diff --git a/src/tests/EngineTest.test.ts b/src/tests/EngineTest.test.ts new file mode 100644 index 00000000..b09e5a72 --- /dev/null +++ b/src/tests/EngineTest.test.ts @@ -0,0 +1,43 @@ +import { CxWrapper } from '../main/wrapper/CxWrapper'; +import { CxCommandOutput } from "../main/wrapper/CxCommandOutput"; +import { BaseTest } from "./BaseTest"; + +describe("EngineListAPI cases", () => { + const cxEngineConfig = new BaseTest(); + it('EngineListAPI Successful case', async () => { + const auth = new CxWrapper(cxEngineConfig); + const cxCommandOutput: CxCommandOutput = await auth.enginesApiList(); + console.log(" Json object from engineAPIList successful case: " + JSON.stringify(cxCommandOutput)); + expect(cxCommandOutput.payload.length).toBeGreaterThan(1); + expect(cxCommandOutput.exitCode).toBe(0); + }); + + it('EngineListAPI Successful case with enegine name sast', async () => { + const auth = new CxWrapper(cxEngineConfig); + const engineName = 'sast'; + const cxCommandOutput: CxCommandOutput = await auth.enginesApiList(engineName); + console.log(" Json object from engineAPIList successful case with enginename sast: " + JSON.stringify(cxCommandOutput)); + + expect(cxCommandOutput.payload[0].EngineName.toLowerCase()).toBe(engineName); + expect(cxCommandOutput.exitCode).toBe(0); + }) + + it('EngineListAPI Successful case with enegine name sca', async () => { + const auth = new CxWrapper(cxEngineConfig); + const engineName = 'sca'; + const cxCommandOutput: CxCommandOutput = await auth.enginesApiList(engineName); + console.log(" Json object from engineAPIList successful case with enginename sast: " + JSON.stringify(cxCommandOutput)); + expect(cxCommandOutput.payload[0].EngineName.toLowerCase()).toBe(engineName); + expect(cxCommandOutput.exitCode).toBe(0); + }) + + it('EngineListAPI Failure case', async () => { + const auth = new CxWrapper(cxEngineConfig); + const engineName = 'fakeengine'; + const cxCommandOutput: CxCommandOutput = await auth.enginesApiList(engineName); + console.log(" Json object from failure case: " + JSON.stringify(cxCommandOutput)); + console.log(" cxCommandOutput: " + cxCommandOutput); + + expect(cxCommandOutput.payload.length).toBeLessThanOrEqual(0); + }) +}); From fd501c986748220a2bb6a45ff17c7faeb0d6baa5 Mon Sep 17 00:00:00 2001 From: Rahul Pidde Date: Mon, 21 Apr 2025 15:20:42 +0530 Subject: [PATCH 2/4] changed message --- src/tests/EngineTest.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tests/EngineTest.test.ts b/src/tests/EngineTest.test.ts index b09e5a72..7b83dc01 100644 --- a/src/tests/EngineTest.test.ts +++ b/src/tests/EngineTest.test.ts @@ -12,7 +12,7 @@ describe("EngineListAPI cases", () => { expect(cxCommandOutput.exitCode).toBe(0); }); - it('EngineListAPI Successful case with enegine name sast', async () => { + it('EngineListAPI Successful case with engine name sast', async () => { const auth = new CxWrapper(cxEngineConfig); const engineName = 'sast'; const cxCommandOutput: CxCommandOutput = await auth.enginesApiList(engineName); @@ -22,7 +22,7 @@ describe("EngineListAPI cases", () => { expect(cxCommandOutput.exitCode).toBe(0); }) - it('EngineListAPI Successful case with enegine name sca', async () => { + it('EngineListAPI Successful case with engine name sca', async () => { const auth = new CxWrapper(cxEngineConfig); const engineName = 'sca'; const cxCommandOutput: CxCommandOutput = await auth.enginesApiList(engineName); From 81ba42a98db40fa455abcbe3ddfbe0c646fe23e1 Mon Sep 17 00:00:00 2001 From: Rahul Pidde Date: Mon, 21 Apr 2025 16:33:10 +0530 Subject: [PATCH 3/4] updated resource-cli --- src/main/wrapper/resources/cx-linux | 4 ++-- src/main/wrapper/resources/cx-mac | 4 ++-- src/main/wrapper/resources/cx.exe | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/wrapper/resources/cx-linux b/src/main/wrapper/resources/cx-linux index bde045cb..8b1ef5ff 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:9eae11d84cb766a5df14ce5e9d57013268f3d687484cf2a4d67595c419a4a762 -size 73937080 +oid sha256:e35790a4420836786fc37d96491679d664375293d8ceb8d36151e40855705ac7 +size 73146520 diff --git a/src/main/wrapper/resources/cx-mac b/src/main/wrapper/resources/cx-mac index 3b851457..c4d16ed0 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:68cb8baeb6eb68cff07440c2dd142b5a3cf53b2d12c4ca98dd01d0a95a4f9370 -size 148816000 +oid sha256:54fec010689ff000d1ecbec665b2f7eaf8ea1b3f0b9444763e3f7aa48e0529e5 +size 147994736 diff --git a/src/main/wrapper/resources/cx.exe b/src/main/wrapper/resources/cx.exe index ab3efe27..24ab8f8c 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:b073010a1e360028fcc2eee56d1a7376be36459a2ea1a27c0a516a227a334943 -size 75835264 +oid sha256:7722354f0b967c115ffabae9f8ee8b9b99f1baa128903ee69a2b554cc9c405f6 +size 75040128 From 2d59077a6d08fb3b809ee33f118bf018bbab2247 Mon Sep 17 00:00:00 2001 From: Rahul Pidde Date: Mon, 21 Apr 2025 23:40:35 +0530 Subject: [PATCH 4/4] updated cli version --- checkmarx-ast-cli.version | 2 +- src/main/wrapper/resources/cx-linux | 4 ++-- src/main/wrapper/resources/cx-mac | 4 ++-- src/main/wrapper/resources/cx.exe | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/checkmarx-ast-cli.version b/checkmarx-ast-cli.version index 1af314a8..9be9c46a 100644 --- a/checkmarx-ast-cli.version +++ b/checkmarx-ast-cli.version @@ -1 +1 @@ -2.3.19-RPDevX-EngineListAPI \ No newline at end of file +2.3.19-RPDevX-EngineListAPITask \ No newline at end of file diff --git a/src/main/wrapper/resources/cx-linux b/src/main/wrapper/resources/cx-linux index 8b1ef5ff..ecf4ae7d 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:e35790a4420836786fc37d96491679d664375293d8ceb8d36151e40855705ac7 -size 73146520 +oid sha256:ec9715167d853524954a1df707d22c4a94f2875325f564052035e9dc4992e19e +size 73949368 diff --git a/src/main/wrapper/resources/cx-mac b/src/main/wrapper/resources/cx-mac index c4d16ed0..b8008d9e 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:54fec010689ff000d1ecbec665b2f7eaf8ea1b3f0b9444763e3f7aa48e0529e5 -size 147994736 +oid sha256:7fc68888f83efe29dcc45bc467fc65646fdf37568cdc6679eef318393da2e31d +size 148833072 diff --git a/src/main/wrapper/resources/cx.exe b/src/main/wrapper/resources/cx.exe index 24ab8f8c..9bf49b54 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:7722354f0b967c115ffabae9f8ee8b9b99f1baa128903ee69a2b554cc9c405f6 -size 75040128 +oid sha256:2b178820caf818debc7c1ed3c1d9990c8b916ef2c1892022a0de658eb24e5105 +size 75847040