Skip to content

Commit e8a3005

Browse files
cx-itay-pazItay Paz
andauthored
Fix Tenant settings request and added test (#842)
* fix pr * fix pr * Fix Tenant settings requests and add test --------- Co-authored-by: Itay Paz <[email protected]>
1 parent f0f91c2 commit e8a3005

File tree

4 files changed

+47
-19
lines changed

4 files changed

+47
-19
lines changed

src/main/wrapper/CxConstants.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ export enum CxConstants {
107107
SEVERITY_MEDIUM = "medium",
108108
STATE_CONFIRMED = "confirmed",
109109
CMD_LEARN_MORE = "learn-more",
110-
IDE_SCANS_KEY = " scan.config.plugins.ideScans",
111-
AI_GUIDED_REMEDIATION_KEY = " scan.config.plugins.aiGuidedRemediation",
110+
IDE_SCANS_KEY = "scan.config.plugins.ideScans",
111+
AI_GUIDED_REMEDIATION_KEY = "scan.config.plugins.aiGuidedRemediation",
112112
AI_MCP_SERVER_KEY = "scan.config.plugins.aiMcpServer"
113113

114114
}

src/main/wrapper/CxWrapper.ts

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import * as fs from "fs"
88
import * as os from "os";
99
import CxBFL from "../bfl/CxBFL";
1010
import path = require('path');
11+
import {getTrimmedMapValue} from "./utils";
1112

1213
type ParamTypeMap = Map<CxParamType, string>;
1314

@@ -56,6 +57,7 @@ export class CxWrapper {
5657
}
5758
}
5859

60+
5961
initializeCommands(formatRequired: boolean): string[] {
6062
const list: string[] = [];
6163
if (this.config.clientId) {
@@ -353,30 +355,38 @@ export class CxWrapper {
353355
return exec.executeCommands(this.config.pathToExecutable, commands);
354356
}
355357

356-
async ideScansEnabled() : Promise<boolean> {
357-
const commands: string[] = [CxConstants.CMD_UTILS, CxConstants.SUB_CMD_TENANT];
358-
commands.push(...this.initializeCommands(false));
359-
const exec = new ExecutionService();
360-
const output = await exec.executeMapTenantOutputCommands(this.config.pathToExecutable, commands);
361-
return output.has(CxConstants.IDE_SCANS_KEY) && output.get(CxConstants.IDE_SCANS_KEY).toLowerCase() === " true";
362-
}
358+
async ideScansEnabled(): Promise<boolean> {
359+
const commands: string[] = [CxConstants.CMD_UTILS, CxConstants.SUB_CMD_TENANT];
360+
commands.push(...this.initializeCommands(false));
363361

364-
async guidedRemediationEnabled() : Promise<boolean> {
365-
const commands: string[] = [CxConstants.CMD_UTILS, CxConstants.SUB_CMD_TENANT];
366-
commands.push(...this.initializeCommands(false));
367-
const exec = new ExecutionService();
368-
const output = await exec.executeMapTenantOutputCommands(this.config.pathToExecutable, commands);
369-
return output.has(CxConstants.AI_GUIDED_REMEDIATION_KEY) && output.get(CxConstants.AI_GUIDED_REMEDIATION_KEY).toLowerCase() === " true";
370-
}
362+
const exec = new ExecutionService();
363+
const output = await exec.executeMapTenantOutputCommands(this.config.pathToExecutable, commands);
371364

365+
const value = getTrimmedMapValue(output, CxConstants.IDE_SCANS_KEY);
366+
return value?.toLowerCase() === "true";
367+
}
372368

373-
async aiMcpServerEnabled(): Promise<boolean> {
369+
async guidedRemediationEnabled(): Promise<boolean> {
374370
const commands: string[] = [CxConstants.CMD_UTILS, CxConstants.SUB_CMD_TENANT];
375371
commands.push(...this.initializeCommands(false));
372+
376373
const exec = new ExecutionService();
377374
const output = await exec.executeMapTenantOutputCommands(this.config.pathToExecutable, commands);
378-
return output.has(CxConstants.AI_MCP_SERVER_KEY) &&
379-
output.get(CxConstants.AI_MCP_SERVER_KEY).toLowerCase() === "true";
375+
376+
const value = getTrimmedMapValue(output, CxConstants.AI_GUIDED_REMEDIATION_KEY);
377+
return value?.toLowerCase() === "true";
378+
}
379+
380+
381+
async aiMcpServerEnabled(): Promise<boolean> {
382+
const commands: string[] = [CxConstants.CMD_UTILS, CxConstants.SUB_CMD_TENANT];
383+
commands.push(...this.initializeCommands(false));
384+
385+
const exec = new ExecutionService();
386+
const output = await exec.executeMapTenantOutputCommands(this.config.pathToExecutable, commands);
387+
388+
const value = getTrimmedMapValue(output, CxConstants.AI_MCP_SERVER_KEY);
389+
return value?.toLowerCase() === "true";
380390
}
381391

382392
async kicsChat(apikey: string, file: string, line: number, severity: string, vulnerability: string, input: string, conversationId?: string, model?: string): Promise<CxCommandOutput> {

src/main/wrapper/utils.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export function getTrimmedMapValue(map: Map<string, string>, targetKey: string): string | undefined {
2+
const entries = Array.from(map.entries());
3+
4+
for (const [key, value] of entries) {
5+
if (key.trim() === targetKey) {
6+
return value.trim();
7+
}
8+
}
9+
10+
return undefined;
11+
}

src/tests/ScanTest.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,13 @@ describe("ScanCreate cases", () => {
125125
expect(aiEnabled).toBeDefined();
126126
})
127127

128+
it("Should check if AI MCP server is active", async () => {
129+
const cxScanConfig = new BaseTest();
130+
const auth = new CxWrapper(cxScanConfig);
131+
const aiMcpEnabled: boolean = await auth.aiMcpServerEnabled();
132+
expect(typeof aiMcpEnabled).toBe("boolean");
133+
});
134+
128135
it('ScanAsca fail case Without extensions', async () => {
129136
const auth = new CxWrapper(cxScanConfig);
130137
const cxCommandOutput: CxCommandOutput = await auth.scanAsca("tsc/tests/data/python-file");

0 commit comments

Comments
 (0)