Skip to content

Commit 8ddedfb

Browse files
added support for engineAPI list
1 parent 83a9bb1 commit 8ddedfb

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed

src/main/wrapper/CxConstants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ export enum CxConstants {
3030
CMD_PROJECT = "project",
3131
SUB_CMD_BRANCHES = "branches",
3232
CMD_SCAN = "scan",
33+
CMD_ENGINE="engine",
34+
FLAG_ENGINE_NAME="--engine-name",
3335
SUB_CMD_SHOW = "show",
3436
SUB_CMD_CANCEL = "cancel",
3537
SUB_CMD_LIST = "list",
@@ -62,6 +64,7 @@ export enum CxConstants {
6264
CMD_SAST_CHAT_RESULT_SOURCE_FILE = "--source-dir",
6365
SCAN_INFO_FORMAT = "--scan-info-format",
6466
FORMAT = "--format",
67+
OUTPUT_FORMAT="--output-format",
6568
FORMAT_JSON = "json",
6669
FORMAT_HTML = "html",
6770
FORMAT_JSON_FILE = ".json",

src/main/wrapper/CxWrapper.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,45 @@ export class CxWrapper {
9494
return list;
9595
}
9696

97+
98+
initializeCommandsEngine(formatRequired: boolean): string[] {
99+
const list: string[] = [];
100+
if (this.config.clientId) {
101+
list.push(CxConstants.CLIENT_ID);
102+
list.push(this.config.clientId);
103+
}
104+
if (this.config.clientSecret) {
105+
list.push(CxConstants.CLIENT_SECRET);
106+
list.push(this.config.clientSecret);
107+
}
108+
if (this.config.apiKey) {
109+
list.push(CxConstants.API_KEY);
110+
list.push(this.config.apiKey);
111+
}
112+
if (this.config.baseUri) {
113+
list.push(CxConstants.BASE_URI);
114+
list.push(this.config.baseUri);
115+
}
116+
if (this.config.baseAuthUri) {
117+
list.push(CxConstants.BASE_AUTH_URI);
118+
list.push(this.config.baseAuthUri);
119+
}
120+
if (this.config.tenant) {
121+
list.push(CxConstants.TENANT);
122+
list.push(this.config.tenant);
123+
}
124+
if(this.config.additionalParameters){
125+
this.prepareAdditionalParams(this.config.additionalParameters).forEach(function (param){
126+
list.push(param)
127+
})
128+
}
129+
if (formatRequired) {
130+
list.push(CxConstants.OUTPUT_FORMAT);
131+
list.push(CxConstants.FORMAT_JSON);
132+
}
133+
return list;
134+
}
135+
97136
async authValidate(): Promise<CxCommandOutput> {
98137
const commands: string[] = [CxConstants.CMD_AUTH, CxConstants.SUB_CMD_VALIDATE];
99138
commands.push(...this.initializeCommands(false));
@@ -169,6 +208,18 @@ export class CxWrapper {
169208
return await exec.executeCommands(this.config.pathToExecutable, commands, CxConstants.SCAN_TYPE);
170209
}
171210

211+
212+
async engineList(engineName:string):Promise<CxCommandOutput>{
213+
const commands:string[]=[CxConstants.CMD_ENGINE,"list-api"]
214+
if(engineName!=""){
215+
commands.push(CxConstants.FLAG_ENGINE_NAME);
216+
commands.push(engineName)
217+
}
218+
commands.push(...this.initializeCommandsEngine(true));
219+
const exec = new ExecutionService();
220+
return await exec.executeCommands(this.config.pathToExecutable, commands);
221+
}
222+
172223
async projectList(filters: string): Promise<CxCommandOutput> {
173224
const validated_filters = this.filterArguments(filters);
174225
const commands: string[] = [CxConstants.CMD_PROJECT, "list"].concat(validated_filters);

src/tests/EngineTest.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import {BaseTest} from "./BaseTest";
2+
import {CxWrapper} from '../main/wrapper/CxWrapper';
3+
import {CxCommandOutput} from "../main/wrapper/CxCommandOutput";
4+
5+
describe("Engine cases",()=>{
6+
const cxScanConfig = new BaseTest();
7+
8+
it("ALL Engine API List case",async ()=>{
9+
const auth = new CxWrapper(cxScanConfig);
10+
const engineList: CxCommandOutput = await auth.engineList("");
11+
expect(engineList.payload.length).toBeGreaterThanOrEqual(0);
12+
expect(engineList.payload.some(engine => engine.EngineName === "SAST")).toBe(true);
13+
expect(engineList.payload.some(engine => engine.EngineName === "SCA")).toBe(true);
14+
expect(engineList.payload.some(engine => engine.EngineName === "DAST")).toBe(true);
15+
});
16+
17+
it("SAST Engine API List case",async ()=>{
18+
const auth = new CxWrapper(cxScanConfig);
19+
const engineList: CxCommandOutput = await auth.engineList("sast");
20+
expect(engineList.payload.length).toBeGreaterThanOrEqual(0);
21+
expect(engineList.payload.some(engine => engine.EngineName === "SAST")).toBe(true);
22+
expect(engineList.payload.some(engine => engine.EngineName === "SCA")).toBe(false);
23+
expect(engineList.payload.some(engine => engine.EngineName === "DAST")).toBe(false);
24+
});
25+
26+
it("SCA Engine API List case",async ()=>{
27+
const auth = new CxWrapper(cxScanConfig);
28+
const engineList: CxCommandOutput = await auth.engineList("sca");
29+
expect(engineList.payload.length).toBeGreaterThanOrEqual(0);
30+
expect(engineList.payload.some(engine => engine.EngineName === "SAST")).toBe(false);
31+
expect(engineList.payload[0].EngineName).toBe("SCA");
32+
expect(engineList.payload.some(engine => engine.EngineName === "DAST")).toBe(false);
33+
});
34+
})

0 commit comments

Comments
 (0)