Skip to content

Commit 3a54fa8

Browse files
authored
Merge branch 'main' into feature/saraChen/telemetryAIEvents
2 parents 5d83f8f + 5a23f6f commit 3a54fa8

File tree

10 files changed

+120
-24
lines changed

10 files changed

+120
-24
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: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
version https://git-lfs.github.com/spec/v1
2-
oid sha256:21771d942fb89bbd90c919037cda83447a1203cd326830434337c32a3492dc0f
3-
size 75620536
1+
oid sha256:3dc4decd7c938c329a672b42f273e5a439e39294d60f7adb81e6e79b7187b333
2+
size 75718840

src/main/wrapper/resources/cx-mac

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

src/main/wrapper/resources/cx.exe

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
version https://git-lfs.github.com/spec/v1
2-
oid sha256:4bbeacde274d8f70bc971071523ef2885bcaba7592a8f9108fe94af719028eac
3-
size 77585792
1+
oid sha256:14d343b959bcb155f03f2aa5f80fdb8e549b91827705051ef9455b6d67b12ad0
2+
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)