Skip to content

Commit b4c3b11

Browse files
Implementation of engine-task
1 parent 83a9bb1 commit b4c3b11

File tree

6 files changed

+92
-1
lines changed

6 files changed

+92
-1
lines changed

checkmarx-ast-cli.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.3.19
1+
2.3.19-RPDevX-EngineListAPI

src/main/engine/CxEngineListAPI.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export default class CxEngineListAPI {
2+
engineId: string;
3+
engineName: string;
4+
engineApiName: string;
5+
engineApiURL: string;
6+
engineDescription: string;
7+
8+
static parseEngineApis(resultObject: any): CxEngineListAPI[] {
9+
let engineApiList: CxEngineListAPI[] = [];
10+
if (resultObject instanceof Array) {
11+
engineApiList = resultObject.map((member: any) => {
12+
const engines = new CxEngineListAPI();
13+
engines.engineId = member.EngineId;
14+
engines.engineApiName = member.EngineName;
15+
engines.engineApiName = member.ApiName;
16+
engines.engineApiURL = member.ApiURL;
17+
engines.engineDescription = member.Description;
18+
return engines;
19+
});
20+
}
21+
return engineApiList;
22+
}
23+
}
24+

src/main/wrapper/CxConstants.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ export enum CxConstants {
2929
SUB_CMD_VALIDATE = "validate",
3030
CMD_PROJECT = "project",
3131
SUB_CMD_BRANCHES = "branches",
32+
CMD_ENGINES = "engines",
3233
CMD_SCAN = "scan",
34+
SUB_CMD_LISTAPI = "list-api",
3335
SUB_CMD_SHOW = "show",
3436
SUB_CMD_CANCEL = "cancel",
3537
SUB_CMD_LIST = "list",
@@ -61,6 +63,9 @@ export enum CxConstants {
6163
CMD_SAST_CHAT_RESULT_RESULTS_FILE = "--scan-results-file",
6264
CMD_SAST_CHAT_RESULT_SOURCE_FILE = "--source-dir",
6365
SCAN_INFO_FORMAT = "--scan-info-format",
66+
ENGINE_NAME = "--engine-name",
67+
ENGINE_FORMAT_JSON = "json",
68+
ENGINE_OUTPUT_FORMAT = "--output-format",
6469
FORMAT = "--format",
6570
FORMAT_JSON = "json",
6671
FORMAT_HTML = "html",
@@ -85,6 +90,7 @@ export enum CxConstants {
8590
FILE_SOURCES = "--file",
8691
ADDITONAL_PARAMS = "--additional-params",
8792
ENGINE = "--engine",
93+
ENGINE_TYPE = "CxEngines",
8894
SCAN_TYPE = "CxScan",
8995
SCAN_ASCA = "CxAsca",
9096
PROJECT_TYPE = "CxProject",

src/main/wrapper/CxWrapper.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,19 @@ export class CxWrapper {
101101
return await exec.executeCommands(this.config.pathToExecutable, commands);
102102
}
103103

104+
async enginesApiList(engineName:string | null = "",engineOutputFormat:string | null = "json"): Promise<CxCommandOutput> {
105+
const commands: string[] = [CxConstants.CMD_ENGINES, CxConstants.SUB_CMD_LISTAPI];
106+
commands.push(...this.initializeCommands(false));
107+
if(engineName != "") {
108+
commands.push(CxConstants.ENGINE_NAME);
109+
commands.push(engineName)
110+
}
111+
commands.push(CxConstants.ENGINE_OUTPUT_FORMAT);
112+
commands.push(engineOutputFormat);
113+
const exec = new ExecutionService();
114+
return await exec.executeCommands(this.config.pathToExecutable, commands);
115+
}
116+
104117
async scanCreate(params: ParamTypeMap): Promise<CxCommandOutput> {
105118
const commands: string[] = [CxConstants.CMD_SCAN, CxConstants.SUB_CMD_CREATE];
106119
commands.push(...this.initializeCommands(false));

src/main/wrapper/ExecutionService.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import CxScaRealTime from "../scaRealtime/CxScaRealTime";
2323
import CxChat from "../chat/CxChat";
2424
import CxMask from "../mask/CxMask";
2525
import CxAsca from "../asca/CxAsca";
26+
import CxEngineListAPI from "../engine/CxEngineListAPI";
2627

2728
let skipValue = false;
2829
const fileSourceFlag = "--file-source"
@@ -201,6 +202,10 @@ export class ExecutionService {
201202
const scans = CxScan.parseProject(resultObject);
202203
cxCommandOutput.payload = scans;
203204
break;
205+
case CxConstants.ENGINE_TYPE:
206+
const engines = CxEngineListAPI.parseEngineApis(resultObject);
207+
cxCommandOutput.payload = engines;
208+
break;
204209
case CxConstants.SCAN_ASCA:
205210
const asca = CxAsca.parseScan(resultObject);
206211
cxCommandOutput.payload = [asca];

src/tests/EngineTest.test.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { CxWrapper } from '../main/wrapper/CxWrapper';
2+
import { CxCommandOutput } from "../main/wrapper/CxCommandOutput";
3+
import { BaseTest } from "./BaseTest";
4+
5+
describe("EngineListAPI cases", () => {
6+
const cxEngineConfig = new BaseTest();
7+
it('EngineListAPI Successful case', async () => {
8+
const auth = new CxWrapper(cxEngineConfig);
9+
const cxCommandOutput: CxCommandOutput = await auth.enginesApiList();
10+
console.log(" Json object from engineAPIList successful case: " + JSON.stringify(cxCommandOutput));
11+
expect(cxCommandOutput.payload.length).toBeGreaterThan(1);
12+
expect(cxCommandOutput.exitCode).toBe(0);
13+
});
14+
15+
it('EngineListAPI Successful case with enegine name sast', async () => {
16+
const auth = new CxWrapper(cxEngineConfig);
17+
const engineName = 'sast';
18+
const cxCommandOutput: CxCommandOutput = await auth.enginesApiList(engineName);
19+
console.log(" Json object from engineAPIList successful case with enginename sast: " + JSON.stringify(cxCommandOutput));
20+
21+
expect(cxCommandOutput.payload[0].EngineName.toLowerCase()).toBe(engineName);
22+
expect(cxCommandOutput.exitCode).toBe(0);
23+
})
24+
25+
it('EngineListAPI Successful case with enegine name sca', async () => {
26+
const auth = new CxWrapper(cxEngineConfig);
27+
const engineName = 'sca';
28+
const cxCommandOutput: CxCommandOutput = await auth.enginesApiList(engineName);
29+
console.log(" Json object from engineAPIList successful case with enginename sast: " + JSON.stringify(cxCommandOutput));
30+
expect(cxCommandOutput.payload[0].EngineName.toLowerCase()).toBe(engineName);
31+
expect(cxCommandOutput.exitCode).toBe(0);
32+
})
33+
34+
it('EngineListAPI Failure case', async () => {
35+
const auth = new CxWrapper(cxEngineConfig);
36+
const engineName = 'fakeengine';
37+
const cxCommandOutput: CxCommandOutput = await auth.enginesApiList(engineName);
38+
console.log(" Json object from failure case: " + JSON.stringify(cxCommandOutput));
39+
console.log(" cxCommandOutput: " + cxCommandOutput);
40+
41+
expect(cxCommandOutput.payload.length).toBeLessThanOrEqual(0);
42+
})
43+
});

0 commit comments

Comments
 (0)