-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScanTest.test.ts
More file actions
314 lines (257 loc) · 14.4 KB
/
ScanTest.test.ts
File metadata and controls
314 lines (257 loc) · 14.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
import { CxWrapper } from '../main/wrapper/CxWrapper';
import { CxCommandOutput } from "../main/wrapper/CxCommandOutput";
import { CxParamType } from "../main/wrapper/CxParamType";
import { BaseTest } from "./BaseTest";
import {OssPackage} from "./data/ossTypes";
import CxIacResult from "../main/iacRealtime/CxIac";
import CxContainerRealtimeResult from "../main/containersRealtime/CxContainerRealtime";
import CxAsca from '../main/asca/CxAsca';
describe("ScanCreate cases", () => {
const cxScanConfig = new BaseTest();
it('ScanList Successful case', async () => {
const auth = new CxWrapper(cxScanConfig);
const cxCommandOutput: CxCommandOutput = await auth.scanList("");
console.log(" Json object from scanList successful case: " + JSON.stringify(cxCommandOutput));
expect(cxCommandOutput.payload.length).toBeGreaterThan(1);
expect(cxCommandOutput.exitCode).toBe(0);
});
it('ScanCreate Successful case wait mode', async () => {
const params = new Map();
params.set(CxParamType.PROJECT_NAME, "ast-cli-javascript-integration-success");
params.set(CxParamType.S, "./src");
params.set(CxParamType.FILTER, "*.ts,!**/node_modules/**/*");
params.set(CxParamType.BRANCH, "master");
params.set(CxParamType.SCAN_TYPES,"kics");
const auth = new CxWrapper(cxScanConfig);
const cxCommandOutput: CxCommandOutput = await auth.scanCreate(params);
const scanObject = cxCommandOutput.payload.pop();
const scanShowObject = await auth.scanShow(scanObject.id);
console.log(" Json object from successful wait mode case: " + JSON.stringify(scanShowObject));
expect(scanShowObject.payload.pop().status).toEqual("Completed");
})
it('ScanCreate Failure case', async () => {
const params = new Map();
params.set(CxParamType.PROJECT_NAME, "ast-cli-javascript-integration-failure");
params.set(CxParamType.S, "./src");
params.set(CxParamType.SAST_PRESET_NAME, "Checkmarx Default Fake");
params.set(CxParamType.BRANCH, "master");
params.set(CxParamType.SCAN_TYPES, "sast");
const auth = new CxWrapper(cxScanConfig);
const cxCommandOutput: CxCommandOutput = await auth.scanCreate(params);
const scanObject = cxCommandOutput.payload.pop();
const scanShowObject = await auth.scanShow(scanObject.id);
console.log(" Json object from failure case: " + JSON.stringify(scanShowObject));
expect(scanShowObject.payload.pop().status).toEqual("Failed");
})
it('ScanCreate Successful case with Branch', async () => {
const params = new Map();
params.set(CxParamType.PROJECT_NAME, "ast-cli-javascript-integration-success-branch");
params.set(CxParamType.S, "./src");
params.set(CxParamType.FILTER, "*.ts,!**/node_modules/**/*");
params.set(CxParamType.BRANCH, "master");
params.set(CxParamType.ADDITIONAL_PARAMETERS, "--scan-types sast");
const auth = new CxWrapper(cxScanConfig);
const cxCommandOutput: CxCommandOutput = await auth.scanCreate(params);
const scanObject = cxCommandOutput.payload.pop();
const scanShowObject = await auth.scanShow(scanObject.id);
console.log(" Json object from successful wait mode case with branch: " + JSON.stringify(scanShowObject));
expect(scanShowObject.payload.pop().status).toEqual("Completed");
})
it('ScanCreate Successful case no wait mode', async () => {
const params = new Map();
params.set(CxParamType.PROJECT_NAME, "ast-cli-javascript-integration-nowait");
params.set(CxParamType.S, "./src");
params.set(CxParamType.SAST_PRESET_NAME, "Checkmarx Default Fake");
params.set(CxParamType.ADDITIONAL_PARAMETERS, "--async");
params.set(CxParamType.BRANCH, "master");
const auth = new CxWrapper(cxScanConfig);
const cxCommandOutput: CxCommandOutput = await auth.scanCreate(params);
const scanObject = cxCommandOutput.payload.pop();
const scanShowObject = await auth.scanShow(scanObject.id);
console.log(" Json object from successful no wait mode case: " + JSON.stringify(scanShowObject));
expect(scanShowObject.payload.pop().status).toEqual("Running");
})
it('ScanCancel Successful case', async () => {
const params = new Map();
params.set(CxParamType.PROJECT_NAME, "ast-cli-javascript-integration-cancel");
params.set(CxParamType.S, "./src");
params.set(CxParamType.BRANCH, "master");
params.set(CxParamType.FILTER, "*.ts,!**/node_modules/**/*");
params.set(CxParamType.ADDITIONAL_PARAMETERS, "--async");
const auth = new CxWrapper(cxScanConfig);
const cxCommandOutput: CxCommandOutput = await auth.scanCreate(params);
const scanObject = cxCommandOutput.payload.pop();
await auth.scanCancel(scanObject.id)
const scanShowObject = await auth.scanShow(scanObject.id);
expect(scanShowObject.exitCode).toEqual(0);
})
it('KicsRealtime Successful case ', async () => {
const auth = new CxWrapper(cxScanConfig);
const [outputProcess,pid] = await auth.kicsRealtimeScan("dist/tests/data/Dockerfile","docker","-v");
const cxCommandOutput: CxCommandOutput = await outputProcess;
console.log(" Json object from successful no wait mode case: " + JSON.stringify( cxCommandOutput.payload));
const scanObject = cxCommandOutput.payload.pop();
console.log(" Json object from successful no wait mode case: " + JSON.stringify(scanObject));
expect(scanObject.results.length).toBeGreaterThan(0);
expect(pid).toBeDefined();
})
it('ScaRealtime Successful case', async () => {
const wrapper = new CxWrapper(cxScanConfig);
const cxCommandOutput: CxCommandOutput = await wrapper.runScaRealtimeScan(process.cwd());
if(cxCommandOutput.exitCode == 1) {
expect(cxCommandOutput.payload).toBeUndefined();
} else {
const scanObject = cxCommandOutput.payload.pop();
expect(scanObject.results).toBeDefined();
}
})
it("Should check if scan create is possible", async() => {
const cxScanConfig = new BaseTest();
const auth = new CxWrapper(cxScanConfig);
const tenantSettings: boolean = await auth.ideScansEnabled();
expect(tenantSettings).toBeDefined();
})
it("Should check if AI guided remediation is active", async() => {
const cxScanConfig = new BaseTest();
const auth = new CxWrapper(cxScanConfig);
const aiEnabled: boolean = await auth.guidedRemediationEnabled();
expect(aiEnabled).toBeDefined();
})
it("Should check if AI MCP server is active", async () => {
const cxScanConfig = new BaseTest();
const auth = new CxWrapper(cxScanConfig);
const aiMcpEnabled: boolean = await auth.aiMcpServerEnabled();
expect(typeof aiMcpEnabled).toBe("boolean");
});
it('ScanAsca fail case Without extensions', async () => {
const auth = new CxWrapper(cxScanConfig);
const cxCommandOutput: CxCommandOutput = await auth.scanAsca("tsc/tests/data/python-file");
console.log(" Json object from failure case: " + JSON.stringify(cxCommandOutput));
expect(cxCommandOutput.payload[0].error.description).toEqual("The file name must have an extension.");
expect(cxCommandOutput.exitCode).toBe(0);
expect(cxCommandOutput.payload[0].status).toBeUndefined();
});
it('ScanAsca Successful case', async () => {
const auth = new CxWrapper(cxScanConfig);
const cxCommandOutput: CxCommandOutput = await auth.scanAsca("tsc/tests/data/python-vul-file.py");
console.log("Json object from scanAsca successful case: " + JSON.stringify(cxCommandOutput));
const scanObject = cxCommandOutput.payload.pop();
expect(cxCommandOutput.payload).toBeDefined();
expect(cxCommandOutput.exitCode).toBe(0);
expect(scanObject.status).toEqual(true);
});
it('ScanAsca with complex name Successful case', async () => {
const auth = new CxWrapper(cxScanConfig);
const cxCommandOutput: CxCommandOutput = await auth.scanAsca("tsc/tests/data/var express = require('express';.js");
console.log("Json object from scanAsca successful case: " + JSON.stringify(cxCommandOutput));
const scanObject = cxCommandOutput.payload.pop();
expect(cxCommandOutput.payload).toBeDefined();
expect(cxCommandOutput.exitCode).toBe(0);
expect(scanObject.status).toEqual(true);
});
it('ScanAsca Successful case with update version', async () => {
const auth = new CxWrapper(cxScanConfig);
const cxCommandOutput: CxCommandOutput = await auth.scanAsca("tsc/tests/data/python-vul-file.py", true);
console.log("Json object from scanAsca successful case with update version: " + JSON.stringify(cxCommandOutput));
const scanObject = cxCommandOutput.payload.pop();
expect(cxCommandOutput.payload).toBeDefined();
expect(cxCommandOutput.exitCode).toBe(0);
expect(scanObject.status).toEqual(true);
expect(Number.isInteger(scanObject.scanDetails[0].line)).toBe(true);
expect(typeof scanObject.scanDetails[0].description).toBe('string');
});
it('ScanOss Successful case', async () => {
const wrapper = new CxWrapper(cxScanConfig);
const cxCommandOutput: CxCommandOutput = await wrapper.ossScanResults("tsc/tests/data/package.json","");
console.log("Json object from scanOSS successful case: " + JSON.stringify(cxCommandOutput));
expect(cxCommandOutput.payload).toBeDefined();
expect(cxCommandOutput.exitCode).toBe(0);
});
it('ScanOss with ignored package should filter results', async () => {
const wrapper = new CxWrapper(cxScanConfig);
const sourceFile = "tsc/tests/data/package.json";
const ignoredFile = "tsc/tests/data/checkmarxIgnoredTempFile.json";
const cxCommandOutput: CxCommandOutput = await wrapper.ossScanResults(sourceFile, ignoredFile);
expect(cxCommandOutput.exitCode).toBe(0);
expect(cxCommandOutput.payload).toBeDefined();
const results = cxCommandOutput.payload as OssPackage[];
console.log("Filtered OSS packages:", results);
expect(results.length).toBe(1);
const hasCOA = results.some(pkg =>
pkg.PackageManager === "coa" && pkg.PackageVersion === "3.1.3"
);
expect(hasCOA).toBe(false);
});
it('ScanSecrets Successful case', async () => {
const wrapper = new CxWrapper(cxScanConfig);
const cxCommandOutput: CxCommandOutput = await wrapper.secretsScanResults("src/tests/data/secret-exposed.txt","");
console.log("Json object from scanOSS successful case: " + JSON.stringify(cxCommandOutput));
expect(cxCommandOutput.payload).toBeDefined();
expect(cxCommandOutput.exitCode).toBe(0);
});
it('ScanSecrets with ignore file filters the result', async () => {
const wrapper = new CxWrapper(cxScanConfig);
const cxCommandOutput: CxCommandOutput = await wrapper.secretsScanResults(
"src/tests/data/secret-exposed.txt",
"src/tests/data/ignoreFileSecrets.json"
);
console.log("Json object from scanSecrets with ignore file: " + JSON.stringify(cxCommandOutput));
expect(cxCommandOutput.payload).toBeDefined();
expect(Array.isArray(cxCommandOutput.payload)).toBe(true);
expect(cxCommandOutput.payload.pop().length).toBe(0);
expect(cxCommandOutput.exitCode).toBe(0);
});
it('ScanContainersRealtime Successful case', async () => {
const wrapper = new CxWrapper(cxScanConfig);
const cxCommandOutput: CxCommandOutput = await wrapper.containersRealtimeScanResults("src/tests/data/Dockerfile", "");
console.log("Json object from scanContainersRealtime successful case: " + JSON.stringify(cxCommandOutput));
expect(cxCommandOutput.payload).toBeDefined();
expect(cxCommandOutput.exitCode).toBe(0);
});
it.skip('ScanIacRealtime Successful case', async () => {
const wrapper = new CxWrapper(cxScanConfig);
const cxCommandOutput: CxCommandOutput = await wrapper.iacRealtimeScanResults("src/tests/data/Dockerfile", "docker","");
console.log("Json object from scanIacRealtime successful case: " + JSON.stringify(cxCommandOutput));
expect(cxCommandOutput.payload).toBeDefined();
expect(cxCommandOutput.exitCode).toBe(0);
});
it.skip('ScanIacRealtime with ignore file should filter results', async () => {
const wrapper = new CxWrapper(cxScanConfig);
const sourceFile = "src/tests/data/Dockerfile";
const ignoredFile = "src/tests/data/ignoredIacContainersAsca";
const cxCommandOutput: CxCommandOutput = await wrapper.iacRealtimeScanResults(sourceFile, "docker", ignoredFile);
expect(cxCommandOutput.exitCode).toBe(0);
expect(cxCommandOutput.payload).toBeDefined();
const findings = CxIacResult.parseResult(cxCommandOutput.payload);
console.log("Filtered IAC findings:", findings);
expect(findings.length).toBe(3);
});
it.skip('ScanContainersRealtime with ignored image should filter result', async () => {
const wrapper = new CxWrapper(cxScanConfig);
const sourceFile = "tsc/tests/data/Dockerfile";
const ignoredFile = "tsc/tests/data/ignoredIacContainersAsca.json";
const cxCommandOutput: CxCommandOutput = await wrapper.containersRealtimeScanResults(sourceFile, ignoredFile);
expect(cxCommandOutput.exitCode).toBe(0);
expect(cxCommandOutput.payload).toBeDefined();
const parsedResults = CxContainerRealtimeResult.parseResult(cxCommandOutput.payload[0]);
console.log("Filtered container results:", parsedResults);
expect(parsedResults.length).toBe(0);
});
it.skip('ScanAsca with ignore file should filter one result', async () => {
const wrapper = new CxWrapper(cxScanConfig);
const sourcePath = "tsc/tests/data/python-vul-file.py";
const ignoreFile = "tsc/tests/data/ignoredIacContainersAsca.json";
const cxCommandOutput: CxCommandOutput = await wrapper.scanAsca(
sourcePath,
false,
ignoreFile
);
expect(cxCommandOutput.exitCode).toBe(0);
expect(cxCommandOutput.payload).toBeDefined();
const parsed = CxAsca.parseScan(cxCommandOutput.payload[0]);
console.log("Filtered ASCA results:", parsed.scanDetails);
expect(parsed.status).toBe(true);
expect(Array.isArray(parsed.scanDetails)).toBe(true);
expect(parsed.scanDetails.length).toBe(5);
});
});