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
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,5 @@ jobs:
CX_CLIENT_SECRET: ${{ secrets.CX_CLIENT_SECRET}}
CX_BASE_URI: ${{ secrets.CX_BASE_URI }}
CX_TENANT: ${{ secrets.CX_TENANT }}
CX_SCANID: ${{ secrets.SCANID }}
CX_APIKEY: ${{ secrets.CX_APIKEY }}
run: npm test
2 changes: 1 addition & 1 deletion checkmarx-ast-cli.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0.60
2.0.63
6 changes: 3 additions & 3 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ module.exports = {
coverageThreshold: {
"global": {
"branches": 70,
"functions": 90,
"lines": 90,
"statements": 90
"functions": 80,
"lines": 80,
"statements": 80
}
},
coveragePathIgnorePatterns: ['/node_modules/', '\\.json$', '/__tests__/', '/stories/', '/\\.storybook/'],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"postbuild": "copyfiles -u 1 src/main/wrapper/resources/cx* dist/;copyfiles -u 1 src/tests/data/* dist/;",
"lint": "eslint . --ext .ts",
"lint-and-fix": "eslint . --ext .ts --fix",
"test": "copyfiles -u 1 src/tests/data/* dist/; tsc && jest --runInBand --coverage"
"test": "copyfiles -u 1 src/tests/data/* dist/; tsc && jest"
},
"repository": "https://github.com/CheckmarxDev/ast-cli-javascript-wrapper.git",
"author": "Jay Nanduri",
Expand Down
12 changes: 9 additions & 3 deletions src/main/wrapper/CxWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,10 @@ export class CxWrapper {
commands.push(...this.initializeCommands(true));
const exec = new ExecutionService();
const response = await exec.executeCommands(this.config.pathToExecutable, commands, CxConstants.BFL_TYPE);
const bflNodeIndex = this.getIndexOfBflNode(response.payload, resultNodes)
response.payload[0] = bflNodeIndex;
if (response) {
const bflNodeIndex = this.getIndexOfBflNode(response.payload, resultNodes)
response.payload[0] = bflNodeIndex;
}
return response;
}

Expand Down Expand Up @@ -356,8 +358,12 @@ export class CxWrapper {
}

getIndexOfBflNode(bflNodes: CxBFL[], resultNodes: any[]): number {

const bflNodeNotFound = -1;

if (!bflNodes) {
return bflNodeNotFound
}

for (const bflNode of bflNodes) {
for (const resultNode of resultNodes) {

Expand Down
Binary file modified src/main/wrapper/resources/cx-linux
Binary file not shown.
Binary file modified src/main/wrapper/resources/cx-mac
Binary file not shown.
Binary file modified src/main/wrapper/resources/cx.exe
Binary file not shown.
1 change: 0 additions & 1 deletion src/tests/BaseTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export class BaseTest {
this.clientSecret = process.env["CX_CLIENT_SECRET"];
this.tenant = process.env["CX_TENANT"];
this.apiKey = process.env["CX_APIKEY"];
this.scanId = process.env["CX_SCANID"];
this.additionalParameters = "--debug"
if (process.env["PATH_TO_EXECUTABLE"] !== null && process.env["PATH_TO_EXECUTABLE"] !== undefined) {
this.pathToExecutable = process.env["PATH_TO_EXECUTABLE"];
Expand Down
42 changes: 24 additions & 18 deletions src/tests/PredicateTest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,36 @@ import {CxWrapper} from '../main/wrapper/CxWrapper';
import {CxCommandOutput} from "../main/wrapper/CxCommandOutput";
import {BaseTest} from "./BaseTest";
import CxResult from '../main/results/CxResult';
import { CxConstants } from '../main/wrapper/CxConstants';
import {CxConstants} from '../main/wrapper/CxConstants';

describe("Triage cases",() => {
describe("Triage cases", () => {
const cxScanConfig = new BaseTest();

it('TriageShow Successful case', async () => {
it('Triage Successful case', async () => {
const auth = new CxWrapper(cxScanConfig);
const scan = (await auth.scanShow(cxScanConfig.scanId)).payload.pop();
const results = await auth.getResultsList(cxScanConfig.scanId)
const result: CxResult = results.payload.find(res => res.type == CxConstants.SAST)

const cxCommandOutput: CxCommandOutput = await auth.triageShow(scan.projectID, result.similarityId, result.type);

expect(cxCommandOutput.exitCode).toEqual(0);
})
const scanList: CxCommandOutput = await auth.scanList("statuses=Completed");
let scan, output;
while (!output && scanList && scanList.payload && scanList.payload.length > 0) {
scan = scanList.payload.pop()
console.log("Triage Successful case - ScanId " + scan.id)
output = await auth.getResultsList(scan.id)
if (output.status == "Error in the json file.") {
output = undefined;
}
}

it('TriageUpdate Successful case', async () => {
const auth = new CxWrapper(cxScanConfig);
const scan = (await auth.scanShow(cxScanConfig.scanId)).payload.pop();
const results = await auth.getResultsList(cxScanConfig.scanId)
const result: CxResult = results.payload.find(res => res.type == CxConstants.SAST)
const result: CxResult = output.payload.find(res => res.type == CxConstants.SAST)

const cxShow: CxCommandOutput = await auth.triageShow(scan.projectID, result.similarityId, result.type);

expect(cxShow.exitCode).toEqual(0);

const cxCommandOutput: CxCommandOutput = await auth.triageUpdate(scan.projectID, result.similarityId, result.type, CxConstants.STATE_CONFIRMED, "Edited via JavascriptWrapper", result.severity.toLowerCase() == "high" ? CxConstants.SEVERITY_MEDIUM : CxConstants.SEVERITY_HIGH);
const cxUpdate: CxCommandOutput = await
auth.triageUpdate(scan.projectID, result.similarityId, result.type, result.state,
"Edited via JavascriptWrapper",
result.severity.toLowerCase() == "high" ? CxConstants.SEVERITY_MEDIUM : CxConstants.SEVERITY_HIGH);

expect(cxCommandOutput.exitCode).toEqual(0);
})
expect(cxUpdate.exitCode).toEqual(0);
});
});
40 changes: 15 additions & 25 deletions src/tests/ResultTest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,38 @@ import {CxWrapper} from '../main/wrapper/CxWrapper';
import {CxCommandOutput} from "../main/wrapper/CxCommandOutput";
import {BaseTest} from "./BaseTest";
import * as fs from "fs";
import { CxConstants } from '../main/wrapper/CxConstants';
import CxResult from '../main/results/CxResult';

describe("Results cases",() => {
const cxScanConfig = new BaseTest();
it('Result Test Successful case', async () => {
const auth = new CxWrapper(cxScanConfig);
const cxCommandOutput: CxCommandOutput = await auth.scanList("");
const cxCommandOutput: CxCommandOutput = await auth.scanList("statuses=Completed");
const sampleId = cxCommandOutput.payload.pop().id;

auth.getResults(sampleId,"json","jsonList", ".").then(() => {
fileExists("./jsonList.json").then(file => expect(file).toBe(true));

});

});

it('Result List Successful case', async () => {
const auth = new CxWrapper(cxScanConfig);
const cxCommandOutput: CxCommandOutput = await auth.scanList("");
console.log(JSON.stringify(cxCommandOutput));
const sampleId = cxCommandOutput.payload.pop().id;
const written = await auth.getResultsList(sampleId);
expect(written.status).toBeUndefined();
expect(written.payload.length).toBeGreaterThanOrEqual(0);
const scanList: CxCommandOutput = await auth.scanList("statuses=Completed");
let output;
while (!output && scanList && scanList.payload && scanList.payload.length > 0) {
const scanId = scanList.payload.pop().id;
console.log("Triage Successful case - ScanId " + scanId);
output = await auth.getResultsList(scanId);
if (output.status == "Error in the json file.") {
output = undefined;
}
}
expect(output.status).toBeUndefined();
expect(output.payload.length).toBeGreaterThanOrEqual(0);
});

it('Result summary html file generation successful case', async () => {
const auth = new CxWrapper(cxScanConfig);
const cxCommandOutput: CxCommandOutput = await auth.scanList("");
const cxCommandOutput: CxCommandOutput = await auth.scanList("statuses=Completed");
const sampleId = cxCommandOutput.payload.pop().id;
await auth.getResults(sampleId,"summaryHTML","test", ".");
const file = await fileExists("./test.html");
Expand All @@ -40,7 +42,7 @@ describe("Results cases",() => {

it('Result summary html string successful case', async () => {
const auth = new CxWrapper(cxScanConfig);
const cxCommandOutput: CxCommandOutput = await auth.scanList("");
const cxCommandOutput: CxCommandOutput = await auth.scanList("statuses=Completed");
const sampleId = cxCommandOutput.payload.pop().id;
const written = await auth.getResultsSummary(sampleId);
expect(written.payload.length).toBeGreaterThan(0);
Expand All @@ -51,18 +53,6 @@ describe("Results cases",() => {
const cxCommandOutput: CxCommandOutput = await auth.codeBashingList("79","PHP","Reflected XSS All Clients");
expect(cxCommandOutput.payload.length).toBeGreaterThan(0);
});

it('Result bfl successful case', async () => {
const auth = new CxWrapper(cxScanConfig);
console.log("ScanID : " + cxScanConfig.scanId)
const results = await auth.getResultsList(cxScanConfig.scanId)
const result: CxResult = results.payload.find(res => res.type == CxConstants.SAST)
const data = result.data
const queryId = data.queryId
console.log("QueryID :" + result.data.queryId)
const cxCommandOutput: CxCommandOutput = await auth.getResultsBfl(cxScanConfig.scanId, queryId, data.nodes);
expect(cxCommandOutput.payload.length).toBeGreaterThanOrEqual(-1);
});
});

const fileExists = (file:string) => {
Expand Down