Skip to content

Commit 8a71f20

Browse files
authored
Merge pull request #39 from CheckmarxDev/feature/AST-7569_triage_command
Triage show and update methods added
2 parents 8e0a4e2 + ac59105 commit 8a71f20

File tree

5 files changed

+73
-8
lines changed

5 files changed

+73
-8
lines changed

src/main/predicates/CxPredicate.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export default class CxPredicate {
2+
id: string = "";
3+
similarityId: string = "";
4+
projectId: string = "";
5+
state: string = "";
6+
severity: string = "";
7+
created: string = "";
8+
updated: string = "";
9+
comment: string = "";
10+
}

src/main/results/CxResult.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export default class CxResult {
22
type: string = "";
33
id: string = "";
44
status: string = "";
5+
similarityId = "";
56
state: string = "";
67
severity: string = "";
78
created: string = "";

src/main/wrapper/CxConstants.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export enum CxConstants {
22
SOURCE = "-s",
33
VERBOSE = "-v",
44
PROJECT_NAME = "--project-name",
5-
SCAN_TYPES = "--scan-types",
5+
SCAN_TYPES_SUB_CMD = "--scan-type",
66
SAST_PRESET_NAME = "--sast-preset-name",
77
FILE_FILTER = "--file-filter",
88
AGENT = "--agent",
@@ -22,6 +22,8 @@ export enum CxConstants {
2222
SUB_CMD_SHOW = "show",
2323
SUB_CMD_LIST = "list",
2424
SUB_CMD_CREATE = "create",
25+
CMD_TRIAGE = "triage",
26+
SUB_CMD_UPDATE = "update",
2527
CMD_RESULT = "result",
2628
FORMAT = "--format",
2729
FORMAT_JSON = "json",
@@ -32,9 +34,14 @@ export enum CxConstants {
3234
FILTER = "--filter",
3335
SCAN_ID = "--scan-id",
3436
PROJECT_ID = "--project-id",
37+
SIMILARITY_ID = "--similarity-id",
38+
STATE = "--state",
39+
COMMENT = "--comment",
40+
SEVERITY = "--severity",
3541
REPORT_FORMAT = "--report-format",
3642
OUTPUT_NAME = "--output-name",
3743
OUTPUT_PATH = "--output-path",
3844
SCAN_TYPE = "CxScan",
3945
PROJECT_TYPE = "CxProject",
46+
PREDICATE_TYPE = "CxPredicate"
4047
}

src/main/wrapper/CxWrapper.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ export class CxWrapper {
7575
return list;
7676
}
7777

78+
async authValidate(): Promise<CxCommandOutput> {
79+
const commands: string[] = [CxConstants.CMD_AUTH, CxConstants.SUB_CMD_VALIDATE];
80+
commands.push(...this.initializeCommands(false));
81+
let exec = new ExecutionService();
82+
return await exec.executeCommands(this.config.pathToExecutable, commands);
83+
}
84+
7885
async scanCreate(params: ParamTypeMap): Promise<CxCommandOutput> {
7986
const commands: string[] = [CxConstants.CMD_SCAN, CxConstants.SUB_CMD_CREATE];
8087
commands.push(...this.initializeCommands(true));
@@ -99,13 +106,6 @@ export class CxWrapper {
99106
return await exec.executeCommands(this.config.pathToExecutable, commands, CxConstants.SCAN_TYPE);
100107
}
101108

102-
async authValidate(): Promise<CxCommandOutput> {
103-
const commands: string[] = [CxConstants.CMD_AUTH, CxConstants.SUB_CMD_VALIDATE];
104-
commands.push(...this.initializeCommands(false));
105-
let exec = new ExecutionService();
106-
return await exec.executeCommands(this.config.pathToExecutable, commands);
107-
}
108-
109109
async scanShow(id: string): Promise<CxCommandOutput> {
110110
const commands: string[] = [CxConstants.CMD_SCAN, CxConstants.SUB_CMD_SHOW, CxConstants.SCAN_ID, id];
111111
commands.push(...this.initializeCommands(true));
@@ -145,6 +145,20 @@ export class CxWrapper {
145145
return await exec.executeCommands(this.config.pathToExecutable, commands, CxConstants.PROJECT_TYPE);
146146
}
147147

148+
async triageShow(projectId: string, similarityId: string, scanType: string ): Promise<CxCommandOutput> {
149+
const commands: string[] = [CxConstants.CMD_TRIAGE, CxConstants.SUB_CMD_SHOW, CxConstants.PROJECT_ID, projectId, CxConstants.SIMILARITY_ID, similarityId, CxConstants.SCAN_TYPES_SUB_CMD, scanType];
150+
commands.push(...this.initializeCommands(true));
151+
const exec = new ExecutionService();
152+
return await exec.executeCommands(this.config.pathToExecutable, commands, CxConstants.PREDICATE_TYPE);
153+
}
154+
155+
async triageUpdate(projectId: string, similarityId: string, scanType: string, state: string, comment: string, severity: string): Promise<CxCommandOutput> {
156+
const commands: string[] = [CxConstants.CMD_TRIAGE, CxConstants.SUB_CMD_UPDATE, CxConstants.PROJECT_ID, projectId, CxConstants.SIMILARITY_ID, similarityId, CxConstants.SCAN_TYPE, scanType, CxConstants.STATE, state, CxConstants.COMMENT, comment, CxConstants.SEVERITY, severity];
157+
commands.push(...this.initializeCommands(false));
158+
const exec = new ExecutionService();
159+
return await exec.executeCommands(this.config.pathToExecutable, commands);
160+
}
161+
148162
async getResultsList(scanId: string) {
149163
const exec = new ExecutionService();
150164
const fileName = new Date().getTime().toString();

src/tests/PredicateTest.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import {CxWrapper} from '../main/wrapper/CxWrapper';
2+
import {CxCommandOutput} from "../main/wrapper/CxCommandOutput";
3+
import {BaseTest} from "./BaseTest";
4+
import CxResult from '../main/results/CxResult';
5+
import CxScan from '../main/scan/CxScan';
6+
7+
describe("Triage cases",() => {
8+
let cxScanConfig = new BaseTest();
9+
10+
it('TriageShow Successful case', async () => {
11+
const auth = new CxWrapper(cxScanConfig);
12+
const scanListOutput = await auth.scanList("statuses=Completed");
13+
const scan: CxScan = scanListOutput.payload[0]
14+
const results = await auth.getResultsList(scan.id)
15+
const result: CxResult = results.payload.find(res => res.type == "sast")
16+
17+
const cxCommandOutput: CxCommandOutput = await auth.triageShow(scan.projectID, result.similarityId, "sast");
18+
19+
expect(cxCommandOutput.exitCode).toEqual(0);
20+
})
21+
22+
it('TriageUpdate Successful case', async () => {
23+
const auth = new CxWrapper(cxScanConfig);
24+
const scanListOutput = await auth.scanList("statuses=Completed");
25+
const scan: CxScan = scanListOutput.payload[0]
26+
const results = await auth.getResultsList(scan.id)
27+
const result: CxResult = results.payload.find(res => res.type == "sast")
28+
29+
const cxCommandOutput: CxCommandOutput = await auth.triageUpdate(scan.projectID, result.similarityId, "sast", "confirmed", "Edited via JavascriptWrapper", "high");
30+
31+
expect(cxCommandOutput.exitCode).toEqual(0);
32+
})
33+
});

0 commit comments

Comments
 (0)