Skip to content

Commit aad6930

Browse files
Itay PazItay Paz
authored andcommitted
add support ignore file oss
1 parent 3fb583d commit aad6930

File tree

7 files changed

+76
-17
lines changed

7 files changed

+76
-17
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: 18 additions & 12 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,26 @@ 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);
157-
}
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+
];
158159

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);
160+
if (ignoredFilePath) {
161+
commands.push(CxConstants.IGNORE__FILE_PATH);
162+
commands.push(ignoredFilePath);
164163
}
165164

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+
166172
async scanCancel(id: string): Promise<CxCommandOutput> {
167173
const commands: string[] = [CxConstants.CMD_SCAN, CxConstants.SUB_CMD_CANCEL, CxConstants.SCAN_ID, id];
168174
commands.push(...this.initializeCommands(false));

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:b5c1762c7a739fbb292e270e674906d54eb8384650863aed8a5ca2e5d21d52c5
3+
size 152228816

src/tests/ScanTest.test.ts

Lines changed: 25 additions & 2 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,15 +174,37 @@ 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

186+
it('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+
185208
it.skip('ScanSecrets Successful case', async () => {
186209
const wrapper = new CxWrapper(cxScanConfig);
187210
const cxCommandOutput: CxCommandOutput = await wrapper.secretsScanResults("src/tests/data/secret-exposed.txt");

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)