diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e63537c0..a36f2e13 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -39,10 +39,4 @@ jobs: CX_BASE_URI: ${{ secrets.BASE_URI }} PATH_TO_EXECUTABLE: /tmp/cx-linux run: npm test - - name: 'Upload Artifact' - uses: actions/upload-artifact@v2 - with: - name: cxAST.log - path: cxAST.log - retention-days: 30 \ No newline at end of file diff --git a/package.json b/package.json index 19f53e91..4a465536 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@CheckmarxDev/ast-cli-javascript-wrapper", - "version": "0.0.23", + "version": "0.0.24", "description": "AST CLI Javascript wrapper", "main": "dist/CxAuth.js", "typings": "dist/CxAuth.d.ts", @@ -21,7 +21,7 @@ "scripts": { "build": "tsc", "postbuild": "copyfiles -u 1 src/main/resources/cx* dist/", - "test": "jest" + "test": "tsc && jest" }, "repository": "https://github.com/CheckmarxDev/ast-cli-javascript-wrapper.git", "author": "Jay Nanduri", diff --git a/src/main/CxAuth.ts b/src/main/CxAuth.ts index 30b8ec30..d788e08f 100644 --- a/src/main/CxAuth.ts +++ b/src/main/CxAuth.ts @@ -30,7 +30,6 @@ export class CxAuth { } let executablePath: string; - if (cxScanConfig.pathToExecutable !== null && cxScanConfig.pathToExecutable !== "") { this.pathToExecutable = cxScanConfig.pathToExecutable; } else if (process.platform === 'win32') { @@ -39,19 +38,13 @@ export class CxAuth { } else if (process.platform === 'darwin') { executablePath = path.join(__dirname, '/resources/cx-mac'); this.pathToExecutable = executablePath; - fs.chmod(this.pathToExecutable, 7, function(err){ - console.log("Permission function output: ",err) - }) - } - else { - + fs.chmodSync(this.pathToExecutable, 0o777); + } else { executablePath = path.join(__dirname, '/resources/cx-linux'); this.pathToExecutable = executablePath; - fs.chmod(this.pathToExecutable, 7, function(err){ - console.log("Permission function output: ",err) - }) - + fs.chmodSync(this.pathToExecutable, 0o777); } + if (cxScanConfig.baseUri !== null && cxScanConfig.baseUri !== '') { this.baseUri = cxScanConfig.baseUri; } @@ -88,13 +81,13 @@ 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 !== null && value !== undefined && value.length > 1) { 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 !== null && value !== undefined) { this.commands.push("-" + key.toString().replace(/_/g, "-").toLowerCase()); this.commands.push(value); - } else if(key === CxParamType.ADDITIONAL_PARAMETERS) { + } else if (key === CxParamType.ADDITIONAL_PARAMETERS) { let paramList = value.match(/(?:[^\s"]+|"[^"]*")+/g); console.log("Additional parameters refined: " + paramList) if (paramList !== null) { @@ -139,42 +132,40 @@ export class CxAuth { this.commands = this.initializeCommands(false); this.commands.push("result"); this.commands.push("list"); - if(scanId !== null && scanId !== "") { + if (scanId !== null && scanId !== "") { this.commands.push("--scan-id") this.commands.push(scanId) - } - else{ + } else { console.log("Scan Id not provided") } - if(formatType !== null && formatType != '') { + if (formatType !== null && formatType != '') { this.commands.push("--format") this.commands.push(formatType) } let exec = new ExecutionService(); - return await exec.executeResultsCommands(this.pathToExecutable,this.commands) -} + return await exec.executeResultsCommands(this.pathToExecutable, this.commands) + } - async getResultsSummary(scanId: string, formatType: string, target:string) { + async getResultsSummary(scanId: string, formatType: string, target: string) { this.commands = this.initializeCommands(false); this.commands.push("result"); this.commands.push("summary"); - if(scanId !== null && scanId !== "") { + if (scanId !== null && scanId !== "") { this.commands.push("--scan-id") this.commands.push(scanId) - } - else{ + } else { console.log("Scan Id not provided") } - if(formatType !== null && formatType != '') { + if (formatType !== null && formatType != '') { this.commands.push("--format") this.commands.push(formatType) } - if(target !== null && target != '') { + if (target !== null && target != '') { this.commands.push("--target") this.commands.push(target) } let exec = new ExecutionService(); - return await exec.executeResultsCommands(this.pathToExecutable,this.commands) + return await exec.executeResultsCommands(this.pathToExecutable, this.commands) } async getResults(scanId: string, targetPath: string, resultParam: CxResultType) { diff --git a/src/main/CxAuthType.ts b/src/main/CxAuthType.ts deleted file mode 100644 index 3feffe7b..00000000 --- a/src/main/CxAuthType.ts +++ /dev/null @@ -1,3 +0,0 @@ -export enum CxAuthType { - TOKEN, KEYSECRET, ENVIRONMENT -} \ No newline at end of file diff --git a/src/main/CxParamType.ts b/src/main/CxParamType.ts index 596e21c2..1e301640 100644 --- a/src/main/CxParamType.ts +++ b/src/main/CxParamType.ts @@ -1,3 +1,4 @@ export enum CxParamType { - S = "S", V = "V", G = "G", PROJECT_NAME = "PROJECT_NAME", SCAN_TYPES = "SCAN_TYPES", SAST_PRESET_NAME = "SAST_PRESET_NAME", FILTER = "FILE_FILTER", DIRECTORY = "DIRECTORY", ADDITIONAL_PARAMETERS = "ADDITIONAL_PARAMETERS", AGENT = "AGENT", SOURCES = "FILE_SOURCE", TENANT = "TENANT", BRANCH = "BRANCH" + S = "S", V = "V", G = "G", PROJECT_NAME = "PROJECT_NAME", SCAN_TYPES = "SCAN_TYPES", SAST_PRESET_NAME = "SAST_PRESET_NAME", + FILTER = "FILE_FILTER", DIRECTORY = "DIRECTORY", ADDITIONAL_PARAMETERS = "ADDITIONAL_PARAMETERS", AGENT = "AGENT", SOURCES = "FILE_SOURCE", TENANT = "TENANT", BRANCH = "BRANCH" } \ No newline at end of file diff --git a/src/main/ExecutionService.ts b/src/main/ExecutionService.ts index 8bb131ce..6473533f 100644 --- a/src/main/ExecutionService.ts +++ b/src/main/ExecutionService.ts @@ -16,7 +16,6 @@ function isJsonString(s: string) { function transformation(commands: string[]):string[] { const result:string[] = commands.map(transform); - console.log(JSON.stringify(result)) return result; } @@ -42,17 +41,18 @@ export class ExecutionService { logger.info(stderr) }); cp.stdout.on('data', (data: any) => { - logger.info(`${data}`); - if (isJsonString(data.toString())) { - let resultObject = JSON.parse(data.toString().split('\n')[0]); - if (resultObject instanceof Array) { - logger.info(JSON.stringify(resultObject)) - cxCommandOutput.scanObjectList = resultObject - } else { - let resultArray: CxScan[] = []; - resultArray.push(resultObject); - cxCommandOutput.scanObjectList = resultArray; - + if (data) { + logger.info(`${data.toString().trim()}`); + if (isJsonString(data.toString())) { + let resultObject = JSON.parse(data.toString().split('\n')[0]); + if (resultObject instanceof Array) { + logger.info(JSON.stringify(resultObject)) + cxCommandOutput.scanObjectList = resultObject + } else { + let resultArray: CxScan[] = []; + resultArray.push(resultObject); + cxCommandOutput.scanObjectList = resultArray; + } } } }); diff --git a/src/tests/CxAuthCall.test.ts b/src/tests/CxAuthCall.test.ts index b4c56817..2462b27c 100644 --- a/src/tests/CxAuthCall.test.ts +++ b/src/tests/CxAuthCall.test.ts @@ -16,19 +16,19 @@ let params = new Map(); params.set(CxParamType.PROJECT_NAME, "ASTJSWrapperIntegrationTests"); params.set(CxParamType.SCAN_TYPES, "sast"); -params.set(CxParamType.S, "."); +params.set(CxParamType.S, "./src/tests"); params.set(CxParamType.FILTER, "*.ts,!**/node_modules/**/*"); const auth = new CxAuth(cxScanConfig); describe("ScanCreate cases",() => { it('ScanCreate Successful case wait mode', async () => { - const data = await auth.scanCreate(params); - const cxCommandOutput: CxCommandOutput =JSON.parse(JSON.stringify(data)) - const ScanObject = cxCommandOutput.scanObjectList.pop() - const scanShowObject = await auth.scanShow(ScanObject.ID); - console.log(" Json object from successful wait mode case: " + JSON.stringify(scanShowObject)) - expect(scanShowObject.scanObjectList.pop().Status).toEqual("Completed") -}) + const data = await auth.scanCreate(params); + const cxCommandOutput: CxCommandOutput =JSON.parse(JSON.stringify(data)) + const ScanObject = cxCommandOutput.scanObjectList.pop() + const scanShowObject = await auth.scanShow(ScanObject.ID); + console.log(" Json object from successful wait mode case: " + JSON.stringify(scanShowObject)) + expect(scanShowObject.scanObjectList.pop().Status).toEqual("Completed") + }) it('ScanCreate Successful case with Branch', async () => { params.set(CxParamType.BRANCH, "master"); @@ -43,7 +43,7 @@ describe("ScanCreate cases",() => { }) it('ScanCreate Failure case', async () => { - params.set(CxParamType.SAST_PRESET_NAME, "Checkmarx Default Jay"); + params.set(CxParamType.SAST_PRESET_NAME, "Checkmarx Default Fake"); const data = await auth.scanCreate(params); const cxCommandOutput: CxCommandOutput =JSON.parse(JSON.stringify(data)) const ScanObject = cxCommandOutput.scanObjectList.pop() @@ -54,6 +54,7 @@ describe("ScanCreate cases",() => { it('ScanCreate Successful case no wait mode', async () => { params.set(CxParamType.PROJECT_NAME, "ASTJSWrapperTestNoWait"); + params.set(CxParamType.SAST_PRESET_NAME, "Checkmarx Default"); params.set(CxParamType.ADDITIONAL_PARAMETERS, "--nowait"); const data = await auth.scanCreate(params); const cxCommandOutput: CxCommandOutput =JSON.parse(JSON.stringify(data))