Skip to content

Commit aaded75

Browse files
Add SCA Triage Show and Update Support (AST-14824) (#933)
1 parent b23df43 commit aaded75

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed

src/main/wrapper/CxConstants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export enum CxConstants {
2+
VULNERABILITIES = "--vulnerability-identifiers",
23
IGNORE__FILE_PATH = "--ignored-file-path",
34
SOURCE = "-s",
45
VERBOSE = "-v",

src/main/wrapper/CxWrapper.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,34 @@ export class CxWrapper {
298298
return await exec.executeCommands(this.config.pathToExecutable, commands, CxConstants.PREDICATE_TYPE);
299299
}
300300

301+
async triageSCAShow(projectId: string, vulnerabilities: string, scanType: string): Promise<CxCommandOutput> {
302+
const commands: string[] = [
303+
CxConstants.CMD_TRIAGE,
304+
CxConstants.SUB_CMD_SHOW,
305+
CxConstants.SCAN_TYPES_SUB_CMD, scanType,
306+
CxConstants.VULNERABILITIES, vulnerabilities,
307+
CxConstants.PROJECT_ID, projectId
308+
];
309+
commands.push(...this.initializeCommands(true));
310+
const exec = new ExecutionService();
311+
return await exec.executeCommands(this.config.pathToExecutable, commands, CxConstants.PREDICATE_TYPE);
312+
}
313+
314+
async triageSCAUpdate(projectId: string, vulnerabilities: string, scanType: string, state: string, comment: string): Promise<CxCommandOutput> {
315+
const commands: string[] = [
316+
CxConstants.CMD_TRIAGE,
317+
CxConstants.SUB_CMD_UPDATE,
318+
CxConstants.SCAN_TYPES_SUB_CMD, scanType,
319+
CxConstants.VULNERABILITIES, vulnerabilities,
320+
CxConstants.STATE, state,
321+
CxConstants.COMMENT, comment,
322+
CxConstants.PROJECT_ID, projectId
323+
];
324+
commands.push(...this.initializeCommands(false));
325+
const exec = new ExecutionService();
326+
return await exec.executeCommands(this.config.pathToExecutable, commands);
327+
}
328+
301329
async triageUpdate(projectId: string, similarityId: string, scanType: string, state: string, comment: string, severity: string, stateId: number | null = null): Promise<CxCommandOutput> {
302330
const commands: string[] = [CxConstants.CMD_TRIAGE, CxConstants.SUB_CMD_UPDATE, CxConstants.PROJECT_ID, projectId, CxConstants.SIMILARITY_ID, similarityId, CxConstants.SCAN_TYPES_SUB_CMD, scanType, CxConstants.STATE, state, CxConstants.COMMENT, comment, CxConstants.SEVERITY, severity];
303331
if (stateId) {

src/tests/PredicateTest.test.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,19 @@ describe("Triage cases", () => {
3939
);
4040
expect(cxUpdate.exitCode).toEqual(0);
4141
};
42+
43+
// Helper for SCA triage show
44+
const handleTriageSCAShow = async (projectId: string, vulnerabilities: string, scanType: string) => {
45+
const cxShow: CxCommandOutput = await auth.triageSCAShow(projectId, vulnerabilities, scanType);
46+
expect(cxShow.exitCode).toEqual(0);
47+
};
48+
49+
// Helper for SCA triage update
50+
const handleTriageSCAUpdate = async (projectId: string, vulnerabilities: string, scanType: string, state: string, comment: string) => {
51+
const cxUpdate: CxCommandOutput = await auth.triageSCAUpdate(projectId, vulnerabilities, scanType, state, comment);
52+
expect(cxUpdate.exitCode).toEqual(0);
53+
};
54+
4255
const handlegetStates = async () => {
4356
const cxCommandOutput: CxCommandOutput = await auth.triageGetStates(false);
4457
console.log("Json object from states successful case: " + JSON.stringify(cxCommandOutput));
@@ -47,12 +60,57 @@ describe("Triage cases", () => {
4760
return cxCommandOutput
4861
};
4962

63+
it('SCA Triage Show and Update Successful case', async () => {
64+
const projectId = "d4d7f382-8dee-48c7-ac8f-67fab2c313a8";
65+
const vulnerabilities = "packagename=Maven-org.apache.tomcat.embed:tomcat-embed-core,packageversion=9.0.14,vulnerabilityId=CVE-2024-56337,packagemanager=maven";
66+
const scanType = "sca";
67+
const state = "To_verify";
68+
const comment = "comment1";
69+
await handleTriageSCAShow(projectId, vulnerabilities, scanType);
70+
await handleTriageSCAUpdate(projectId, vulnerabilities, scanType, state, comment);
71+
});
72+
73+
it('SCA Triage Show and Update Failure case', async () => {
74+
const projectId = "invalid-project-id";
75+
const vulnerabilities = "invalid-vulnerability-string";
76+
const scanType = "invalid";
77+
const state = "invalid_state";
78+
const comment = "invalid_comment";
79+
80+
const cxShow: CxCommandOutput = await auth.triageSCAShow(projectId, vulnerabilities, scanType);
81+
expect(cxShow.exitCode).not.toEqual(0);
82+
83+
const cxUpdate: CxCommandOutput = await auth.triageSCAUpdate(projectId, vulnerabilities, scanType, state, comment);
84+
expect(cxUpdate.exitCode).not.toEqual(0);
85+
});
86+
87+
it('SCA Triage Show and Update with empty vulnerabilities', async () => {
88+
const projectId = "d4d7f382-8dee-48c7-ac8f-67fab2c313a8";
89+
const vulnerabilities = "";
90+
const scanType = "sca";
91+
const state = "To_verify";
92+
const comment = "comment1";
93+
const cxShow: CxCommandOutput = await auth.triageSCAShow(projectId, vulnerabilities, scanType);
94+
expect(cxShow.exitCode).not.toEqual(0);
95+
96+
const cxUpdate: CxCommandOutput = await auth.triageSCAUpdate(projectId, vulnerabilities, scanType, state, comment);
97+
expect(cxUpdate.exitCode).not.toEqual(0);
98+
});
99+
100+
it('SCA Triage Show and Update with null/undefined arguments', async () => {
101+
const cxShow: CxCommandOutput = await auth.triageSCAShow(undefined, undefined, undefined);
102+
expect(cxShow.exitCode).not.toEqual(0);
103+
const cxUpdate: CxCommandOutput = await auth.triageSCAUpdate(undefined, undefined, undefined, undefined, undefined);
104+
expect(cxUpdate.exitCode).not.toEqual(0);
105+
});
106+
50107
it('Triage Successful case', async () => {
51108
const { scan, result } = await getScanAndResult();
52109
await handleTriageShow(scan, result);
53110
await handleTriageUpdate(scan, result, result.state, result.severity.toLowerCase() === "high" ? CxConstants.SEVERITY_MEDIUM : CxConstants.SEVERITY_HIGH);
54111
});
55112

113+
56114
it.skip('Triage with custom state Successful case', async () => {
57115
const { scan, result } = await getScanAndResult();
58116

0 commit comments

Comments
 (0)