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
6 changes: 0 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

4 changes: 2 additions & 2 deletions 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.23",
"version": "0.0.24",
"description": "AST CLI Javascript wrapper",
"main": "dist/CxAuth.js",
"typings": "dist/CxAuth.d.ts",
Expand All @@ -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",
Expand Down
45 changes: 18 additions & 27 deletions src/main/CxAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand All @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 0 additions & 3 deletions src/main/CxAuthType.ts

This file was deleted.

3 changes: 2 additions & 1 deletion src/main/CxParamType.ts
Original file line number Diff line number Diff line change
@@ -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"
}
24 changes: 12 additions & 12 deletions src/main/ExecutionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}
}
}
});
Expand Down
19 changes: 10 additions & 9 deletions src/tests/CxAuthCall.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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()
Expand All @@ -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))
Expand Down