Skip to content

Commit 18407b8

Browse files
committed
make CxWrapperFactory.ts interface and object
1 parent a4cbc65 commit 18407b8

10 files changed

+62
-39
lines changed

src/main/wrapper/CxWrapperFactory.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
import {CxWrapper} from "./CxWrapper";
2-
import {CxConfig} from "./CxConfig";
1+
// ICxWrapperFactory.ts
2+
import { CxWrapper } from "./CxWrapper";
3+
import { CxConfig } from "./CxConfig";
34

4-
class CxWrapperFactory {
5-
static async createWrapper(cxScanConfig: CxConfig, logFilePath?: string): Promise<CxWrapper> {
5+
export interface ICxWrapperFactory {
6+
createWrapper(cxScanConfig: CxConfig, logFilePath?: string): Promise<CxWrapper>;
7+
}
8+
9+
class CxWrapperFactory implements ICxWrapperFactory {
10+
async createWrapper(cxScanConfig: CxConfig, logFilePath?: string): Promise<CxWrapper> {
611
const wrapper = await CxWrapper.getInstance(cxScanConfig, logFilePath);
712
await wrapper.init();
813
return wrapper;
914
}
1015
}
1116

12-
export default CxWrapperFactory;
17+
export default CxWrapperFactory;

src/tests/AuthTest.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ import {CxConfig} from "../main/wrapper/CxConfig";
33
import {BaseTest} from "./BaseTest";
44
import CxWrapperFactory from "../main/wrapper/CxWrapperFactory";
55

6+
const cxWrapperFactory = new CxWrapperFactory();
7+
68
describe("Authentication validation", () => {
79
const cxScanConfig = new BaseTest();
810
it('Result authentication successful case', async () => {
9-
const auth = await CxWrapperFactory.createWrapper(cxScanConfig);
11+
const auth = await cxWrapperFactory.createWrapper(cxScanConfig);
1012
const cxCommandOutput: CxCommandOutput = await auth.authValidate();
1113
expect(cxCommandOutput.exitCode).toBe(0);
1214
});
@@ -18,7 +20,7 @@ describe("Authentication validation", () => {
1820
cxScanConfig_fail.clientSecret = "error";
1921
cxScanConfig_fail.tenant = process.env["CX_TENANT"];
2022
cxScanConfig_fail.apiKey = "error";
21-
const auth = await CxWrapperFactory.createWrapper(cxScanConfig_fail);
23+
const auth = await cxWrapperFactory.createWrapper(cxScanConfig_fail);
2224
const cxCommandOutput: CxCommandOutput = await auth.authValidate();
2325
expect(cxCommandOutput.exitCode).toBe(1);
2426
});

src/tests/ChatTest.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ function createOutput(exitCode:number,payload:CxChat):CxCommandOutput {
1313
return output;
1414
}
1515

16+
const cxWrapperFactory = new CxWrapperFactory();
17+
1618
describe("Gpt Chat Cases", () => {
1719
// tests preparation
1820
const cxScanConfig = new BaseTest();
@@ -39,7 +41,7 @@ describe("Gpt Chat Cases", () => {
3941
});
4042

4143
it('KICS Gpt Chat Failed case', async () => {
42-
const originalWrapper: CxWrapper = await CxWrapperFactory.createWrapper(cxScanConfig);
44+
const originalWrapper: CxWrapper = await cxWrapperFactory.createWrapper(cxScanConfig);
4345
const cxCommandOutput = await originalWrapper.kicsChat(
4446
"APIKEY",
4547
"FILE",
@@ -55,7 +57,7 @@ describe("Gpt Chat Cases", () => {
5557
});
5658

5759
it('Sast Gpt Chat Failed case', async () => {
58-
const originalWrapper: CxWrapper = await CxWrapperFactory.createWrapper(cxScanConfig);
60+
const originalWrapper: CxWrapper = await cxWrapperFactory.createWrapper(cxScanConfig);
5961
const cxCommandOutput = await originalWrapper.sastChat(
6062
"APIKEY",
6163
"SOURCE_FILE",

src/tests/LearnMoreDescriptions.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,20 @@ import {BaseTest} from "./BaseTest";
22
import {CxCommandOutput} from "../main/wrapper/CxCommandOutput";
33
import CxWrapperFactory from "../main/wrapper/CxWrapperFactory";
44

5+
const cxWrapperFactory = new CxWrapperFactory();
6+
57
describe("LearnMoreDescriptions cases",() => {
68
const cxScanConfig = new BaseTest();
79
it('LearnMoreDescriptions Successful case', async () => {
8-
const auth = await CxWrapperFactory.createWrapper(cxScanConfig);
10+
const auth = await cxWrapperFactory.createWrapper(cxScanConfig);
911
const queryId = process.env.CX_TEST_QUERY_ID;
1012
const data = await auth.learnMore(queryId !== undefined? queryId : "16772998409937314312")
1113
const cxCommandOutput: CxCommandOutput = data;
1214
expect(cxCommandOutput.payload.length).toBeGreaterThan(0);
1315
})
1416

1517
it('LearnMoreDescriptions Failure case', async () => {
16-
const auth = await CxWrapperFactory.createWrapper(cxScanConfig);
18+
const auth = await cxWrapperFactory.createWrapper(cxScanConfig);
1719
const data = await auth.learnMore("")
1820
const cxCommandOutput: CxCommandOutput = data;
1921
expect(cxCommandOutput.status).toBe("Value of query-id is invalid\n");

src/tests/MaskTest.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ import {CxCommandOutput} from "../main/wrapper/CxCommandOutput";
22
import {BaseTest} from "./BaseTest";
33
import CxWrapperFactory from "../main/wrapper/CxWrapperFactory";
44

5+
const cxWrapperFactory = new CxWrapperFactory();
6+
57
describe("Mask cases",() => {
68
const cxScanConfig = new BaseTest();
79
it('Mask Successful case', async () => {
8-
const auth = await CxWrapperFactory.createWrapper(cxScanConfig);
10+
const auth = await cxWrapperFactory.createWrapper(cxScanConfig);
911
const data = await auth.maskSecrets("dist/tests/data/package.json")
1012
const cxCommandOutput: CxCommandOutput = data;
1113
expect(cxCommandOutput.payload.length).toEqual(1);

src/tests/PredicateTest.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import CxResult from '../main/results/CxResult';
44
import {CxConstants} from '../main/wrapper/CxConstants';
55
import CxWrapperFactory from "../main/wrapper/CxWrapperFactory";
66

7+
const cxWrapperFactory = new CxWrapperFactory();
8+
79
describe("Triage cases", () => {
810
const cxScanConfig = new BaseTest();
911

1012
it('Triage Successful case', async () => {
11-
const auth = await CxWrapperFactory.createWrapper(cxScanConfig);
13+
const auth = await cxWrapperFactory.createWrapper(cxScanConfig);
1214

1315
const scanList: CxCommandOutput = await auth.scanList("statuses=Completed,limit=100");
1416
let result: CxResult;

src/tests/ProjectTest.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ import {CxParamType} from "../main/wrapper/CxParamType";
44
import CxScan from "../main/scan/CxScan";
55
import CxWrapperFactory from "../main/wrapper/CxWrapperFactory";
66

7+
const cxWrapperFactory = new CxWrapperFactory();
8+
79
describe("ProjectList cases",() => {
810
const cxScanConfig = new BaseTest();
911
it('ProjectList Successful case', async () => {
10-
const auth = await CxWrapperFactory.createWrapper(cxScanConfig);
12+
const auth = await cxWrapperFactory.createWrapper(cxScanConfig);
1113
const data = await auth.projectList("");
1214
const cxCommandOutput: CxCommandOutput = data;
1315
expect(cxCommandOutput.payload.length).toBeGreaterThan(0);
@@ -19,7 +21,7 @@ describe("ProjectList cases",() => {
1921
params.set(CxParamType.S, "./src");
2022
params.set(CxParamType.FILTER, "*.ts,!**/node_modules/**/*");
2123
params.set(CxParamType.BRANCH, "master");
22-
const auth = await CxWrapperFactory.createWrapper(cxScanConfig);
24+
const auth = await cxWrapperFactory.createWrapper(cxScanConfig);
2325
const cxCommandOutput: CxCommandOutput = await auth.scanCreate(params);
2426
const scan: CxScan = cxCommandOutput.payload.pop();
2527

@@ -34,7 +36,7 @@ describe("ProjectList cases",() => {
3436
params.set(CxParamType.S, "./src");
3537
params.set(CxParamType.FILTER, "*.ts,!**/node_modules/**/*");
3638
params.set(CxParamType.BRANCH, "master");
37-
const auth = await CxWrapperFactory.createWrapper(cxScanConfig);
39+
const auth = await cxWrapperFactory.createWrapper(cxScanConfig);
3840
const cxCommandOutput: CxCommandOutput = await auth.scanCreate(params);
3941
const scan: CxScan = cxCommandOutput.payload.pop();
4042

src/tests/RemediationTest.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ import {CxCommandOutput} from "../main/wrapper/CxCommandOutput";
33
import CxKicsRemediation from "../main/remediation/CxKicsRemediation";
44
import CxWrapperFactory from "../main/wrapper/CxWrapperFactory";
55

6+
const cxWrapperFactory = new CxWrapperFactory();
7+
68
describe("SCA Remediation cases",() => {
79
const cxScanConfig = new BaseTest();
810
it('SCA Remediation Successful case ', async () => {
9-
const auth = await CxWrapperFactory.createWrapper(cxScanConfig);
11+
const auth = await cxWrapperFactory.createWrapper(cxScanConfig);
1012
const e:CxCommandOutput = await auth.scaRemediation("dist/tests/data/package.json","copyfiles","1.2")
1113
expect(e.exitCode).toBe(0);
1214
});
@@ -15,7 +17,7 @@ describe("SCA Remediation cases",() => {
1517
describe("Kics Remediation cases",() => {
1618
const cxScanConfig = new BaseTest();
1719
it('Kics Remediation Successful case', async () => {
18-
const auth = await CxWrapperFactory.createWrapper(cxScanConfig);
20+
const auth = await cxWrapperFactory.createWrapper(cxScanConfig);
1921
const e:[Promise<CxCommandOutput>,any] = await auth.kicsRemediation("dist/tests/data/results.json",__dirname+"/data","docker")
2022
const output = await e[0];
2123
const remediation: CxKicsRemediation = output.payload[0];
@@ -24,7 +26,7 @@ describe("Kics Remediation cases",() => {
2426
});
2527

2628
it('Kics Remediation Successful case with filter', async () => {
27-
const auth = await CxWrapperFactory.createWrapper(cxScanConfig);
29+
const auth = await cxWrapperFactory.createWrapper(cxScanConfig);
2830
const e:[Promise<CxCommandOutput>,any] = await auth.kicsRemediation("dist/tests/data/results.json",__dirname+"/data/","","9574288c118e8c87eea31b6f0b011295a39ec5e70d83fb70e839b8db4a99eba8")
2931
const output = await e[0];
3032
const remediation: CxKicsRemediation = output.payload[0];

src/tests/ResultTest.test.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ import {BaseTest} from "./BaseTest";
33
import * as fs from "fs";
44
import CxWrapperFactory from "../main/wrapper/CxWrapperFactory";
55

6+
const cxWrapperFactory = new CxWrapperFactory();
7+
68
describe("Results cases",() => {
79
const cxScanConfig = new BaseTest();
810
it('Result Test Successful case', async () => {
9-
const auth = await CxWrapperFactory.createWrapper(cxScanConfig);
11+
const auth = await cxWrapperFactory.createWrapper(cxScanConfig);
1012
const cxCommandOutput: CxCommandOutput = await auth.scanList("statuses=Completed");
1113
const sampleId = cxCommandOutput.payload.pop().id;
1214

@@ -16,7 +18,7 @@ describe("Results cases",() => {
1618
});
1719

1820
it('Result Test With Agent Flug Successful case', async () => {
19-
const auth = await CxWrapperFactory.createWrapper(cxScanConfig);
21+
const auth = await cxWrapperFactory.createWrapper(cxScanConfig);
2022
const cxCommandOutput: CxCommandOutput = await auth.scanList("statuses=Completed");
2123
const sampleId = cxCommandOutput.payload.pop().id;
2224

@@ -26,7 +28,7 @@ describe("Results cases",() => {
2628
});
2729

2830
it('Result List Successful case', async () => {
29-
const auth = await CxWrapperFactory.createWrapper(cxScanConfig);
31+
const auth = await cxWrapperFactory.createWrapper(cxScanConfig);
3032
const scanList: CxCommandOutput = await auth.scanList("statuses=Completed");
3133
let output;
3234
while (!output && scanList && scanList.payload && scanList.payload.length > 0) {
@@ -42,7 +44,7 @@ describe("Results cases",() => {
4244
});
4345

4446
it('Result summary html file generation successful case', async () => {
45-
const auth = await CxWrapperFactory.createWrapper(cxScanConfig);
47+
const auth = await cxWrapperFactory.createWrapper(cxScanConfig);
4648
const cxCommandOutput: CxCommandOutput = await auth.scanList("statuses=Completed");
4749
const sampleId = cxCommandOutput.payload.pop().id;
4850
await auth.getResults(sampleId,"summaryHTML","test", ".");
@@ -51,15 +53,15 @@ describe("Results cases",() => {
5153
});
5254

5355
it('Result summary html string successful case', async () => {
54-
const auth = await CxWrapperFactory.createWrapper(cxScanConfig);
56+
const auth = await cxWrapperFactory.createWrapper(cxScanConfig);
5557
const cxCommandOutput: CxCommandOutput = await auth.scanList("statuses=Completed");
5658
const sampleId = cxCommandOutput.payload.pop().id;
5759
const written = await auth.getResultsSummary(sampleId);
5860
expect(written.payload.length).toBeGreaterThan(0);
5961
});
6062

6163
it('Result codebashing successful case', async () => {
62-
const auth = await CxWrapperFactory.createWrapper(cxScanConfig);
64+
const auth = await cxWrapperFactory.createWrapper(cxScanConfig);
6365
const cxCommandOutput: CxCommandOutput = await auth.codeBashingList("79","PHP","Reflected XSS All Clients");
6466
expect(cxCommandOutput.payload.length).toBeGreaterThan(0);
6567
});

src/tests/ScanTest.test.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ import { CxParamType } from "../main/wrapper/CxParamType";
33
import { BaseTest } from "./BaseTest";
44
import CxWrapperFactory from "../main/wrapper/CxWrapperFactory";
55

6+
const cxWrapperFactory = new CxWrapperFactory();
7+
68
describe("ScanCreate cases", () => {
79
const cxScanConfig = new BaseTest();
810
it('ScanList Successful case', async () => {
9-
const auth = await CxWrapperFactory.createWrapper(cxScanConfig);
11+
const auth = await cxWrapperFactory.createWrapper(cxScanConfig);
1012
const cxCommandOutput: CxCommandOutput = await auth.scanList("");
1113
console.log(" Json object from scanList successful case: " + JSON.stringify(cxCommandOutput));
1214
expect(cxCommandOutput.payload.length).toBeGreaterThan(1);
@@ -20,7 +22,7 @@ describe("ScanCreate cases", () => {
2022
params.set(CxParamType.FILTER, "*.ts,!**/node_modules/**/*");
2123
params.set(CxParamType.BRANCH, "master");
2224
params.set(CxParamType.SCAN_TYPES,"kics");
23-
const auth = await CxWrapperFactory.createWrapper(cxScanConfig);
25+
const auth = await cxWrapperFactory.createWrapper(cxScanConfig);
2426
const cxCommandOutput: CxCommandOutput = await auth.scanCreate(params);
2527
const scanObject = cxCommandOutput.payload.pop();
2628
const scanShowObject = await auth.scanShow(scanObject.id);
@@ -35,7 +37,7 @@ describe("ScanCreate cases", () => {
3537
params.set(CxParamType.SAST_PRESET_NAME, "Checkmarx Default Fake");
3638
params.set(CxParamType.BRANCH, "master");
3739
params.set(CxParamType.SCAN_TYPES, "sast");
38-
const auth = await CxWrapperFactory.createWrapper(cxScanConfig);
40+
const auth = await cxWrapperFactory.createWrapper(cxScanConfig);
3941
const cxCommandOutput: CxCommandOutput = await auth.scanCreate(params);
4042
const scanObject = cxCommandOutput.payload.pop();
4143
const scanShowObject = await auth.scanShow(scanObject.id);
@@ -50,7 +52,7 @@ describe("ScanCreate cases", () => {
5052
params.set(CxParamType.FILTER, "*.ts,!**/node_modules/**/*");
5153
params.set(CxParamType.BRANCH, "master");
5254
params.set(CxParamType.ADDITIONAL_PARAMETERS, "--scan-types sast");
53-
const auth = await CxWrapperFactory.createWrapper(cxScanConfig);
55+
const auth = await cxWrapperFactory.createWrapper(cxScanConfig);
5456
const cxCommandOutput: CxCommandOutput = await auth.scanCreate(params);
5557
const scanObject = cxCommandOutput.payload.pop();
5658
const scanShowObject = await auth.scanShow(scanObject.id);
@@ -66,7 +68,7 @@ describe("ScanCreate cases", () => {
6668
params.set(CxParamType.SAST_PRESET_NAME, "Checkmarx Default Fake");
6769
params.set(CxParamType.ADDITIONAL_PARAMETERS, "--async");
6870
params.set(CxParamType.BRANCH, "master");
69-
const auth = await CxWrapperFactory.createWrapper(cxScanConfig);
71+
const auth = await cxWrapperFactory.createWrapper(cxScanConfig);
7072
const cxCommandOutput: CxCommandOutput = await auth.scanCreate(params);
7173
const scanObject = cxCommandOutput.payload.pop();
7274
const scanShowObject = await auth.scanShow(scanObject.id);
@@ -81,7 +83,7 @@ describe("ScanCreate cases", () => {
8183
params.set(CxParamType.BRANCH, "master");
8284
params.set(CxParamType.FILTER, "*.ts,!**/node_modules/**/*");
8385
params.set(CxParamType.ADDITIONAL_PARAMETERS, "--async");
84-
const auth = await CxWrapperFactory.createWrapper(cxScanConfig);
86+
const auth = await cxWrapperFactory.createWrapper(cxScanConfig);
8587
const cxCommandOutput: CxCommandOutput = await auth.scanCreate(params);
8688
const scanObject = cxCommandOutput.payload.pop();
8789
await auth.scanCancel(scanObject.id)
@@ -90,7 +92,7 @@ describe("ScanCreate cases", () => {
9092
})
9193

9294
it('KicsRealtime Successful case ', async () => {
93-
const auth = await CxWrapperFactory.createWrapper(cxScanConfig);
95+
const auth = await cxWrapperFactory.createWrapper(cxScanConfig);
9496
const [outputProcess,pid] = await auth.kicsRealtimeScan("dist/tests/data/Dockerfile","docker","-v");
9597
const cxCommandOutput: CxCommandOutput = await outputProcess;
9698
console.log(" Json object from successful no wait mode case: " + JSON.stringify( cxCommandOutput.payload));
@@ -101,7 +103,7 @@ describe("ScanCreate cases", () => {
101103
})
102104

103105
it('ScaRealtime Successful case', async () => {
104-
const wrapper = await CxWrapperFactory.createWrapper(cxScanConfig);
106+
const wrapper = await cxWrapperFactory.createWrapper(cxScanConfig);
105107
const cxCommandOutput: CxCommandOutput = await wrapper.runScaRealtimeScan(process.cwd());
106108
if(cxCommandOutput.exitCode == 1) {
107109
expect(cxCommandOutput.payload).toBeUndefined();
@@ -113,20 +115,20 @@ describe("ScanCreate cases", () => {
113115

114116
it("Should check if scan create is possible", async() => {
115117
const cxScanConfig = new BaseTest();
116-
const auth = await CxWrapperFactory.createWrapper(cxScanConfig);
118+
const auth = await cxWrapperFactory.createWrapper(cxScanConfig);
117119
const tenantSettings: boolean = await auth.ideScansEnabled();
118120
expect(tenantSettings).toBeDefined();
119121
})
120122

121123
it("Should check if AI guided remediation is active", async() => {
122124
const cxScanConfig = new BaseTest();
123-
const auth = await CxWrapperFactory.createWrapper(cxScanConfig);
125+
const auth = await cxWrapperFactory.createWrapper(cxScanConfig);
124126
const aiEnabled: boolean = await auth.guidedRemediationEnabled();
125127
expect(aiEnabled).toBeDefined();
126128
})
127129

128130
it('ScanVorpal fail case Without extensions', async () => {
129-
const auth = await CxWrapperFactory.createWrapper(cxScanConfig);
131+
const auth = await cxWrapperFactory.createWrapper(cxScanConfig);
130132
const cxCommandOutput: CxCommandOutput = await auth.scanVorpal("tsc/tests/data/python-file");
131133
console.log(" Json object from failure case: " + JSON.stringify(cxCommandOutput));
132134

@@ -136,7 +138,7 @@ describe("ScanCreate cases", () => {
136138
});
137139

138140
it('ScanVorpal Successful case', async () => {
139-
const auth = await CxWrapperFactory.createWrapper(cxScanConfig);
141+
const auth = await cxWrapperFactory.createWrapper(cxScanConfig);
140142
const cxCommandOutput: CxCommandOutput = await auth.scanVorpal("tsc/tests/data/python-vul-file.py");
141143
console.log("Json object from scanVorpal successful case: " + JSON.stringify(cxCommandOutput));
142144
const scanObject = cxCommandOutput.payload.pop();
@@ -146,7 +148,7 @@ describe("ScanCreate cases", () => {
146148
});
147149

148150
it('ScanVorpal with complex name Successful case', async () => {
149-
const auth = await CxWrapperFactory.createWrapper(cxScanConfig);
151+
const auth = await cxWrapperFactory.createWrapper(cxScanConfig);
150152
const cxCommandOutput: CxCommandOutput = await auth.scanVorpal("tsc/tests/data/var express = require('express';.js");
151153
console.log("Json object from scanVorpal successful case: " + JSON.stringify(cxCommandOutput));
152154
const scanObject = cxCommandOutput.payload.pop();
@@ -156,7 +158,7 @@ describe("ScanCreate cases", () => {
156158
});
157159

158160
it('ScanVorpal Successful case with update version', async () => {
159-
const auth = await CxWrapperFactory.createWrapper(cxScanConfig);
161+
const auth = await cxWrapperFactory.createWrapper(cxScanConfig);
160162
const cxCommandOutput: CxCommandOutput = await auth.scanVorpal("tsc/tests/data/python-vul-file.py", true);
161163
console.log("Json object from scanVorpal successful case with update version: " + JSON.stringify(cxCommandOutput));
162164
const scanObject = cxCommandOutput.payload.pop();

0 commit comments

Comments
 (0)