diff --git a/src/main/learnmore/CxLearnMoreDescriptions.ts b/src/main/learnmore/CxLearnMoreDescriptions.ts new file mode 100644 index 00000000..c6abbe45 --- /dev/null +++ b/src/main/learnmore/CxLearnMoreDescriptions.ts @@ -0,0 +1,31 @@ +import CxLearnMoreSamples from "./CxLearnMoreSamples"; + +export default class CxLearnMoreDescriptions { + queryId: string; + queryName: string; + queryDescriptionId: string; + resultDescription: string; + risk: string; + cause: string; + generalRecommendations: string; + samples: CxLearnMoreSamples[]; + + static parseLearnMoreDescriptionsResponse(resultObject: any[]): CxLearnMoreDescriptions[] { + let learnMoreDescriptionsArray:CxLearnMoreDescriptions[] = [] + learnMoreDescriptionsArray = resultObject.map((result: any) => { + const cxLearnMoreDescriptions = new CxLearnMoreDescriptions(); + cxLearnMoreDescriptions.queryId = result.queryId; + cxLearnMoreDescriptions.queryName = result.queryName; + cxLearnMoreDescriptions.queryDescriptionId = result.queryDescriptionId; + cxLearnMoreDescriptions.resultDescription = result.resultDescription; + cxLearnMoreDescriptions.risk = result.risk; + cxLearnMoreDescriptions.cause = result.cause; + cxLearnMoreDescriptions.generalRecommendations = result.generalRecommendations; + cxLearnMoreDescriptions.samples = result.samples; + return cxLearnMoreDescriptions; + }); + + return learnMoreDescriptionsArray; + } + +} diff --git a/src/main/learnmore/CxLearnMoreSamples.ts b/src/main/learnmore/CxLearnMoreSamples.ts new file mode 100644 index 00000000..a92b75a9 --- /dev/null +++ b/src/main/learnmore/CxLearnMoreSamples.ts @@ -0,0 +1,5 @@ +export default class CxLearnMoreSamples { + progLanguage: string; + code: string; + title: string; +} diff --git a/src/main/wrapper/CxConstants.ts b/src/main/wrapper/CxConstants.ts index 15bf4251..3ab1e1e2 100644 --- a/src/main/wrapper/CxConstants.ts +++ b/src/main/wrapper/CxConstants.ts @@ -66,14 +66,15 @@ export enum CxConstants { PREDICATE_TYPE = "CxPredicate", CODE_BASHING_TYPE = "CxCodeBashing", KICS_REALTIME_TYPE = "CxKicsRealTime", + LEARN_MORE_DESCRIPTIONS_TYPE = "CxLearnMoreDescriptions", KICS_REMEDIATION_TYPE = "CxKicsRemediation", BFL_TYPE = "CxBFL", SAST = "sast", LANGUAGE = "--language", VULNERABILITY_TYPE = "--vulnerability-type", CWE_ID = "--cwe-id", - SEVERITY_HIGH = "high", SEVERITY_MEDIUM = "medium", - STATE_CONFIRMED = "confirmed" + STATE_CONFIRMED = "confirmed", + CMD_LEARN_MORE = "learn-more" } diff --git a/src/main/wrapper/CxWrapper.ts b/src/main/wrapper/CxWrapper.ts index cc52ff7b..a99605aa 100644 --- a/src/main/wrapper/CxWrapper.ts +++ b/src/main/wrapper/CxWrapper.ts @@ -247,6 +247,14 @@ export class CxWrapper { return exec.executeKicsCommands(this.config.pathToExecutable, commands, CxConstants.KICS_REALTIME_TYPE); } + + async learnMore(queryId: string){ + const commands: string[] = [CxConstants.CMD_UTILS,CxConstants.CMD_LEARN_MORE,CxConstants.QUERY_ID,queryId] + commands.push(...this.initializeCommands(true)) + const exec = new ExecutionService(); + return exec.executeCommands(this.config.pathToExecutable, commands, CxConstants.LEARN_MORE_DESCRIPTIONS_TYPE); + } + async kicsRemediation(resultsFile: string, kicsFile:string, engine:string,similarityIds?: string):Promise<[Promise,any]> { const commands: string[] = [CxConstants.CMD_UTILS, CxConstants.CMD_REMEDIATION,CxConstants.SUB_CMD_REMEDIATION_KICS,CxConstants.KICS_REMEDIATION_RESULTS_FILE, resultsFile, CxConstants.KICS_REMEDIATION_KICS_FILE, kicsFile]; if(engine.length>0){ @@ -267,6 +275,7 @@ export class CxWrapper { return exec.executeCommands(this.config.pathToExecutable, commands); } + getIndexOfBflNode(bflNodes: CxBFL[], resultNodes: any[]): number { const bflNodeNotFound = -1; diff --git a/src/main/wrapper/ExecutionService.ts b/src/main/wrapper/ExecutionService.ts index 8d48cf7f..f1191111 100644 --- a/src/main/wrapper/ExecutionService.ts +++ b/src/main/wrapper/ExecutionService.ts @@ -10,6 +10,8 @@ import CxCodeBashing from "../codebashing/CxCodeBashing"; import CxBFL from "../bfl/CxBFL"; import spawner = require('child_process'); import CxKicsRealTime from "../kicsRealtime/CxKicsRealTime"; +import CxLearnMoreDescriptions from "../learnmore/CxLearnMoreDescriptions"; +import {CxConstants} from "./CxConstants"; import CxData from "../results/CxData"; import CxScaPackageData from "../results/CxScaPackageData"; import CxVulnerabilityDetails from "../results/CxVulnerabilityDetails"; @@ -20,6 +22,7 @@ import CxKicsRemediation from "../remediation/CxKicsRemediation"; + function isJsonString(s: string) { try { const stringObject = s.split('\n')[0]; @@ -127,31 +130,35 @@ export class ExecutionService { if (data) { const resultObject = JSON.parse(data); switch (output) { - case "CxScan": + case CxConstants.SCAN_TYPE: const scans = CxScan.parseProject(resultObject); cxCommandOutput.payload = scans; break; - case "CxProject": + case CxConstants.PROJECT_TYPE: const projects = CxProject.parseProject(resultObject); cxCommandOutput.payload = projects; break; - case "CxCodeBashing": + case CxConstants.CODE_BASHING_TYPE: const codeBashing = CxCodeBashing.parseCodeBashing(resultObject); cxCommandOutput.payload = codeBashing; break; - case "CxBFL": + case CxConstants.BFL_TYPE: const bflNode = CxBFL.parseBFLResponse(resultObject); cxCommandOutput.payload = bflNode; break; - case "CxKicsRealTime": + case CxConstants.KICS_REALTIME_TYPE: const kicsResults = CxKicsRealTime.parseKicsRealTimeResponse(resultObject); cxCommandOutput.payload = [kicsResults]; break; - case "CxKicsRemediation": - const kicsRemediationOutput = CxKicsRemediation.parseKicsRemediation(resultObject) - cxCommandOutput.payload = [kicsRemediationOutput] - break; - default: + case CxConstants.LEARN_MORE_DESCRIPTIONS_TYPE: + const learnMore = CxLearnMoreDescriptions.parseLearnMoreDescriptionsResponse(resultObject); + cxCommandOutput.payload = learnMore; + break; + case CxConstants.KICS_REMEDIATION_TYPE: + const kicsRemediationOutput = CxKicsRemediation.parseKicsRemediation(resultObject) + cxCommandOutput.payload = [kicsRemediationOutput] + break; + default: cxCommandOutput.payload = resultObject; } } diff --git a/src/tests/LearnMoreDescriptions.test.ts b/src/tests/LearnMoreDescriptions.test.ts new file mode 100644 index 00000000..4d2a689f --- /dev/null +++ b/src/tests/LearnMoreDescriptions.test.ts @@ -0,0 +1,21 @@ +import {BaseTest} from "./BaseTest"; +import {CxWrapper} from "../main/wrapper/CxWrapper"; +import {CxCommandOutput} from "../main/wrapper/CxCommandOutput"; + +describe("LearnMoreDescriptions cases",() => { + const cxScanConfig = new BaseTest(); + it('LearnMoreDescriptions Successful case', async () => { + const auth = new CxWrapper(cxScanConfig); + const queryId = process.env.CX_TEST_QUERY_ID; + const data = await auth.learnMore(queryId !== undefined? queryId : "16772998409937314312") + const cxCommandOutput: CxCommandOutput = data; + expect(cxCommandOutput.payload.length).toBeGreaterThan(0); + }) + + it('LearnMoreDescriptions Failure case', async () => { + const auth = new CxWrapper(cxScanConfig); + const data = await auth.learnMore("") + const cxCommandOutput: CxCommandOutput = data; + expect(cxCommandOutput.status).toBe("Value of query-id is invalid\n"); + }) +})