Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@CheckmarxDev/ast-cli-javascript-wrapper",
"version": "0.0.22",
"version": "0.0.23",
"description": "AST CLI Javascript wrapper",
"main": "dist/CxAuth.js",
"typings": "dist/CxAuth.d.ts",
Expand Down
42 changes: 42 additions & 0 deletions src/main/CxAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,48 @@ export class CxAuth {
return await exec.executeCommands(this.pathToExecutable, this.commands);
}

async getResultsList(scanId: string, formatType: string) {
this.commands = this.initializeCommands(false);
this.commands.push("result");
this.commands.push("list");
if(scanId !== null && scanId !== "") {
this.commands.push("--scan-id")
this.commands.push(scanId)
}
else{
console.log("Scan Id not provided")
}
if(formatType !== null && formatType != '') {
this.commands.push("--format")
this.commands.push(formatType)
}
let exec = new ExecutionService();
return await exec.executeResultsCommands(this.pathToExecutable,this.commands)
}

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 !== "") {
this.commands.push("--scan-id")
this.commands.push(scanId)
}
else{
console.log("Scan Id not provided")
}
if(formatType !== null && formatType != '') {
this.commands.push("--format")
this.commands.push(formatType)
}
if(target !== null && target != '') {
this.commands.push("--target")
this.commands.push(target)
}
let exec = new ExecutionService();
return await exec.executeResultsCommands(this.pathToExecutable,this.commands)
}

async getResults(scanId: string, targetPath: string, resultParam: CxResultType) {
this.commands = this.initializeCommands(false);
this.commands.push("result");
Expand Down
31 changes: 31 additions & 0 deletions src/main/ExecutionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,22 @@ function isJsonString(s: string) {
return true;
}

function transformation(commands: string[]):string[] {
const result:string[] = commands.map(transform);
console.log(JSON.stringify(result))
return result;
}

function transform(n:string) {
return n.replace(/["']/g, "").replace("/[, ]/g",",")
}

export class ExecutionService {
executeCommands(pathToExecutable: string, commands: string[]): Promise<CxCommandOutput> {
return new Promise(function (resolve, reject) {
let stderr = '';
let cxCommandOutput = new CxCommandOutput();
commands = transformation(commands)
const cp = spawn(pathToExecutable, commands);
cp.stderr.on('data', function (chunk: string) {
stderr += chunk;
Expand Down Expand Up @@ -47,4 +58,24 @@ export class ExecutionService {
});
});
}
executeResultsCommands(pathToExecutable: string, commands: string[]): Promise<string> {
return new Promise(function (resolve, reject) {
let stderr = '';
let results:string = '';
const cp = spawn(pathToExecutable, commands);
cp.stderr.on('data', function (chunk: string) {
stderr += chunk;
});
cp.on('error', reject)
.on('close', function (code: number) {
logger.info("Exit code received from AST-CLI: " + code)
resolve(results)
logger.info(stderr)
});
cp.stdout.on('data', (data: any) => {
logger.info(`${data}`);
results += data;
});
});
}
}
Binary file modified src/main/resources/cx-linux
Binary file not shown.
Binary file modified src/main/resources/cx-mac
100755 → 100644
Binary file not shown.
Binary file modified src/main/resources/cx.exe
Binary file not shown.
40 changes: 39 additions & 1 deletion src/tests/CxAuthCall.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {CxScanConfig} from '../main/CxScanConfig';
import {CxAuth} from '../main/CxAuth';
import {CxParamType} from '../main/CxParamType';
import {CxCommandOutput} from "../main/CxCommandOutput";
import * as fs from "fs";


let cxScanConfig = new CxScanConfig();
Expand Down Expand Up @@ -81,12 +82,49 @@ describe("ProjectList cases",() => {
});

describe("Results cases",() => {
it('Result List Successful case', async () => {
it('Result Test Successful case', async () => {
const data = await auth.scanList();
const cxCommandOutput: CxCommandOutput =JSON.parse(JSON.stringify(data))
let sampleId = cxCommandOutput.scanObjectList.pop().ID;
const written = await auth.getResults(sampleId,"test.json",null)
console.log(written)
expect(cxCommandOutput.scanObjectList.length).toBeGreaterThan(0);
});

it('Result List Successful case', async () => {
const data = await auth.scanList();
const cxCommandOutput: CxCommandOutput =JSON.parse(JSON.stringify(data))
let sampleId = cxCommandOutput.scanObjectList.pop().ID;
const written = await auth.getResultsList(sampleId,"json")
console.log(written)
expect(written.length).toBeGreaterThan(0);
});

it('Result summary html file generation successful case', async () => {
const data = await auth.scanList();
const cxCommandOutput: CxCommandOutput =JSON.parse(JSON.stringify(data))
let sampleId = cxCommandOutput.scanObjectList.pop().ID;
const written = await auth.getResultsSummary(sampleId,"html","./test.html")
console.log(written)
const file = await fileExists("./test.html");
expect(file).toBe(true);
});

it('Result summary html string successful case', async () => {
const data = await auth.scanList();
const cxCommandOutput: CxCommandOutput =JSON.parse(JSON.stringify(data))
let sampleId = cxCommandOutput.scanObjectList.pop().ID;
const written = await auth.getResultsSummary(sampleId,"html",null)
console.log(written)
expect(written.length).toBeGreaterThan(0);
});

});

const fileExists = (file:any) => {
return new Promise((resolve) => {
fs.access(file, fs.constants.F_OK, (err) => {
err ? resolve(false) : resolve(true)
});
})
}