Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/main/wrapper/CxConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export enum CxConstants {
SUB_CMD_CREATE = "create",
CMD_TRIAGE = "triage",
SUB_CMD_UPDATE = "update",
SUB_CMD_GET_STATES = "get-states",
ALL_STATES_FLAG = "--all",
CMD_RESULT = "results",
SUB_CMD_BFL = "bfl",
CMD_CODE_BASHING = "codebashing",
Expand Down Expand Up @@ -72,6 +74,7 @@ export enum CxConstants {
SIMILARITY_ID = "--similarity-id",
QUERY_ID = "--query-id",
STATE = "--state",
STATE_ID = "--state-id",
COMMENT = "--comment",
SEVERITY = "--severity",
REPORT_FORMAT = "--report-format",
Expand Down
14 changes: 13 additions & 1 deletion src/main/wrapper/CxWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,20 @@ export class CxWrapper {
return await exec.executeCommands(this.config.pathToExecutable, commands, CxConstants.PREDICATE_TYPE);
}

async triageUpdate(projectId: string, similarityId: string, scanType: string, state: string, comment: string, severity: string): Promise<CxCommandOutput> {
async triageUpdate(projectId: string, similarityId: string, scanType: string, state: string, comment: string, severity: string, stateId = ""): Promise<CxCommandOutput> {
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];
if(stateId) {
commands.push(CxConstants.STATE_ID)
commands.push(stateId)
}
commands.push(...this.initializeCommands(false));
const exec = new ExecutionService();
return await exec.executeCommands(this.config.pathToExecutable, commands);
}

async triageGetStates(all: boolean): Promise<CxCommandOutput> {
const commands: string[] = [CxConstants.CMD_TRIAGE, CxConstants.SUB_CMD_GET_STATES];
if (all) commands.push(CxConstants.ALL_STATES_FLAG)
commands.push(...this.initializeCommands(false));
const exec = new ExecutionService();
return await exec.executeCommands(this.config.pathToExecutable, commands);
Expand Down
89 changes: 70 additions & 19 deletions src/tests/PredicateTest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,87 @@ import {CxConstants} from '../main/wrapper/CxConstants';

describe("Triage cases", () => {
const cxScanConfig = new BaseTest();

it('Triage Successful case', async () => {
const auth = new CxWrapper(cxScanConfig);

const auth = new CxWrapper(cxScanConfig);
const getScanAndResult = async (): Promise<{ scan: any, result: CxResult }> => {
const scanList: CxCommandOutput = await auth.scanList("statuses=Completed,limit=100");
let result: CxResult;
let scan, output;
while (!output && scanList && scanList.payload && scanList.payload.length > 0) {
scan = scanList.payload.pop()
console.log("Triage Successful case - ScanId " + scan.id)
output = await auth.getResultsList(scan.id)
if (output.status == "Error in the json file.") {
let scan, output, result;
while (!output && scanList?.payload?.length > 0) {
scan = scanList.payload.pop();
console.log("Triage case - ScanId " + scan.id);
output = await auth.getResultsList(scan.id);
if (output.status === "Error in the json file.") {
output = undefined;
} else {
result = output.payload.find(res => res.type == CxConstants.SAST)
if (!result || !result.similarityId) {
result = output.payload.find(res => res.type === CxConstants.SAST);
if (!result?.similarityId) {
output = undefined;
}
}
}
return { scan, result };
};

const handleTriageShow = async (scan: any, result: CxResult) => {
const cxShow: CxCommandOutput = await auth.triageShow(scan.projectID, result.similarityId, result.type);

expect(cxShow.exitCode).toEqual(0);
}

const cxUpdate: CxCommandOutput = await
auth.triageUpdate(scan.projectID, result.similarityId, result.type, result.state,
"Edited via JavascriptWrapper",
result.severity.toLowerCase() == "high" ? CxConstants.SEVERITY_MEDIUM : CxConstants.SEVERITY_HIGH);

const handleTriageUpdate = async (scan: any, result: CxResult, newState: string, newSeverity: string, newStateId = "") => {
const cxUpdate: CxCommandOutput = await auth.triageUpdate(
scan.projectID, result.similarityId, result.type, newState,
"Edited via JavascriptWrapper",
newSeverity, newStateId
);
expect(cxUpdate.exitCode).toEqual(0);
};
const handlegetStates = async () => {
const cxCommandOutput: CxCommandOutput = await auth.triageGetStates(false);
console.log("Json object from states successful case: " + JSON.stringify(cxCommandOutput));
expect(cxCommandOutput.payload.length).toBeGreaterThanOrEqual(1);
expect(cxCommandOutput.exitCode).toBe(0);
return cxCommandOutput
};

it('Triage Successful case', async () => {
const { scan, result } = await getScanAndResult();
await handleTriageShow(scan, result);
await handleTriageUpdate(scan, result, result.state, result.severity.toLowerCase() === "high" ? CxConstants.SEVERITY_MEDIUM : CxConstants.SEVERITY_HIGH);
});

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

const cxCommandOutput = await handlegetStates();

let customState = cxCommandOutput.payload[0].name

if (result.state == customState) {
if (cxCommandOutput.payload.length > 1) {
customState = cxCommandOutput.payload[1].name
} else {
await handleTriageUpdate(scan, result, CxConstants.STATE_CONFIRMED, CxConstants.SEVERITY_MEDIUM);
}
}
await handleTriageUpdate(scan, result, customState, CxConstants.SEVERITY_MEDIUM);

});

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

const cxCommandOutput = await handlegetStates();

const allStates = cxCommandOutput.payload;
let customStateId = allStates[0].id
const customStateName = allStates[0].name

if (result.state == customStateName) {
if (allStates.length > 1) {
customStateId = allStates[1].id
} else {
await handleTriageUpdate(scan, result, CxConstants.STATE_CONFIRMED, CxConstants.SEVERITY_MEDIUM);
}
}
await handleTriageUpdate(scan, result, "", CxConstants.SEVERITY_MEDIUM, customStateId.toString());
});
});