Skip to content

Commit 5a23f6f

Browse files
cx-itay-pazItay Pazgithub-actionscx-daniel-greenspancx-ben-alvo
authored
Support Ignore file path for Oss real time and Secrets real time (#859)
* add support ignore file oss * revert secretsscanresults * change realse tag * Track Checkmarx CLI binaries with Git LFS * Update checkmarx-ast-cli to 2.3.27 * change to 2.3.27-itay pre ealse cli * remove exe files * change tag cli * Revert "remove exe files" This reverts commit d8c11d9. * revert tag * Update cx-mac * Update cx.exe * Update cx-linux * Update checkmarx-ast-cli.version * Update ScanTest.test.ts * add ignore file to secrets (#865) Co-authored-by: Itay Paz <itaypaz@Itays-MacBook-Pro-2.local> * add ignore secrets test * fix ignore file * change tag for pre prealse cli * Track Checkmarx CLI binaries with Git LFS * Update checkmarx-ast-cli to 2.3.27 * revert tag * Update checkmarx-ast-cli.version --------- Co-authored-by: Itay Paz <itaypaz@Itays-MacBook-Pro-2.local> Co-authored-by: github-actions <github-actions@github.com> Co-authored-by: Daniel Greenspan <33864348+cx-daniel-greenspan@users.noreply.github.com> Co-authored-by: Ben Alvo <144705560+cx-ben-alvo@users.noreply.github.com>
1 parent 3fb583d commit 5a23f6f

File tree

10 files changed

+121
-22
lines changed

10 files changed

+121
-22
lines changed

src/main/wrapper/CxConstants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export enum CxConstants {
2+
IGNORE__FILE_PATH = "--ignored-file-path",
23
SOURCE = "-s",
34
VERBOSE = "-v",
45
PROJECT_NAME = "--project-name",

src/main/wrapper/CxWrapper.ts

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export class CxWrapper {
5757
}
5858
}
5959

60-
60+
6161
initializeCommands(formatRequired: boolean): string[] {
6262
const list: string[] = [];
6363
if (this.config.clientId) {
@@ -149,20 +149,44 @@ export class CxWrapper {
149149
return await exec.executeCommands(this.config.pathToExecutable, commands, CxConstants.SCAN_ASCA);
150150
}
151151

152-
async ossScanResults(sourceFile: string): Promise<CxCommandOutput> {
153-
const commands: string[] = [CxConstants.CMD_SCAN, CxConstants.CMD_OSS, CxConstants.SOURCE, sourceFile];
154-
commands.push(...this.initializeCommands(false));
155-
const exec = new ExecutionService();
156-
return await exec.executeCommands(this.config.pathToExecutable, commands, CxConstants.SCAN_OSS);
152+
async ossScanResults(sourceFile: string, ignoredFilePath?: string): Promise<CxCommandOutput> {
153+
const commands: string[] = [
154+
CxConstants.CMD_SCAN,
155+
CxConstants.CMD_OSS,
156+
CxConstants.SOURCE,
157+
sourceFile
158+
];
159+
160+
if (ignoredFilePath) {
161+
commands.push(CxConstants.IGNORE__FILE_PATH);
162+
commands.push(ignoredFilePath);
157163
}
158164

159-
async secretsScanResults(sourceFile: string): Promise<CxCommandOutput> {
160-
const commands: string[] = [CxConstants.CMD_SCAN, CxConstants.CMD_SECRETS, CxConstants.SOURCE, sourceFile];
161-
commands.push(...this.initializeCommands(false));
162-
const exec = new ExecutionService();
163-
return await exec.executeCommands(this.config.pathToExecutable, commands, CxConstants.SCAN_SECRETS);
165+
commands.push(...this.initializeCommands(false));
166+
167+
const exec = new ExecutionService();
168+
return await exec.executeCommands(this.config.pathToExecutable, commands, CxConstants.SCAN_OSS);
169+
}
170+
171+
async secretsScanResults(sourceFile: string, ignoredFilePath?: string): Promise<CxCommandOutput> {
172+
const commands: string[] = [
173+
CxConstants.CMD_SCAN,
174+
CxConstants.CMD_SECRETS,
175+
CxConstants.SOURCE,
176+
sourceFile
177+
];
178+
179+
if (ignoredFilePath) {
180+
commands.push(CxConstants.IGNORE__FILE_PATH);
181+
commands.push(ignoredFilePath);
164182
}
165183

184+
commands.push(...this.initializeCommands(false));
185+
186+
const exec = new ExecutionService();
187+
return await exec.executeCommands(this.config.pathToExecutable, commands, CxConstants.SCAN_SECRETS);
188+
}
189+
166190
async scanCancel(id: string): Promise<CxCommandOutput> {
167191
const commands: string[] = [CxConstants.CMD_SCAN, CxConstants.SUB_CMD_CANCEL, CxConstants.SCAN_ID, id];
168192
commands.push(...this.initializeCommands(false));
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:c575ad83e1b594441fa60b9ced859709adaeb1fb82310c7a14cc03faf8bed385
3-
size 75616440
2+
oid sha256:3dc4decd7c938c329a672b42f273e5a439e39294d60f7adb81e6e79b7187b333
3+
size 75718840

src/main/wrapper/resources/cx-mac

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:a290c0a5147403168bf8f56bb6b7752e76a278ded9639f4b8563e4a0f8f77090
3-
size 152195792
2+
oid sha256:c7ffcb8755b167b5b6cc2c4610bc4ebe664af6974df2127092ef30c2b7b17223
3+
size 152395216

src/main/wrapper/resources/cx.exe

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:9cb276f871d8fc9460baef9d12f7aaf5773d133e3327a83d7cfd228db8aa0d97
3-
size 77584256
2+
oid sha256:14d343b959bcb155f03f2aa5f80fdb8e549b91827705051ef9455b6d67b12ad0
3+
size 77686208

src/tests/ScanTest.test.ts

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { CxWrapper } from '../main/wrapper/CxWrapper';
22
import { CxCommandOutput } from "../main/wrapper/CxCommandOutput";
33
import { CxParamType } from "../main/wrapper/CxParamType";
44
import { BaseTest } from "./BaseTest";
5+
import {OssPackage} from "./data/ossTypes";
56

67
describe("ScanCreate cases", () => {
78
const cxScanConfig = new BaseTest();
@@ -173,21 +174,58 @@ describe("ScanCreate cases", () => {
173174
expect(Number.isInteger(scanObject.scanDetails[0].line)).toBe(true);
174175
expect(typeof scanObject.scanDetails[0].description).toBe('string');
175176
});
176-
177+
177178
it('ScanOss Successful case', async () => {
178179
const wrapper = new CxWrapper(cxScanConfig);
179-
const cxCommandOutput: CxCommandOutput = await wrapper.ossScanResults("tsc/tests/data/package.json");
180+
const cxCommandOutput: CxCommandOutput = await wrapper.ossScanResults("tsc/tests/data/package.json","");
180181
console.log("Json object from scanOSS successful case: " + JSON.stringify(cxCommandOutput));
181182
expect(cxCommandOutput.payload).toBeDefined();
182183
expect(cxCommandOutput.exitCode).toBe(0);
183184
});
184185

185-
it.skip('ScanSecrets Successful case', async () => {
186+
it.skip('ScanOss with ignored package should filter results', async () => {
187+
const wrapper = new CxWrapper(cxScanConfig);
188+
const sourceFile = "tsc/tests/data/package.json";
189+
const ignoredFile = "tsc/tests/data/checkmarxIgnoredTempFile.json";
190+
191+
const cxCommandOutput: CxCommandOutput = await wrapper.ossScanResults(sourceFile, ignoredFile);
192+
193+
expect(cxCommandOutput.exitCode).toBe(0);
194+
expect(cxCommandOutput.payload).toBeDefined();
195+
196+
const results = cxCommandOutput.payload as OssPackage[];
197+
198+
console.log("Filtered OSS packages:", results);
199+
200+
expect(results.length).toBe(1);
201+
202+
const hasCOA = results.some(pkg =>
203+
pkg.PackageManager === "coa" && pkg.PackageVersion === "3.1.3"
204+
);
205+
expect(hasCOA).toBe(false);
206+
});
207+
208+
it('ScanSecrets Successful case', async () => {
186209
const wrapper = new CxWrapper(cxScanConfig);
187-
const cxCommandOutput: CxCommandOutput = await wrapper.secretsScanResults("src/tests/data/secret-exposed.txt");
210+
const cxCommandOutput: CxCommandOutput = await wrapper.secretsScanResults("src/tests/data/secret-exposed.txt","");
188211
console.log("Json object from scanOSS successful case: " + JSON.stringify(cxCommandOutput));
189212
expect(cxCommandOutput.payload).toBeDefined();
190213
expect(cxCommandOutput.exitCode).toBe(0);
191214
});
192215

216+
it.skip('ScanSecrets with ignore file filters the result', async () => {
217+
const wrapper = new CxWrapper(cxScanConfig);
218+
const cxCommandOutput: CxCommandOutput = await wrapper.secretsScanResults(
219+
"src/tests/data/secret-exposed.txt",
220+
"src/tests/data/ignoreFileSecrets.json"
221+
);
222+
223+
console.log("Json object from scanSecrets with ignore file: " + JSON.stringify(cxCommandOutput));
224+
expect(cxCommandOutput.payload).toBeDefined();
225+
expect(Array.isArray(cxCommandOutput.payload)).toBe(true);
226+
expect(cxCommandOutput.payload.length).toBe(0);
227+
expect(cxCommandOutput.exitCode).toBe(0);
193228
});
229+
230+
});
231+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[
2+
{
3+
"Title": "github-pat",
4+
"FilePath": "/Users/itaypaz/Library/CloudStorage/OneDrive-Checkmarx/Documents/jswrapper/ast-cli-javascript-wrapper/src/tests/data/secret-exposed.txt",
5+
"Line": 3
6+
}
7+
]

src/tests/data/ossTypes.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
export interface Location {
2+
Line: number;
3+
StartIndex: number;
4+
EndIndex: number;
5+
}
6+
7+
export interface Vulnerability {
8+
CVE: string;
9+
Description: string;
10+
Severity: string;
11+
}
12+
13+
export interface OssPackage {
14+
PackageManager: string;
15+
PackageName: string;
16+
PackageVersion: string;
17+
FilePath: string;
18+
Locations: Location[];
19+
Status: string;
20+
Vulnerabilities: Vulnerability[];
21+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[
2+
{
3+
"PackageManager": "npm",
4+
"PackageName": "coa",
5+
"PackageVersion": "3.1.3"
6+
}
7+
]

tsc/tests/data/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "0.0.1",
44
"description": "AST CLI Javascript wrapper tests",
55
"dependencies": {
6-
"log4js": "^6.9.1"
6+
"log4js": "^6.9.1",
7+
"coa":"3.1.3"
78
}
89
}

0 commit comments

Comments
 (0)