Skip to content

Commit ea467db

Browse files
committed
add support risk managment
1 parent 083e1ce commit ea467db

File tree

3 files changed

+138
-63
lines changed

3 files changed

+138
-63
lines changed

src/main/wrapper/CxConstants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ export enum CxConstants {
3939
SUB_CMD_GET_STATES = "get-states",
4040
ALL_STATES_FLAG = "--all",
4141
CMD_RESULT = "results",
42+
CMD_RISK_MANAGEMENT = "risk-management",
43+
CMD_LIMIT = "--limit",
4244
SUB_CMD_BFL = "bfl",
4345
CMD_CODE_BASHING = "codebashing",
4446
CMD_KICS_REALTIME = "kics-realtime",

src/main/wrapper/CxWrapper.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,20 @@ export class CxWrapper {
228228
// Reads the result file and retrieves the results
229229
return exec.executeResultsCommandsFile(scanId, CxConstants.FORMAT_JSON, CxConstants.FORMAT_JSON_FILE, commands, this.config.pathToExecutable, fileName);
230230
}
231+
232+
async riskManagementResults(projectId: string, limit?: number): Promise<CxCommandOutput> {
233+
const commands: string[] = [CxConstants.CMD_RESULT, CxConstants.CMD_RISK_MANAGEMENT];
234+
commands.push(CxConstants.PROJECT_ID, projectId);
235+
236+
if (limit !== undefined) {
237+
commands.push(CxConstants.CMD_LIMIT, limit.toString());
238+
}
239+
240+
commands.push(...this.initializeCommands(false));
241+
242+
const exec = new ExecutionService();
243+
return await exec.executeCommands(this.config.pathToExecutable, commands);
244+
}
231245

232246
async getResultsSummary(scanId: string): Promise<CxCommandOutput> {
233247
const exec = new ExecutionService();

src/tests/ResultTest.test.ts

Lines changed: 122 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,133 @@
1-
import {CxWrapper} from '../main/wrapper/CxWrapper';
2-
import {CxCommandOutput} from "../main/wrapper/CxCommandOutput";
3-
import {BaseTest} from "./BaseTest";
1+
import { CxWrapper } from "../main/wrapper/CxWrapper";
2+
import { CxCommandOutput } from "../main/wrapper/CxCommandOutput";
3+
import { BaseTest } from "./BaseTest";
44
import * as fs from "fs";
55

6-
describe("Results cases",() => {
7-
const cxScanConfig = new BaseTest();
8-
it('Result Test Successful case', async () => {
9-
const auth = new CxWrapper(cxScanConfig);
10-
const cxCommandOutput: CxCommandOutput = await auth.scanList("statuses=Completed");
11-
const sampleId = cxCommandOutput.payload.pop().id;
12-
13-
auth.getResults(sampleId,"json","jsonList", ".").then(() => {
14-
fileExists("./jsonList.json").then(file => expect(file).toBe(true));
15-
});
16-
});
6+
describe("Results cases", () => {
7+
const cxScanConfig = new BaseTest();
8+
it("Result Test Successful case", async () => {
9+
const auth = new CxWrapper(cxScanConfig);
10+
const cxCommandOutput: CxCommandOutput = await auth.scanList(
11+
"statuses=Completed"
12+
);
13+
const sampleId = cxCommandOutput.payload.pop().id;
1714

18-
it('Result Test With Agent Flug Successful case', async () => {
19-
const auth = new CxWrapper(cxScanConfig);
20-
const cxCommandOutput: CxCommandOutput = await auth.scanList("statuses=Completed");
21-
const sampleId = cxCommandOutput.payload.pop().id;
22-
23-
auth.getResults(sampleId,"json","jsonList", ".", "jswrapper").then(() => {
24-
fileExists("./jsonList.json").then(file => expect(file).toBe(true));
25-
});
15+
auth.getResults(sampleId, "json", "jsonList", ".").then(() => {
16+
fileExists("./jsonList.json").then((file) => expect(file).toBe(true));
2617
});
18+
});
2719

28-
it('Result List Successful case', async () => {
29-
const auth = new CxWrapper(cxScanConfig);
30-
const scanList: CxCommandOutput = await auth.scanList("statuses=Completed");
31-
let output;
32-
while (!output && scanList && scanList.payload && scanList.payload.length > 0) {
33-
const scanId = scanList.payload.pop().id;
34-
console.log("Triage Successful case - ScanId " + scanId);
35-
output = await auth.getResultsList(scanId);
36-
if (output.status == "Error in the json file.") {
37-
output = undefined;
38-
}
39-
}
40-
expect(output.status).toBeUndefined();
41-
expect(output.payload.length).toBeGreaterThanOrEqual(0);
42-
});
20+
it("Result Test With Agent Flug Successful case", async () => {
21+
const auth = new CxWrapper(cxScanConfig);
22+
const cxCommandOutput: CxCommandOutput = await auth.scanList(
23+
"statuses=Completed"
24+
);
25+
const sampleId = cxCommandOutput.payload.pop().id;
4326

44-
it('Result summary html file generation successful case', async () => {
45-
const auth = new CxWrapper(cxScanConfig);
46-
const cxCommandOutput: CxCommandOutput = await auth.scanList("statuses=Completed");
47-
const sampleId = cxCommandOutput.payload.pop().id;
48-
await auth.getResults(sampleId,"summaryHTML","test", ".");
49-
const file = await fileExists("./test.html");
50-
expect(file).toBe(true);
27+
auth.getResults(sampleId, "json", "jsonList", ".", "jswrapper").then(() => {
28+
fileExists("./jsonList.json").then((file) => expect(file).toBe(true));
5129
});
30+
});
5231

53-
it('Result summary html string successful case', async () => {
54-
const auth = new CxWrapper(cxScanConfig);
55-
const cxCommandOutput: CxCommandOutput = await auth.scanList("statuses=Completed");
56-
const sampleId = cxCommandOutput.payload.pop().id;
57-
const written = await auth.getResultsSummary(sampleId);
58-
expect(written.payload.length).toBeGreaterThan(0);
59-
});
32+
it("Result List Successful case", async () => {
33+
const auth = new CxWrapper(cxScanConfig);
34+
const scanList: CxCommandOutput = await auth.scanList("statuses=Completed");
35+
let output;
36+
while (
37+
!output &&
38+
scanList &&
39+
scanList.payload &&
40+
scanList.payload.length > 0
41+
) {
42+
const scanId = scanList.payload.pop().id;
43+
console.log("Triage Successful case - ScanId " + scanId);
44+
output = await auth.getResultsList(scanId);
45+
if (output.status == "Error in the json file.") {
46+
output = undefined;
47+
}
48+
}
49+
expect(output.status).toBeUndefined();
50+
expect(output.payload.length).toBeGreaterThanOrEqual(0);
51+
});
6052

61-
it('Result codebashing successful case', async () => {
62-
const auth = new CxWrapper(cxScanConfig);
63-
const cxCommandOutput: CxCommandOutput = await auth.codeBashingList("79","PHP","Reflected XSS All Clients");
64-
expect(cxCommandOutput.payload.length).toBeGreaterThan(0);
65-
});
53+
it("Result summary html file generation successful case", async () => {
54+
const auth = new CxWrapper(cxScanConfig);
55+
const cxCommandOutput: CxCommandOutput = await auth.scanList(
56+
"statuses=Completed"
57+
);
58+
const sampleId = cxCommandOutput.payload.pop().id;
59+
await auth.getResults(sampleId, "summaryHTML", "test", ".");
60+
const file = await fileExists("./test.html");
61+
expect(file).toBe(true);
62+
});
63+
64+
it("Result summary html string successful case", async () => {
65+
const auth = new CxWrapper(cxScanConfig);
66+
const cxCommandOutput: CxCommandOutput = await auth.scanList(
67+
"statuses=Completed"
68+
);
69+
const sampleId = cxCommandOutput.payload.pop().id;
70+
const written = await auth.getResultsSummary(sampleId);
71+
expect(written.payload.length).toBeGreaterThan(0);
72+
});
73+
74+
it("Result codebashing successful case", async () => {
75+
const auth = new CxWrapper(cxScanConfig);
76+
const cxCommandOutput: CxCommandOutput = await auth.codeBashingList(
77+
"79",
78+
"PHP",
79+
"Reflected XSS All Clients"
80+
);
81+
expect(cxCommandOutput.payload.length).toBeGreaterThan(0);
82+
});
83+
84+
it("Risk Management - Successful case", async () => {
85+
const auth = new CxWrapper(cxScanConfig);
86+
const projectId = await getProjectId(auth);
87+
88+
const cxCommandOutput: CxCommandOutput = await auth.riskManagementResults(
89+
projectId
90+
);
91+
console.log("Risk Management Results: " + JSON.stringify(cxCommandOutput));
92+
93+
expect(cxCommandOutput.exitCode).toBe(0);
94+
expect(cxCommandOutput.payload.length).toBeGreaterThan(0);
95+
});
96+
97+
it("Risk Management - With Limit", async () => {
98+
const auth = new CxWrapper(cxScanConfig);
99+
const projectId = await getProjectId(auth);
100+
const cxCommandOutput: CxCommandOutput = await auth.riskManagementResults(
101+
projectId,
102+
10
103+
);
104+
console.log(
105+
"Risk Management Results with limit 10: " +
106+
JSON.stringify(cxCommandOutput)
107+
);
108+
109+
expect(cxCommandOutput.exitCode).toBe(0);
110+
expect(cxCommandOutput.payload.length).toBeLessThanOrEqual(10);
111+
});
66112
});
67113

68-
const fileExists = (file:string) => {
69-
return new Promise((resolve) => {
70-
fs.access(file, fs.constants.F_OK, (err) => {
71-
err ? resolve(false) : resolve(true)
72-
});
73-
})
74-
}
114+
const getProjectId = async (auth: CxWrapper): Promise<string> => {
115+
const scanList: CxCommandOutput = await auth.scanList("statuses=Completed");
116+
if (!scanList.payload.length) {
117+
throw new Error("No completed scans found.");
118+
}
119+
const scan = scanList.payload.find((scan) => scan.projectID);
120+
if (!scan) {
121+
throw new Error("No valid projectId found.");
122+
}
123+
return scan.projectID;
124+
};
125+
126+
127+
const fileExists = (file: string) => {
128+
return new Promise((resolve) => {
129+
fs.access(file, fs.constants.F_OK, (err) => {
130+
err ? resolve(false) : resolve(true);
131+
});
132+
});
133+
};

0 commit comments

Comments
 (0)