From fa54223061a0f721ca611c62b4e0c7899ac0942c Mon Sep 17 00:00:00 2001 From: Jay Nanduri Date: Tue, 12 Jul 2022 16:54:20 -0400 Subject: [PATCH 1/4] add learn more descriptions command to wrapper and tests --- src/main/learnmore/CxLearnMoreDescriptions.ts | 26 +++++++++++++++++++ src/main/learnmore/CxLearnMoreSamples.ts | 5 ++++ src/main/wrapper/CxConstants.ts | 6 ++++- src/main/wrapper/CxWrapper.ts | 20 +++++++++----- src/main/wrapper/ExecutionService.ts | 5 ++++ src/tests/LearnMoreDescriptions.test.ts | 21 +++++++++++++++ 6 files changed, 75 insertions(+), 8 deletions(-) create mode 100644 src/main/learnmore/CxLearnMoreDescriptions.ts create mode 100644 src/main/learnmore/CxLearnMoreSamples.ts create mode 100644 src/tests/LearnMoreDescriptions.test.ts diff --git a/src/main/learnmore/CxLearnMoreDescriptions.ts b/src/main/learnmore/CxLearnMoreDescriptions.ts new file mode 100644 index 00000000..fe25b534 --- /dev/null +++ b/src/main/learnmore/CxLearnMoreDescriptions.ts @@ -0,0 +1,26 @@ +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(result: any): CxLearnMoreDescriptions { + 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; + } + +} \ No newline at end of file diff --git a/src/main/learnmore/CxLearnMoreSamples.ts b/src/main/learnmore/CxLearnMoreSamples.ts new file mode 100644 index 00000000..83a4569f --- /dev/null +++ b/src/main/learnmore/CxLearnMoreSamples.ts @@ -0,0 +1,5 @@ +export default class CxLearnMoreSamples { + progLanguage: string; + code: string; + title: string; +} \ No newline at end of file diff --git a/src/main/wrapper/CxConstants.ts b/src/main/wrapper/CxConstants.ts index 4e0521dc..365721ff 100644 --- a/src/main/wrapper/CxConstants.ts +++ b/src/main/wrapper/CxConstants.ts @@ -56,6 +56,7 @@ export enum CxConstants { PREDICATE_TYPE = "CxPredicate", CODE_BASHING_TYPE = "CxCodeBashing", KICS_REALTIME_TYPE = "CxKicsRealTime", + LEARN_MORE_DESCRIPTIONS_TYPE = "CxLearnMoreDescriptions", BFL_TYPE = "CxBFL", SAST = "sast", LANGUAGE = "--language", @@ -64,5 +65,8 @@ export enum CxConstants { SEVERITY_HIGH = "high", SEVERITY_MEDIUM = "medium", - STATE_CONFIRMED = "confirmed" + STATE_CONFIRMED = "confirmed", + + CMD_UTILS = "utils", + CMD_LEARN_MORE = "learn-more" } diff --git a/src/main/wrapper/CxWrapper.ts b/src/main/wrapper/CxWrapper.ts index 31e059f3..aa98d026 100644 --- a/src/main/wrapper/CxWrapper.ts +++ b/src/main/wrapper/CxWrapper.ts @@ -1,13 +1,13 @@ -import { CxConfig } from "./CxConfig"; -import { CxParamType } from "./CxParamType"; -import { CxConstants } from "./CxConstants"; -import { ExecutionService } from "./ExecutionService"; -import { CxCommandOutput } from "./CxCommandOutput"; -import path = require('path'); -import { getLoggerWithFilePath, logger } from "./loggerConfig"; +import {CxConfig} from "./CxConfig"; +import {CxParamType} from "./CxParamType"; +import {CxConstants} from "./CxConstants"; +import {ExecutionService} from "./ExecutionService"; +import {CxCommandOutput} from "./CxCommandOutput"; +import {getLoggerWithFilePath, logger} from "./loggerConfig"; import * as fs from "fs" import * as os from "os"; import CxBFL from "../bfl/CxBFL"; +import path = require('path'); type ParamTypeMap = Map; @@ -247,6 +247,12 @@ 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); + } getIndexOfBflNode(bflNodes: CxBFL[], resultNodes: any[]): number { const bflNodeNotFound = -1; diff --git a/src/main/wrapper/ExecutionService.ts b/src/main/wrapper/ExecutionService.ts index 9292ddd9..f5222cf0 100644 --- a/src/main/wrapper/ExecutionService.ts +++ b/src/main/wrapper/ExecutionService.ts @@ -10,6 +10,7 @@ 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"; @@ -140,6 +141,10 @@ export class ExecutionService { const kicsResults = CxKicsRealTime.parseKicsRealTimeResponse(resultObject); cxCommandOutput.payload = [kicsResults]; break; + case "cxLearnMoreDescriptions": + const learnMore = CxLearnMoreDescriptions.parseLearnMoreDescriptionsResponse(resultObject); + cxCommandOutput.payload = [learnMore]; + 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..3860deb8 --- /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 : "10308959669028119927") + 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"); + }) +}) \ No newline at end of file From 577cdad2510789b2d636dd8e08b05dfa75937475 Mon Sep 17 00:00:00 2001 From: Jay Nanduri Date: Fri, 15 Jul 2022 12:57:37 -0400 Subject: [PATCH 2/4] add new lines and change constant for learn more description case --- src/main/learnmore/CxLearnMoreDescriptions.ts | 2 +- src/main/learnmore/CxLearnMoreSamples.ts | 2 +- src/main/wrapper/ExecutionService.ts | 3 ++- src/tests/LearnMoreDescriptions.test.ts | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/learnmore/CxLearnMoreDescriptions.ts b/src/main/learnmore/CxLearnMoreDescriptions.ts index fe25b534..ba06022a 100644 --- a/src/main/learnmore/CxLearnMoreDescriptions.ts +++ b/src/main/learnmore/CxLearnMoreDescriptions.ts @@ -23,4 +23,4 @@ export default class CxLearnMoreDescriptions { return cxLearnMoreDescriptions; } -} \ No newline at end of file +} diff --git a/src/main/learnmore/CxLearnMoreSamples.ts b/src/main/learnmore/CxLearnMoreSamples.ts index 83a4569f..a92b75a9 100644 --- a/src/main/learnmore/CxLearnMoreSamples.ts +++ b/src/main/learnmore/CxLearnMoreSamples.ts @@ -2,4 +2,4 @@ export default class CxLearnMoreSamples { progLanguage: string; code: string; title: string; -} \ No newline at end of file +} diff --git a/src/main/wrapper/ExecutionService.ts b/src/main/wrapper/ExecutionService.ts index f5222cf0..055eb6ba 100644 --- a/src/main/wrapper/ExecutionService.ts +++ b/src/main/wrapper/ExecutionService.ts @@ -11,6 +11,7 @@ import CxBFL from "../bfl/CxBFL"; import spawner = require('child_process'); import CxKicsRealTime from "../kicsRealtime/CxKicsRealTime"; import CxLearnMoreDescriptions from "../learnmore/CxLearnMoreDescriptions"; +import {CxConstants} from "./CxConstants"; @@ -141,7 +142,7 @@ export class ExecutionService { const kicsResults = CxKicsRealTime.parseKicsRealTimeResponse(resultObject); cxCommandOutput.payload = [kicsResults]; break; - case "cxLearnMoreDescriptions": + case CxConstants.LEARN_MORE_DESCRIPTIONS_TYPE: const learnMore = CxLearnMoreDescriptions.parseLearnMoreDescriptionsResponse(resultObject); cxCommandOutput.payload = [learnMore]; break; diff --git a/src/tests/LearnMoreDescriptions.test.ts b/src/tests/LearnMoreDescriptions.test.ts index 3860deb8..3fc5c862 100644 --- a/src/tests/LearnMoreDescriptions.test.ts +++ b/src/tests/LearnMoreDescriptions.test.ts @@ -18,4 +18,4 @@ describe("LearnMoreDescriptions cases",() => { const cxCommandOutput: CxCommandOutput = data; expect(cxCommandOutput.status).toBe("Value of query-id is invalid\n"); }) -}) \ No newline at end of file +}) From 3b70d2e4f5bfc2982513242d7664c7f1e74007db Mon Sep 17 00:00:00 2001 From: tiagobcx Date: Mon, 29 Aug 2022 10:12:11 +0100 Subject: [PATCH 3/4] updating branch --- src/main/wrapper/ExecutionService.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/wrapper/ExecutionService.ts b/src/main/wrapper/ExecutionService.ts index 055eb6ba..c83a7f51 100644 --- a/src/main/wrapper/ExecutionService.ts +++ b/src/main/wrapper/ExecutionService.ts @@ -122,23 +122,23 @@ 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; From 9ff60fe783bc3d7bc8303ad22c454009bf947b67 Mon Sep 17 00:00:00 2001 From: tiagobcx Date: Mon, 29 Aug 2022 11:51:14 +0100 Subject: [PATCH 4/4] fixing undefined values in description --- src/main/learnmore/CxLearnMoreDescriptions.ts | 27 +++++++++++-------- src/main/wrapper/ExecutionService.ts | 2 +- src/tests/LearnMoreDescriptions.test.ts | 2 +- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/main/learnmore/CxLearnMoreDescriptions.ts b/src/main/learnmore/CxLearnMoreDescriptions.ts index ba06022a..c6abbe45 100644 --- a/src/main/learnmore/CxLearnMoreDescriptions.ts +++ b/src/main/learnmore/CxLearnMoreDescriptions.ts @@ -10,17 +10,22 @@ export default class CxLearnMoreDescriptions { generalRecommendations: string; samples: CxLearnMoreSamples[]; - static parseLearnMoreDescriptionsResponse(result: any): CxLearnMoreDescriptions { - 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; + 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/wrapper/ExecutionService.ts b/src/main/wrapper/ExecutionService.ts index 8a8b92bb..f1191111 100644 --- a/src/main/wrapper/ExecutionService.ts +++ b/src/main/wrapper/ExecutionService.ts @@ -152,7 +152,7 @@ export class ExecutionService { break; case CxConstants.LEARN_MORE_DESCRIPTIONS_TYPE: const learnMore = CxLearnMoreDescriptions.parseLearnMoreDescriptionsResponse(resultObject); - cxCommandOutput.payload = [learnMore]; + cxCommandOutput.payload = learnMore; break; case CxConstants.KICS_REMEDIATION_TYPE: const kicsRemediationOutput = CxKicsRemediation.parseKicsRemediation(resultObject) diff --git a/src/tests/LearnMoreDescriptions.test.ts b/src/tests/LearnMoreDescriptions.test.ts index 3fc5c862..4d2a689f 100644 --- a/src/tests/LearnMoreDescriptions.test.ts +++ b/src/tests/LearnMoreDescriptions.test.ts @@ -7,7 +7,7 @@ describe("LearnMoreDescriptions cases",() => { 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 : "10308959669028119927") + const data = await auth.learnMore(queryId !== undefined? queryId : "16772998409937314312") const cxCommandOutput: CxCommandOutput = data; expect(cxCommandOutput.payload.length).toBeGreaterThan(0); })