From 70c6c4370633fd6df0df5ae1562fd923ca00b570 Mon Sep 17 00:00:00 2001 From: Jay Nanduri Date: Mon, 30 Aug 2021 11:25:52 -0400 Subject: [PATCH 1/6] check the integration tests --- .github/workflows/main.yml | 2 +- src/main/CxAuth.ts | 9 +++++++++ src/main/CxScanConfig.ts | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a36f2e13..89f518b4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -5,7 +5,7 @@ name: Integration Tests on: push: - branches: [ master ] + branches: [ add-tenant ] pull_request: branches: [ master ] diff --git a/src/main/CxAuth.ts b/src/main/CxAuth.ts index d788e08f..ae82e55b 100644 --- a/src/main/CxAuth.ts +++ b/src/main/CxAuth.ts @@ -16,6 +16,7 @@ export class CxAuth { apiKey: string = ""; commands: string[] = []; pathToExecutable: string; + tenant: string; constructor(cxScanConfig: CxScanConfig) { let path = require("path"); @@ -48,6 +49,10 @@ export class CxAuth { if (cxScanConfig.baseUri !== null && cxScanConfig.baseUri !== '') { this.baseUri = cxScanConfig.baseUri; } + + if (cxScanConfig.tenant !== null && cxScanConfig.tenant !== '') { + this.tenant = cxScanConfig.tenant; + } } initializeCommands(formatRequired: boolean): string[] { @@ -68,6 +73,10 @@ export class CxAuth { list.push("--base-uri"); list.push(this.baseUri); } + if (this.tenant !== null && this.tenant.length > 1) { + list.push("--tenant"); + list.push(this.tenant); + } if (formatRequired) { list.push("--format"); list.push("json"); diff --git a/src/main/CxScanConfig.ts b/src/main/CxScanConfig.ts index 33134c7b..48216071 100644 --- a/src/main/CxScanConfig.ts +++ b/src/main/CxScanConfig.ts @@ -4,4 +4,5 @@ export class CxScanConfig { clientId: string = " "; clientSecret: string = " "; apiKey: string = " "; + tenant:string =" "; } \ No newline at end of file From ebc58595bd645c1f608481ca89c8bfbb6c500e36 Mon Sep 17 00:00:00 2001 From: Jay Nanduri Date: Mon, 30 Aug 2021 11:30:31 -0400 Subject: [PATCH 2/6] updated package.json with new version --- .github/workflows/main.yml | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 89f518b4..a36f2e13 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -5,7 +5,7 @@ name: Integration Tests on: push: - branches: [ add-tenant ] + branches: [ master ] pull_request: branches: [ master ] diff --git a/package.json b/package.json index 4a465536..1b30cba2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@CheckmarxDev/ast-cli-javascript-wrapper", - "version": "0.0.24", + "version": "0.0.25", "description": "AST CLI Javascript wrapper", "main": "dist/CxAuth.js", "typings": "dist/CxAuth.d.ts", From 542068b3f1c20dc0d97d9a017c143c1dbbbcf378 Mon Sep 17 00:00:00 2001 From: Jay Nanduri Date: Mon, 30 Aug 2021 11:30:57 -0400 Subject: [PATCH 3/6] package lock added --- package-lock.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index f9dbcf25..0af9da01 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@CheckmarxDev/ast-cli-javascript-wrapper", - "version": "0.0.23", + "version": "0.0.24", "lockfileVersion": 1, "requires": true, "dependencies": { From d77b426a8d265733ce9ae080cf71a0466c2cefa5 Mon Sep 17 00:00:00 2001 From: Jay Nanduri Date: Mon, 30 Aug 2021 12:05:08 -0400 Subject: [PATCH 4/6] check tenant changes --- .github/workflows/main.yml | 2 +- src/main/CxAuth.ts | 32 ++++++++++++++++---------------- src/tests/CxAuthCall.test.ts | 1 + 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a36f2e13..89f518b4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -5,7 +5,7 @@ name: Integration Tests on: push: - branches: [ master ] + branches: [ add-tenant ] pull_request: branches: [ master ] diff --git a/src/main/CxAuth.ts b/src/main/CxAuth.ts index ae82e55b..ad98a240 100644 --- a/src/main/CxAuth.ts +++ b/src/main/CxAuth.ts @@ -20,18 +20,18 @@ export class CxAuth { constructor(cxScanConfig: CxScanConfig) { let path = require("path"); - if (cxScanConfig.clientId !== null && cxScanConfig.clientSecret !== null && cxScanConfig.clientId !== '' && cxScanConfig.clientId !== '') { + if (cxScanConfig.clientId && cxScanConfig.clientSecret) { console.log("Received clientId and clientSecret"); this.clientId = cxScanConfig.clientId; this.clientSecret = cxScanConfig.clientSecret; - } else if (cxScanConfig.apiKey != null) { + } else if (cxScanConfig.apiKey) { this.apiKey = cxScanConfig.apiKey; } else { console.log("Did not receive ClientId/Secret or ApiKey from cli arguments"); } let executablePath: string; - if (cxScanConfig.pathToExecutable !== null && cxScanConfig.pathToExecutable !== "") { + if (cxScanConfig.pathToExecutable) { this.pathToExecutable = cxScanConfig.pathToExecutable; } else if (process.platform === 'win32') { executablePath = path.join(__dirname, '/resources/cx.exe'); @@ -46,34 +46,34 @@ export class CxAuth { fs.chmodSync(this.pathToExecutable, 0o777); } - if (cxScanConfig.baseUri !== null && cxScanConfig.baseUri !== '') { + if (cxScanConfig.baseUri) { this.baseUri = cxScanConfig.baseUri; } - if (cxScanConfig.tenant !== null && cxScanConfig.tenant !== '') { + if (cxScanConfig.tenant) { this.tenant = cxScanConfig.tenant; } } initializeCommands(formatRequired: boolean): string[] { let list: string[] = []; - if (this.clientId !== null && this.clientId.length > 1) { + if (this.clientId) { list.push("--client-id"); list.push(this.clientId); } - if (this.clientSecret !== null && this.clientSecret.length > 1) { + if (this.clientSecret) { list.push("--client-secret"); list.push(this.clientSecret); } - if (this.apiKey !== null && this.apiKey.length > 1) { + if (this.apiKey) { list.push("--apikey"); list.push(this.apiKey); } - if (this.baseUri !== null && this.baseUri.length > 1) { + if (this.baseUri) { list.push("--base-uri"); list.push(this.baseUri); } - if (this.tenant !== null && this.tenant.length > 1) { + if (this.tenant) { list.push("--tenant"); list.push(this.tenant); } @@ -141,13 +141,13 @@ export class CxAuth { this.commands = this.initializeCommands(false); this.commands.push("result"); this.commands.push("list"); - if (scanId !== null && scanId !== "") { + if (scanId) { this.commands.push("--scan-id") this.commands.push(scanId) } else { console.log("Scan Id not provided") } - if (formatType !== null && formatType != '') { + if (formatType) { this.commands.push("--format") this.commands.push(formatType) } @@ -159,17 +159,17 @@ export class CxAuth { this.commands = this.initializeCommands(false); this.commands.push("result"); this.commands.push("summary"); - if (scanId !== null && scanId !== "") { + if (scanId) { this.commands.push("--scan-id") this.commands.push(scanId) } else { console.log("Scan Id not provided") } - if (formatType !== null && formatType != '') { + if (formatType) { this.commands.push("--format") this.commands.push(formatType) } - if (target !== null && target != '') { + if (target) { this.commands.push("--target") this.commands.push(target) } @@ -181,7 +181,7 @@ export class CxAuth { this.commands = this.initializeCommands(false); this.commands.push("result"); this.commands.push(resultParam); - if (targetPath !== null && targetPath !== "") { + if (targetPath) { this.commands.push("--target"); this.commands.push(targetPath); } diff --git a/src/tests/CxAuthCall.test.ts b/src/tests/CxAuthCall.test.ts index 2462b27c..2b0d6957 100644 --- a/src/tests/CxAuthCall.test.ts +++ b/src/tests/CxAuthCall.test.ts @@ -9,6 +9,7 @@ let cxScanConfig = new CxScanConfig(); cxScanConfig.baseUri = process.env["CX_BASE_URI"]; cxScanConfig.clientId = process.env["CX_CLIENT_ID"]; cxScanConfig.clientSecret = process.env["CX_CLIENT_SECRET"]; +cxScanConfig.tenant = "Galactica" if(process.env["PATH_TO_EXECUTABLE"] !== null && process.env["PATH_TO_EXECUTABLE"] !== undefined ) { cxScanConfig.pathToExecutable = process.env["PATH_TO_EXECUTABLE"]; } From 997683aa3318eb9ddc33745c49509b520d0693e7 Mon Sep 17 00:00:00 2001 From: Jay Nanduri Date: Mon, 30 Aug 2021 12:15:48 -0400 Subject: [PATCH 5/6] updated references --- .github/workflows/main.yml | 2 +- src/main/CxAuth.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 89f518b4..a36f2e13 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -5,7 +5,7 @@ name: Integration Tests on: push: - branches: [ add-tenant ] + branches: [ master ] pull_request: branches: [ master ] diff --git a/src/main/CxAuth.ts b/src/main/CxAuth.ts index ad98a240..b5c51e01 100644 --- a/src/main/CxAuth.ts +++ b/src/main/CxAuth.ts @@ -90,16 +90,16 @@ export class CxAuth { this.commands.push("scan"); this.commands.push("create"); params.forEach((value: string, key: CxParamType) => { - if (key !== CxParamType.ADDITIONAL_PARAMETERS && key.length !== 1 && value !== null && value !== undefined && value.length > 1) { + if (key !== CxParamType.ADDITIONAL_PARAMETERS && key.length !== 1 && value) { this.commands.push("--" + key.toString().replace(/_/g, "-").toLowerCase()); this.commands.push(value); - } else if (key.length === 1 && value !== null && value !== undefined) { + } else if (key.length === 1 && value) { this.commands.push("-" + key.toString().replace(/_/g, "-").toLowerCase()); this.commands.push(value); } else if (key === CxParamType.ADDITIONAL_PARAMETERS) { let paramList = value.match(/(?:[^\s"]+|"[^"]*")+/g); console.log("Additional parameters refined: " + paramList) - if (paramList !== null) { + if (paramList) { paramList.forEach((element) => { this.commands.push(element); }); From c61fb87113e138729ba73814db4fbd3063c81fae Mon Sep 17 00:00:00 2001 From: Jay Nanduri Date: Mon, 30 Aug 2021 13:38:20 -0400 Subject: [PATCH 6/6] changed integration tests to use tenant from env --- .github/workflows/main.yml | 1 + src/tests/CxAuthCall.test.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a36f2e13..3f6b78dd 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -37,6 +37,7 @@ jobs: CX_CLIENT_ID: ${{ secrets.CLIENT_ID}} CX_CLIENT_SECRET: ${{ secrets.CLIENT_SECRET}} CX_BASE_URI: ${{ secrets.BASE_URI }} + CX_TENANT: ${{ secrets.TENANT }} PATH_TO_EXECUTABLE: /tmp/cx-linux run: npm test \ No newline at end of file diff --git a/src/tests/CxAuthCall.test.ts b/src/tests/CxAuthCall.test.ts index 2b0d6957..9c33f4a1 100644 --- a/src/tests/CxAuthCall.test.ts +++ b/src/tests/CxAuthCall.test.ts @@ -9,7 +9,7 @@ let cxScanConfig = new CxScanConfig(); cxScanConfig.baseUri = process.env["CX_BASE_URI"]; cxScanConfig.clientId = process.env["CX_CLIENT_ID"]; cxScanConfig.clientSecret = process.env["CX_CLIENT_SECRET"]; -cxScanConfig.tenant = "Galactica" +cxScanConfig.tenant = process.env["CX_TENANT"]; if(process.env["PATH_TO_EXECUTABLE"] !== null && process.env["PATH_TO_EXECUTABLE"] !== undefined ) { cxScanConfig.pathToExecutable = process.env["PATH_TO_EXECUTABLE"]; }