Skip to content

Commit 0b8d7b7

Browse files
authored
add support risk managment (#814)
1 parent 4be6a11 commit 0b8d7b7

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
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
@@ -229,6 +229,20 @@ export class CxWrapper {
229229
return exec.executeResultsCommandsFile(scanId, CxConstants.FORMAT_JSON, CxConstants.FORMAT_JSON_FILE, commands, this.config.pathToExecutable, fileName);
230230
}
231231

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+
}
245+
232246
async getResultsSummary(scanId: string): Promise<CxCommandOutput> {
233247
const exec = new ExecutionService();
234248
const fileName = new Date().getTime().toString();

src/tests/ResultTest.test.ts

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,51 @@ describe("Results cases",() => {
6363
const cxCommandOutput: CxCommandOutput = await auth.codeBashingList("79","PHP","Reflected XSS All Clients");
6464
expect(cxCommandOutput.payload.length).toBeGreaterThan(0);
6565
});
66-
});
66+
67+
// The project ID is hardcoded because there is no dynamic way to associate
68+
// an application with a project through the CLI.
69+
// link to the our application: https://deu.ast.checkmarx.net/applications/5dff8d1c-d27f-4910-afc1-0b9df02324b4/overview
70+
it("Risk Management - Successful case", async () => {
71+
const auth = new CxWrapper(cxScanConfig);
72+
const projectId = "a5d99fa4-973d-48b5-86c7-6401487e1d52"
73+
74+
const cxCommandOutput: CxCommandOutput = await auth.riskManagementResults(
75+
projectId
76+
);
77+
78+
const str = JSON.stringify(cxCommandOutput);
79+
console.log("Risk Management Result 1: " + str);
80+
console.log("Risk Management Exit code 1: " + cxCommandOutput.exitCode);
81+
console.log("Risk Management payload 1: " + cxCommandOutput.payload);
82+
83+
expect(cxCommandOutput.exitCode).toBe(0);
84+
expect(Object.keys(cxCommandOutput.payload).length).toBeGreaterThan(0);
85+
});
86+
87+
88+
// The project ID is hardcoded because there is no dynamic way to associate
89+
// an application with a project through the CLI.
90+
// link to the our application: https://deu.ast.checkmarx.net/applications/5dff8d1c-d27f-4910-afc1-0b9df02324b4/overview
91+
it("Risk Management - With Limit", async () => {
92+
const auth = new CxWrapper(cxScanConfig);
93+
const projectId = "a5d99fa4-973d-48b5-86c7-6401487e1d52"
94+
const cxCommandOutput: CxCommandOutput = await auth.riskManagementResults(
95+
projectId,
96+
10
97+
);
98+
99+
const str = JSON.stringify(cxCommandOutput);
100+
console.log("Risk Management Result 2: " + str);
101+
console.log("Risk Management Exit code 2: " + cxCommandOutput.exitCode);
102+
console.log("Risk Management payload 2: " + cxCommandOutput.payload);
103+
104+
expect(cxCommandOutput.exitCode).toBe(0);
105+
expect(Object.keys(cxCommandOutput.payload).length).toBeGreaterThan(0);
106+
});
107+
108+
})
109+
110+
67111

68112
const fileExists = (file:string) => {
69113
return new Promise((resolve) => {

0 commit comments

Comments
 (0)