Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion checkmarx-ast-cli.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.3.19
2.3.19-RPDevX-EngineListAPITask
24 changes: 24 additions & 0 deletions src/main/engine/CxEngineListAPI.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}

6 changes: 6 additions & 0 deletions src/main/wrapper/CxConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down
13 changes: 13 additions & 0 deletions src/main/wrapper/CxWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<CxCommandOutput> {
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<CxCommandOutput> {
const commands: string[] = [CxConstants.CMD_SCAN, CxConstants.SUB_CMD_CREATE];
commands.push(...this.initializeCommands(false));
Expand Down
5 changes: 5 additions & 0 deletions src/main/wrapper/ExecutionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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];
Expand Down
4 changes: 2 additions & 2 deletions src/main/wrapper/resources/cx-linux
Git LFS file not shown
4 changes: 2 additions & 2 deletions src/main/wrapper/resources/cx-mac
Git LFS file not shown
4 changes: 2 additions & 2 deletions src/main/wrapper/resources/cx.exe
Git LFS file not shown
43 changes: 43 additions & 0 deletions src/tests/EngineTest.test.ts
Original file line number Diff line number Diff line change
@@ -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 engine 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 engine 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);
})
});