This repository was archived by the owner on Apr 23, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScanTest.test.ts
More file actions
178 lines (160 loc) · 9.12 KB
/
ScanTest.test.ts
File metadata and controls
178 lines (160 loc) · 9.12 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
import { CxWrapper } from '../main/wrapper/CxWrapper';
import { CxCommandOutput } from "../main/wrapper/CxCommandOutput";
import { CxParamType } from "../main/wrapper/CxParamType";
import { BaseTest } from "./BaseTest";
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('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 auth = new CxWrapper(cxScanConfig);
const cxCommandOutput: CxCommandOutput = await auth.scanOss("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);
});
});