From 7f368bafefef94b32f65c77bad250bd7a542000b Mon Sep 17 00:00:00 2001 From: Anand Nandeshwar <73646287+cx-anand-nandeshwar@users.noreply.github.com> Date: Mon, 30 Nov 2026 17:16:31 +0530 Subject: [PATCH 1/2] - Added severity threshold parameter with the scanner command --- src/main/wrapper/CxConstants.ts | 1 + src/main/wrapper/CxWrapper.ts | 49 +++++++++++++------------- src/tests/ScanTest.test.ts | 62 +++++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+), 24 deletions(-) diff --git a/src/main/wrapper/CxConstants.ts b/src/main/wrapper/CxConstants.ts index 14cc2a1e..372d698b 100644 --- a/src/main/wrapper/CxConstants.ts +++ b/src/main/wrapper/CxConstants.ts @@ -91,6 +91,7 @@ export enum CxConstants { STATE_ID = "--state-id", COMMENT = "--comment", SEVERITY = "--severity", + SEVERITY_THRESHOLD = "--severity-threshold", REPORT_FORMAT = "--report-format", OUTPUT_NAME = "--output-name", OUTPUT_PATH = "--output-path", diff --git a/src/main/wrapper/CxWrapper.ts b/src/main/wrapper/CxWrapper.ts index 5768eff5..1e7c82b8 100644 --- a/src/main/wrapper/CxWrapper.ts +++ b/src/main/wrapper/CxWrapper.ts @@ -103,6 +103,13 @@ export class CxWrapper { return list; } + /** Pushes `flag value` onto `commands` when `value` is non-empty; a no-op otherwise. */ + private appendFlagIfPresent(commands: string[], flag: string, value?: string): void { + if (value) { + commands.push(flag, value); + } + } + async authValidate(): Promise { const commands: string[] = [CxConstants.CMD_AUTH, CxConstants.SUB_CMD_VALIDATE]; commands.push(...this.initializeCommands(false)); @@ -166,7 +173,8 @@ export class CxWrapper { async scanAsca( sourceFile: string, updateVersion = false, - ignoredFilePath?: string + ignoredFilePath?: string, + severityThreshold?: string ): Promise { const commands: string[] = [ CxConstants.CMD_SCAN, @@ -179,9 +187,8 @@ export class CxWrapper { commands.push(CxConstants.ASCA_UPDATE_VERSION); } - if (ignoredFilePath) { - commands.push(CxConstants.IGNORE__FILE_PATH, ignoredFilePath); - } + this.appendFlagIfPresent(commands, CxConstants.IGNORE__FILE_PATH, ignoredFilePath); + this.appendFlagIfPresent(commands, CxConstants.SEVERITY_THRESHOLD, severityThreshold); commands.push(...this.initializeCommands(false)); @@ -189,7 +196,7 @@ export class CxWrapper { return await exec.executeCommands(this.config.pathToExecutable, commands, CxConstants.SCAN_ASCA); } - async ossScanResults(sourceFile: string, ignoredFilePath?: string): Promise { + async ossScanResults(sourceFile: string, ignoredFilePath?: string, severityThreshold?: string): Promise { const commands: string[] = [ CxConstants.CMD_SCAN, CxConstants.CMD_OSS, @@ -197,10 +204,8 @@ export class CxWrapper { sourceFile ]; - if (ignoredFilePath) { - commands.push(CxConstants.IGNORE__FILE_PATH); - commands.push(ignoredFilePath); - } + this.appendFlagIfPresent(commands, CxConstants.IGNORE__FILE_PATH, ignoredFilePath); + this.appendFlagIfPresent(commands, CxConstants.SEVERITY_THRESHOLD, severityThreshold); commands.push(...this.initializeCommands(false)); @@ -210,7 +215,8 @@ export class CxWrapper { async containersRealtimeScanResults( sourceFile: string, - ignoredFilePath?: string + ignoredFilePath?: string, + severityThreshold?: string ): Promise { const commands: string[] = [ CxConstants.CMD_SCAN, @@ -219,10 +225,8 @@ export class CxWrapper { sourceFile ]; - if (ignoredFilePath) { - commands.push(CxConstants.IGNORE__FILE_PATH); - commands.push(ignoredFilePath); - } + this.appendFlagIfPresent(commands, CxConstants.IGNORE__FILE_PATH, ignoredFilePath); + this.appendFlagIfPresent(commands, CxConstants.SEVERITY_THRESHOLD, severityThreshold); commands.push(...this.initializeCommands(false)); @@ -233,7 +237,8 @@ export class CxWrapper { async iacRealtimeScanResults( sourceFile: string, engine: string, - ignoredFilePath?: string + ignoredFilePath?: string, + severityThreshold?: string ): Promise { const commands: string[] = [ CxConstants.CMD_SCAN, @@ -244,10 +249,8 @@ export class CxWrapper { engine ]; - if (ignoredFilePath) { - commands.push(CxConstants.IGNORE__FILE_PATH); - commands.push(ignoredFilePath); - } + this.appendFlagIfPresent(commands, CxConstants.IGNORE__FILE_PATH, ignoredFilePath); + this.appendFlagIfPresent(commands, CxConstants.SEVERITY_THRESHOLD, severityThreshold); commands.push(...this.initializeCommands(false)); @@ -255,7 +258,7 @@ export class CxWrapper { return await exec.executeCommands(this.config.pathToExecutable, commands, CxConstants.SCAN_IAC); } - async secretsScanResults(sourceFile: string, ignoredFilePath?: string): Promise { + async secretsScanResults(sourceFile: string, ignoredFilePath?: string, severityThreshold?: string): Promise { const commands: string[] = [ CxConstants.CMD_SCAN, CxConstants.CMD_SECRETS, @@ -263,10 +266,8 @@ export class CxWrapper { sourceFile ]; - if (ignoredFilePath) { - commands.push(CxConstants.IGNORE__FILE_PATH); - commands.push(ignoredFilePath); - } + this.appendFlagIfPresent(commands, CxConstants.IGNORE__FILE_PATH, ignoredFilePath); + this.appendFlagIfPresent(commands, CxConstants.SEVERITY_THRESHOLD, severityThreshold); commands.push(...this.initializeCommands(false)); diff --git a/src/tests/ScanTest.test.ts b/src/tests/ScanTest.test.ts index 360e2252..f8c498dd 100644 --- a/src/tests/ScanTest.test.ts +++ b/src/tests/ScanTest.test.ts @@ -308,7 +308,69 @@ it.skip('ScanAsca with ignore file should filter one result', async () => { expect(parsed.scanDetails.length).toBe(5); }); +// Severity threshold (--severity-threshold) is implemented in ast-cli (AST-193900/AST-195213) but not yet +// in the bundled cx.exe for this wrapper's pinned CLI version. Unskip once checkmarx-ast-cli.version is +// bumped to a release that includes it. +describe.skip("Severity threshold", () => { + const cxScanConfig = new BaseTest(); + + it('ScanAsca with severity threshold filters results', async () => { + const wrapper = new CxWrapper(cxScanConfig); + const cxCommandOutput: CxCommandOutput = await wrapper.scanAsca( + "tsc/tests/data/python-vul-file.py", + false, + "", + "high" + ); + expect(cxCommandOutput.exitCode).toBe(0); + expect(cxCommandOutput.payload).toBeDefined(); + }); + + it('ScanOss with severity threshold filters results', async () => { + const wrapper = new CxWrapper(cxScanConfig); + const cxCommandOutput: CxCommandOutput = await wrapper.ossScanResults( + "tsc/tests/data/package.json", + "", + "high" + ); + expect(cxCommandOutput.exitCode).toBe(0); + expect(cxCommandOutput.payload).toBeDefined(); + }); + + it('ScanSecrets with severity threshold filters results', async () => { + const wrapper = new CxWrapper(cxScanConfig); + const cxCommandOutput: CxCommandOutput = await wrapper.secretsScanResults( + "src/tests/data/secret-exposed.txt", + "", + "high" + ); + expect(cxCommandOutput.exitCode).toBe(0); + expect(cxCommandOutput.payload).toBeDefined(); + }); + it('ScanContainersRealtime with severity threshold filters results', async () => { + const wrapper = new CxWrapper(cxScanConfig); + const cxCommandOutput: CxCommandOutput = await wrapper.containersRealtimeScanResults( + "src/tests/data/Dockerfile", + "", + "high" + ); + expect(cxCommandOutput.exitCode).toBe(0); + expect(cxCommandOutput.payload).toBeDefined(); + }); + + it('ScanIacRealtime with severity threshold filters results', async () => { + const wrapper = new CxWrapper(cxScanConfig); + const cxCommandOutput: CxCommandOutput = await wrapper.iacRealtimeScanResults( + "src/tests/data/Dockerfile", + "docker", + "", + "high" + ); + expect(cxCommandOutput.exitCode).toBe(0); + expect(cxCommandOutput.payload).toBeDefined(); + }); +}); }); From 5994fa6be7ac19b0e2d58829f40190c25065055d Mon Sep 17 00:00:00 2001 From: Anand Nandeshwar <73646287+cx-anand-nandeshwar@users.noreply.github.com> Date: Mon, 30 Nov 2026 19:08:27 +0530 Subject: [PATCH 2/2] AST-195853: Fix severity-threshold test gaps - De-nest the skipped Severity threshold integration describe block from ScanCreate cases so it's a sibling, not accidentally nested. - Add SeverityThresholdArgsTest.test.ts: fast unit tests asserting the exact argv built for all five scan methods (with and without a threshold), using the repo's existing ExecutionService spy pattern. These run without a CLI binary that supports --severity-threshold, closing the gap left by the still-skipped integration tests. Co-Authored-By: Claude Sonnet 5 --- src/tests/ScanTest.test.ts | 7 +- src/tests/SeverityThresholdArgsTest.test.ts | 108 ++++++++++++++++++++ 2 files changed, 112 insertions(+), 3 deletions(-) create mode 100644 src/tests/SeverityThresholdArgsTest.test.ts diff --git a/src/tests/ScanTest.test.ts b/src/tests/ScanTest.test.ts index f8c498dd..7227b3f7 100644 --- a/src/tests/ScanTest.test.ts +++ b/src/tests/ScanTest.test.ts @@ -308,9 +308,12 @@ it.skip('ScanAsca with ignore file should filter one result', async () => { expect(parsed.scanDetails.length).toBe(5); }); +}); + // Severity threshold (--severity-threshold) is implemented in ast-cli (AST-193900/AST-195213) but not yet // in the bundled cx.exe for this wrapper's pinned CLI version. Unskip once checkmarx-ast-cli.version is -// bumped to a release that includes it. +// bumped to a release that includes it. Argument construction itself is covered, unskipped, by +// SeverityThresholdArgsTest.test.ts, which does not depend on the bundled CLI version. describe.skip("Severity threshold", () => { const cxScanConfig = new BaseTest(); @@ -372,5 +375,3 @@ describe.skip("Severity threshold", () => { }); }); -}); - diff --git a/src/tests/SeverityThresholdArgsTest.test.ts b/src/tests/SeverityThresholdArgsTest.test.ts new file mode 100644 index 00000000..5fad6aa9 --- /dev/null +++ b/src/tests/SeverityThresholdArgsTest.test.ts @@ -0,0 +1,108 @@ +import {CxWrapper} from '../main/wrapper/CxWrapper'; +import {CxConfig} from "../main/wrapper/CxConfig"; +import {CxCommandOutput} from "../main/wrapper/CxCommandOutput"; +import {ExecutionService} from "../main/wrapper/ExecutionService"; + +// These tests never run the real cx: they only check the arguments passed to ExecutionService, +// so they don't depend on whether the bundled CLI binary already supports --severity-threshold. +describe("Severity threshold arguments", () => { + afterEach(() => { + jest.restoreAllMocks(); + }); + + function wrapper(): CxWrapper { + const config = new CxConfig(); + config.pathToExecutable = process.execPath; + return new CxWrapper(config); + } + + function stubCommands(): jest.SpyInstance { + const done = new CxCommandOutput(); + done.exitCode = 0; + return jest.spyOn(ExecutionService.prototype, "executeCommands").mockResolvedValue(done); + } + + it('scanAsca appends --severity-threshold when given', async () => { + const spy = stubCommands(); + + await wrapper().scanAsca("file.py", false, "", "high"); + + expect(spy).toHaveBeenCalledWith( + process.execPath, + ["scan", "asca", "--file-source", "file.py", "--severity-threshold", "high"], + "CxAsca" + ); + }); + + it('scanAsca omits --severity-threshold when not given', async () => { + const spy = stubCommands(); + + await wrapper().scanAsca("file.py"); + + expect(spy).toHaveBeenCalledWith( + process.execPath, + ["scan", "asca", "--file-source", "file.py"], + "CxAsca" + ); + }); + + it('ossScanResults appends --severity-threshold after --ignored-file-path', async () => { + const spy = stubCommands(); + + await wrapper().ossScanResults("package.json", "ignored.json", "medium"); + + expect(spy).toHaveBeenCalledWith( + process.execPath, + ["scan", "oss-realtime", "-s", "package.json", "--ignored-file-path", "ignored.json", "--severity-threshold", "medium"], + "CxOss" + ); + }); + + it('containersRealtimeScanResults appends --severity-threshold', async () => { + const spy = stubCommands(); + + await wrapper().containersRealtimeScanResults("Dockerfile", "", "critical"); + + expect(spy).toHaveBeenCalledWith( + process.execPath, + ["scan", "containers-realtime", "-s", "Dockerfile", "--severity-threshold", "critical"], + "CxContainersRealtime" + ); + }); + + it('iacRealtimeScanResults appends --severity-threshold after --engine', async () => { + const spy = stubCommands(); + + await wrapper().iacRealtimeScanResults("Dockerfile", "docker", "", "low"); + + expect(spy).toHaveBeenCalledWith( + process.execPath, + ["scan", "iac-realtime", "-s", "Dockerfile", "--engine", "docker", "--severity-threshold", "low"], + "CxIac" + ); + }); + + it('secretsScanResults appends --severity-threshold', async () => { + const spy = stubCommands(); + + await wrapper().secretsScanResults("secret.txt", "", "informational"); + + expect(spy).toHaveBeenCalledWith( + process.execPath, + ["scan", "secrets-realtime", "-s", "secret.txt", "--severity-threshold", "informational"], + "CxSecrets" + ); + }); + + it('never sends an empty --severity-threshold value', async () => { + const spy = stubCommands(); + + await wrapper().ossScanResults("package.json", "", ""); + + expect(spy).toHaveBeenCalledWith( + process.execPath, + ["scan", "oss-realtime", "-s", "package.json"], + "CxOss" + ); + }); +});