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
3 changes: 3 additions & 0 deletions src/main/wrapper/CxConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export enum CxConstants {
CMD_PROJECT = "project",
SUB_CMD_BRANCHES = "branches",
CMD_SCAN = "scan",
CMD_ENGINE="engine",
FLAG_ENGINE_NAME="--engine-name",
SUB_CMD_SHOW = "show",
SUB_CMD_CANCEL = "cancel",
SUB_CMD_LIST = "list",
Expand Down Expand Up @@ -62,6 +64,7 @@ export enum CxConstants {
CMD_SAST_CHAT_RESULT_SOURCE_FILE = "--source-dir",
SCAN_INFO_FORMAT = "--scan-info-format",
FORMAT = "--format",
OUTPUT_FORMAT="--output-format",
FORMAT_JSON = "json",
FORMAT_HTML = "html",
FORMAT_JSON_FILE = ".json",
Expand Down
51 changes: 51 additions & 0 deletions src/main/wrapper/CxWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,45 @@ export class CxWrapper {
return list;
}


initializeCommandsEngine(formatRequired: boolean): string[] {
const list: string[] = [];
if (this.config.clientId) {
list.push(CxConstants.CLIENT_ID);
list.push(this.config.clientId);
}
if (this.config.clientSecret) {
list.push(CxConstants.CLIENT_SECRET);
list.push(this.config.clientSecret);
}
if (this.config.apiKey) {
list.push(CxConstants.API_KEY);
list.push(this.config.apiKey);
}
if (this.config.baseUri) {
list.push(CxConstants.BASE_URI);
list.push(this.config.baseUri);
}
if (this.config.baseAuthUri) {
list.push(CxConstants.BASE_AUTH_URI);
list.push(this.config.baseAuthUri);
}
if (this.config.tenant) {
list.push(CxConstants.TENANT);
list.push(this.config.tenant);
}
if(this.config.additionalParameters){
this.prepareAdditionalParams(this.config.additionalParameters).forEach(function (param){
list.push(param)
})
}
if (formatRequired) {
list.push(CxConstants.OUTPUT_FORMAT);
list.push(CxConstants.FORMAT_JSON);
}
return list;
}

async authValidate(): Promise<CxCommandOutput> {
const commands: string[] = [CxConstants.CMD_AUTH, CxConstants.SUB_CMD_VALIDATE];
commands.push(...this.initializeCommands(false));
Expand Down Expand Up @@ -169,6 +208,18 @@ export class CxWrapper {
return await exec.executeCommands(this.config.pathToExecutable, commands, CxConstants.SCAN_TYPE);
}


async engineList(engineName:string):Promise<CxCommandOutput>{
const commands:string[]=[CxConstants.CMD_ENGINE,"list-api"]
if(engineName!=""){
commands.push(CxConstants.FLAG_ENGINE_NAME);
commands.push(engineName)
}
commands.push(...this.initializeCommandsEngine(true));
const exec = new ExecutionService();
return await exec.executeCommands(this.config.pathToExecutable, commands);
}

async projectList(filters: string): Promise<CxCommandOutput> {
const validated_filters = this.filterArguments(filters);
const commands: string[] = [CxConstants.CMD_PROJECT, "list"].concat(validated_filters);
Expand Down
34 changes: 34 additions & 0 deletions src/tests/EngineTest.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {BaseTest} from "./BaseTest";
import {CxWrapper} from '../main/wrapper/CxWrapper';
import {CxCommandOutput} from "../main/wrapper/CxCommandOutput";

describe("Engine cases",()=>{
const cxScanConfig = new BaseTest();

it("ALL Engine API List case",async ()=>{
const auth = new CxWrapper(cxScanConfig);
const engineList: CxCommandOutput = await auth.engineList("");
expect(engineList.payload.length).toBeGreaterThanOrEqual(0);
expect(engineList.payload.some(engine => engine.EngineName === "SAST")).toBe(true);
expect(engineList.payload.some(engine => engine.EngineName === "SCA")).toBe(true);
expect(engineList.payload.some(engine => engine.EngineName === "DAST")).toBe(true);
});

it("SAST Engine API List case",async ()=>{
const auth = new CxWrapper(cxScanConfig);
const engineList: CxCommandOutput = await auth.engineList("sast");
expect(engineList.payload.length).toBeGreaterThanOrEqual(0);
expect(engineList.payload.some(engine => engine.EngineName === "SAST")).toBe(true);
expect(engineList.payload.some(engine => engine.EngineName === "SCA")).toBe(false);
expect(engineList.payload.some(engine => engine.EngineName === "DAST")).toBe(false);
});

it("SCA Engine API List case",async ()=>{
const auth = new CxWrapper(cxScanConfig);
const engineList: CxCommandOutput = await auth.engineList("sca");
expect(engineList.payload.length).toBeGreaterThanOrEqual(0);
expect(engineList.payload.some(engine => engine.EngineName === "SAST")).toBe(false);
expect(engineList.payload[0].EngineName).toBe("SCA");
expect(engineList.payload.some(engine => engine.EngineName === "DAST")).toBe(false);
});
})
Loading