Skip to content

Commit 82dfbd9

Browse files
change file permissions (#12)
* change file permissions
1 parent ad8ad0e commit 82dfbd9

File tree

7 files changed

+44
-60
lines changed

7 files changed

+44
-60
lines changed

.github/workflows/main.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,4 @@ jobs:
3939
CX_BASE_URI: ${{ secrets.BASE_URI }}
4040
PATH_TO_EXECUTABLE: /tmp/cx-linux
4141
run: npm test
42-
- name: 'Upload Artifact'
43-
uses: actions/upload-artifact@v2
44-
with:
45-
name: cxAST.log
46-
path: cxAST.log
47-
retention-days: 30
4842

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@CheckmarxDev/ast-cli-javascript-wrapper",
3-
"version": "0.0.23",
3+
"version": "0.0.24",
44
"description": "AST CLI Javascript wrapper",
55
"main": "dist/CxAuth.js",
66
"typings": "dist/CxAuth.d.ts",
@@ -21,7 +21,7 @@
2121
"scripts": {
2222
"build": "tsc",
2323
"postbuild": "copyfiles -u 1 src/main/resources/cx* dist/",
24-
"test": "jest"
24+
"test": "tsc && jest"
2525
},
2626
"repository": "https://github.com/CheckmarxDev/ast-cli-javascript-wrapper.git",
2727
"author": "Jay Nanduri",

src/main/CxAuth.ts

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ export class CxAuth {
3030
}
3131
let executablePath: string;
3232

33-
3433
if (cxScanConfig.pathToExecutable !== null && cxScanConfig.pathToExecutable !== "") {
3534
this.pathToExecutable = cxScanConfig.pathToExecutable;
3635
} else if (process.platform === 'win32') {
@@ -39,19 +38,13 @@ export class CxAuth {
3938
} else if (process.platform === 'darwin') {
4039
executablePath = path.join(__dirname, '/resources/cx-mac');
4140
this.pathToExecutable = executablePath;
42-
fs.chmod(this.pathToExecutable, 7, function(err){
43-
console.log("Permission function output: ",err)
44-
})
45-
}
46-
else {
47-
41+
fs.chmodSync(this.pathToExecutable, 0o777);
42+
} else {
4843
executablePath = path.join(__dirname, '/resources/cx-linux');
4944
this.pathToExecutable = executablePath;
50-
fs.chmod(this.pathToExecutable, 7, function(err){
51-
console.log("Permission function output: ",err)
52-
})
53-
45+
fs.chmodSync(this.pathToExecutable, 0o777);
5446
}
47+
5548
if (cxScanConfig.baseUri !== null && cxScanConfig.baseUri !== '') {
5649
this.baseUri = cxScanConfig.baseUri;
5750
}
@@ -88,13 +81,13 @@ export class CxAuth {
8881
this.commands.push("scan");
8982
this.commands.push("create");
9083
params.forEach((value: string, key: CxParamType) => {
91-
if (key !== CxParamType.ADDITIONAL_PARAMETERS && key.length !== 1 && value !== null && value!== undefined && value.length > 1) {
84+
if (key !== CxParamType.ADDITIONAL_PARAMETERS && key.length !== 1 && value !== null && value !== undefined && value.length > 1) {
9285
this.commands.push("--" + key.toString().replace(/_/g, "-").toLowerCase());
9386
this.commands.push(value);
94-
} else if (key.length === 1 && value !== null && value!== undefined) {
87+
} else if (key.length === 1 && value !== null && value !== undefined) {
9588
this.commands.push("-" + key.toString().replace(/_/g, "-").toLowerCase());
9689
this.commands.push(value);
97-
} else if(key === CxParamType.ADDITIONAL_PARAMETERS) {
90+
} else if (key === CxParamType.ADDITIONAL_PARAMETERS) {
9891
let paramList = value.match(/(?:[^\s"]+|"[^"]*")+/g);
9992
console.log("Additional parameters refined: " + paramList)
10093
if (paramList !== null) {
@@ -139,42 +132,40 @@ export class CxAuth {
139132
this.commands = this.initializeCommands(false);
140133
this.commands.push("result");
141134
this.commands.push("list");
142-
if(scanId !== null && scanId !== "") {
135+
if (scanId !== null && scanId !== "") {
143136
this.commands.push("--scan-id")
144137
this.commands.push(scanId)
145-
}
146-
else{
138+
} else {
147139
console.log("Scan Id not provided")
148140
}
149-
if(formatType !== null && formatType != '') {
141+
if (formatType !== null && formatType != '') {
150142
this.commands.push("--format")
151143
this.commands.push(formatType)
152144
}
153145
let exec = new ExecutionService();
154-
return await exec.executeResultsCommands(this.pathToExecutable,this.commands)
155-
}
146+
return await exec.executeResultsCommands(this.pathToExecutable, this.commands)
147+
}
156148

157-
async getResultsSummary(scanId: string, formatType: string, target:string) {
149+
async getResultsSummary(scanId: string, formatType: string, target: string) {
158150
this.commands = this.initializeCommands(false);
159151
this.commands.push("result");
160152
this.commands.push("summary");
161-
if(scanId !== null && scanId !== "") {
153+
if (scanId !== null && scanId !== "") {
162154
this.commands.push("--scan-id")
163155
this.commands.push(scanId)
164-
}
165-
else{
156+
} else {
166157
console.log("Scan Id not provided")
167158
}
168-
if(formatType !== null && formatType != '') {
159+
if (formatType !== null && formatType != '') {
169160
this.commands.push("--format")
170161
this.commands.push(formatType)
171162
}
172-
if(target !== null && target != '') {
163+
if (target !== null && target != '') {
173164
this.commands.push("--target")
174165
this.commands.push(target)
175166
}
176167
let exec = new ExecutionService();
177-
return await exec.executeResultsCommands(this.pathToExecutable,this.commands)
168+
return await exec.executeResultsCommands(this.pathToExecutable, this.commands)
178169
}
179170

180171
async getResults(scanId: string, targetPath: string, resultParam: CxResultType) {

src/main/CxAuthType.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/main/CxParamType.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export enum CxParamType {
2-
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"
2+
S = "S", V = "V", G = "G", PROJECT_NAME = "PROJECT_NAME", SCAN_TYPES = "SCAN_TYPES", SAST_PRESET_NAME = "SAST_PRESET_NAME",
3+
FILTER = "FILE_FILTER", DIRECTORY = "DIRECTORY", ADDITIONAL_PARAMETERS = "ADDITIONAL_PARAMETERS", AGENT = "AGENT", SOURCES = "FILE_SOURCE", TENANT = "TENANT", BRANCH = "BRANCH"
34
}

src/main/ExecutionService.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ function isJsonString(s: string) {
1616

1717
function transformation(commands: string[]):string[] {
1818
const result:string[] = commands.map(transform);
19-
console.log(JSON.stringify(result))
2019
return result;
2120
}
2221

@@ -42,17 +41,18 @@ export class ExecutionService {
4241
logger.info(stderr)
4342
});
4443
cp.stdout.on('data', (data: any) => {
45-
logger.info(`${data}`);
46-
if (isJsonString(data.toString())) {
47-
let resultObject = JSON.parse(data.toString().split('\n')[0]);
48-
if (resultObject instanceof Array) {
49-
logger.info(JSON.stringify(resultObject))
50-
cxCommandOutput.scanObjectList = resultObject
51-
} else {
52-
let resultArray: CxScan[] = [];
53-
resultArray.push(resultObject);
54-
cxCommandOutput.scanObjectList = resultArray;
55-
44+
if (data) {
45+
logger.info(`${data.toString().trim()}`);
46+
if (isJsonString(data.toString())) {
47+
let resultObject = JSON.parse(data.toString().split('\n')[0]);
48+
if (resultObject instanceof Array) {
49+
logger.info(JSON.stringify(resultObject))
50+
cxCommandOutput.scanObjectList = resultObject
51+
} else {
52+
let resultArray: CxScan[] = [];
53+
resultArray.push(resultObject);
54+
cxCommandOutput.scanObjectList = resultArray;
55+
}
5656
}
5757
}
5858
});

src/tests/CxAuthCall.test.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@ let params = new Map();
1616
params.set(CxParamType.PROJECT_NAME, "ASTJSWrapperIntegrationTests");
1717
params.set(CxParamType.SCAN_TYPES, "sast");
1818

19-
params.set(CxParamType.S, ".");
19+
params.set(CxParamType.S, "./src/tests");
2020
params.set(CxParamType.FILTER, "*.ts,!**/node_modules/**/*");
2121
const auth = new CxAuth(cxScanConfig);
2222

2323
describe("ScanCreate cases",() => {
2424
it('ScanCreate Successful case wait mode', async () => {
25-
const data = await auth.scanCreate(params);
26-
const cxCommandOutput: CxCommandOutput =JSON.parse(JSON.stringify(data))
27-
const ScanObject = cxCommandOutput.scanObjectList.pop()
28-
const scanShowObject = await auth.scanShow(ScanObject.ID);
29-
console.log(" Json object from successful wait mode case: " + JSON.stringify(scanShowObject))
30-
expect(scanShowObject.scanObjectList.pop().Status).toEqual("Completed")
31-
})
25+
const data = await auth.scanCreate(params);
26+
const cxCommandOutput: CxCommandOutput =JSON.parse(JSON.stringify(data))
27+
const ScanObject = cxCommandOutput.scanObjectList.pop()
28+
const scanShowObject = await auth.scanShow(ScanObject.ID);
29+
console.log(" Json object from successful wait mode case: " + JSON.stringify(scanShowObject))
30+
expect(scanShowObject.scanObjectList.pop().Status).toEqual("Completed")
31+
})
3232

3333
it('ScanCreate Successful case with Branch', async () => {
3434
params.set(CxParamType.BRANCH, "master");
@@ -43,7 +43,7 @@ describe("ScanCreate cases",() => {
4343
})
4444

4545
it('ScanCreate Failure case', async () => {
46-
params.set(CxParamType.SAST_PRESET_NAME, "Checkmarx Default Jay");
46+
params.set(CxParamType.SAST_PRESET_NAME, "Checkmarx Default Fake");
4747
const data = await auth.scanCreate(params);
4848
const cxCommandOutput: CxCommandOutput =JSON.parse(JSON.stringify(data))
4949
const ScanObject = cxCommandOutput.scanObjectList.pop()
@@ -54,6 +54,7 @@ describe("ScanCreate cases",() => {
5454

5555
it('ScanCreate Successful case no wait mode', async () => {
5656
params.set(CxParamType.PROJECT_NAME, "ASTJSWrapperTestNoWait");
57+
params.set(CxParamType.SAST_PRESET_NAME, "Checkmarx Default");
5758
params.set(CxParamType.ADDITIONAL_PARAMETERS, "--nowait");
5859
const data = await auth.scanCreate(params);
5960
const cxCommandOutput: CxCommandOutput =JSON.parse(JSON.stringify(data))

0 commit comments

Comments
 (0)