Skip to content

Commit fa54223

Browse files
author
Jay Nanduri
committed
add learn more descriptions command to wrapper and tests
1 parent 9b3a161 commit fa54223

File tree

6 files changed

+75
-8
lines changed

6 files changed

+75
-8
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import CxLearnMoreSamples from "./CxLearnMoreSamples";
2+
3+
export default class CxLearnMoreDescriptions {
4+
queryId: string;
5+
queryName: string;
6+
queryDescriptionId: string;
7+
resultDescription: string;
8+
risk: string;
9+
cause: string;
10+
generalRecommendations: string;
11+
samples: CxLearnMoreSamples[];
12+
13+
static parseLearnMoreDescriptionsResponse(result: any): CxLearnMoreDescriptions {
14+
const cxLearnMoreDescriptions = new CxLearnMoreDescriptions();
15+
cxLearnMoreDescriptions.queryId = result.queryId;
16+
cxLearnMoreDescriptions.queryName = result.queryName;
17+
cxLearnMoreDescriptions.queryDescriptionId = result.queryDescriptionId;
18+
cxLearnMoreDescriptions.resultDescription = result.resultDescription;
19+
cxLearnMoreDescriptions.risk = result.risk;
20+
cxLearnMoreDescriptions.cause = result.cause;
21+
cxLearnMoreDescriptions.generalRecommendations = result.generalRecommendations;
22+
cxLearnMoreDescriptions.samples = result.samples;
23+
return cxLearnMoreDescriptions;
24+
}
25+
26+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default class CxLearnMoreSamples {
2+
progLanguage: string;
3+
code: string;
4+
title: string;
5+
}

src/main/wrapper/CxConstants.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export enum CxConstants {
5656
PREDICATE_TYPE = "CxPredicate",
5757
CODE_BASHING_TYPE = "CxCodeBashing",
5858
KICS_REALTIME_TYPE = "CxKicsRealTime",
59+
LEARN_MORE_DESCRIPTIONS_TYPE = "CxLearnMoreDescriptions",
5960
BFL_TYPE = "CxBFL",
6061
SAST = "sast",
6162
LANGUAGE = "--language",
@@ -64,5 +65,8 @@ export enum CxConstants {
6465

6566
SEVERITY_HIGH = "high",
6667
SEVERITY_MEDIUM = "medium",
67-
STATE_CONFIRMED = "confirmed"
68+
STATE_CONFIRMED = "confirmed",
69+
70+
CMD_UTILS = "utils",
71+
CMD_LEARN_MORE = "learn-more"
6872
}

src/main/wrapper/CxWrapper.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import { CxConfig } from "./CxConfig";
2-
import { CxParamType } from "./CxParamType";
3-
import { CxConstants } from "./CxConstants";
4-
import { ExecutionService } from "./ExecutionService";
5-
import { CxCommandOutput } from "./CxCommandOutput";
6-
import path = require('path');
7-
import { getLoggerWithFilePath, logger } from "./loggerConfig";
1+
import {CxConfig} from "./CxConfig";
2+
import {CxParamType} from "./CxParamType";
3+
import {CxConstants} from "./CxConstants";
4+
import {ExecutionService} from "./ExecutionService";
5+
import {CxCommandOutput} from "./CxCommandOutput";
6+
import {getLoggerWithFilePath, logger} from "./loggerConfig";
87
import * as fs from "fs"
98
import * as os from "os";
109
import CxBFL from "../bfl/CxBFL";
10+
import path = require('path');
1111

1212
type ParamTypeMap = Map<CxParamType, string>;
1313

@@ -247,6 +247,12 @@ export class CxWrapper {
247247
return exec.executeKicsCommands(this.config.pathToExecutable, commands, CxConstants.KICS_REALTIME_TYPE);
248248
}
249249

250+
async learnMore(queryId: string){
251+
const commands: string[] = [CxConstants.CMD_UTILS,CxConstants.CMD_LEARN_MORE,CxConstants.QUERY_ID,queryId]
252+
commands.push(...this.initializeCommands(true))
253+
const exec = new ExecutionService();
254+
return exec.executeCommands(this.config.pathToExecutable, commands, CxConstants.LEARN_MORE_DESCRIPTIONS_TYPE);
255+
}
250256
getIndexOfBflNode(bflNodes: CxBFL[], resultNodes: any[]): number {
251257

252258
const bflNodeNotFound = -1;

src/main/wrapper/ExecutionService.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import CxCodeBashing from "../codebashing/CxCodeBashing";
1010
import CxBFL from "../bfl/CxBFL";
1111
import spawner = require('child_process');
1212
import CxKicsRealTime from "../kicsRealtime/CxKicsRealTime";
13+
import CxLearnMoreDescriptions from "../learnmore/CxLearnMoreDescriptions";
1314

1415

1516

@@ -140,6 +141,10 @@ export class ExecutionService {
140141
const kicsResults = CxKicsRealTime.parseKicsRealTimeResponse(resultObject);
141142
cxCommandOutput.payload = [kicsResults];
142143
break;
144+
case "cxLearnMoreDescriptions":
145+
const learnMore = CxLearnMoreDescriptions.parseLearnMoreDescriptionsResponse(resultObject);
146+
cxCommandOutput.payload = [learnMore];
147+
break;
143148
default:
144149
cxCommandOutput.payload = resultObject;
145150
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import {BaseTest} from "./BaseTest";
2+
import {CxWrapper} from "../main/wrapper/CxWrapper";
3+
import {CxCommandOutput} from "../main/wrapper/CxCommandOutput";
4+
5+
describe("LearnMoreDescriptions cases",() => {
6+
const cxScanConfig = new BaseTest();
7+
it('LearnMoreDescriptions Successful case', async () => {
8+
const auth = new CxWrapper(cxScanConfig);
9+
const queryId = process.env.CX_TEST_QUERY_ID;
10+
const data = await auth.learnMore(queryId !== undefined? queryId : "10308959669028119927")
11+
const cxCommandOutput: CxCommandOutput = data;
12+
expect(cxCommandOutput.payload.length).toBeGreaterThan(0);
13+
})
14+
15+
it('LearnMoreDescriptions Failure case', async () => {
16+
const auth = new CxWrapper(cxScanConfig);
17+
const data = await auth.learnMore("")
18+
const cxCommandOutput: CxCommandOutput = data;
19+
expect(cxCommandOutput.status).toBe("Value of query-id is invalid\n");
20+
})
21+
})

0 commit comments

Comments
 (0)