-
Notifications
You must be signed in to change notification settings - Fork 0
Add support risk managment (AST-84560) #812
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ea467db
add support risk managment
cx-itay-paz dc9dc49
fix pr using hard coded project id
cx-itay-paz 066a86e
add link to app deu
cx-itay-paz 6d8cf08
Merge branch 'main' into support-new-risk-management-command
cx-itay-paz 215eefe
update cli
cx-daniel-greenspan 8ddf23d
push new cli
cx-daniel-greenspan 9107183
Track Checkmarx CLI binaries with Git LFS
invalid-email-address 0a69b32
commit
cx-daniel-greenspan 577217d
update tests
cx-daniel-greenspan 540d3ec
tests
cx-daniel-greenspan eb529da
try again
cx-daniel-greenspan 9c6b080
try again
cx-daniel-greenspan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -228,6 +228,20 @@ export class CxWrapper { | |
| // Reads the result file and retrieves the results | ||
| return exec.executeResultsCommandsFile(scanId, CxConstants.FORMAT_JSON, CxConstants.FORMAT_JSON_FILE, commands, this.config.pathToExecutable, fileName); | ||
| } | ||
|
|
||
| async riskManagementResults(projectId: string, limit?: number): Promise<CxCommandOutput> { | ||
| const commands: string[] = [CxConstants.CMD_RESULT, CxConstants.CMD_RISK_MANAGEMENT]; | ||
| commands.push(CxConstants.PROJECT_ID, projectId); | ||
|
|
||
| if (limit !== undefined) { | ||
| commands.push(CxConstants.CMD_LIMIT, limit.toString()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lets get limit and a string in func input |
||
| } | ||
|
|
||
| commands.push(...this.initializeCommands(false)); | ||
|
|
||
| const exec = new ExecutionService(); | ||
| return await exec.executeCommands(this.config.pathToExecutable, commands); | ||
| } | ||
|
|
||
| async getResultsSummary(scanId: string): Promise<CxCommandOutput> { | ||
| const exec = new ExecutionService(); | ||
|
|
||
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,74 +1,133 @@ | ||
| import {CxWrapper} from '../main/wrapper/CxWrapper'; | ||
| import {CxCommandOutput} from "../main/wrapper/CxCommandOutput"; | ||
| import {BaseTest} from "./BaseTest"; | ||
| import { CxWrapper } from "../main/wrapper/CxWrapper"; | ||
| import { CxCommandOutput } from "../main/wrapper/CxCommandOutput"; | ||
| import { BaseTest } from "./BaseTest"; | ||
| import * as fs from "fs"; | ||
|
|
||
| describe("Results cases",() => { | ||
| const cxScanConfig = new BaseTest(); | ||
| it('Result Test Successful case', async () => { | ||
| const auth = new CxWrapper(cxScanConfig); | ||
| 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)); | ||
| }); | ||
| }); | ||
| describe("Results cases", () => { | ||
| const cxScanConfig = new BaseTest(); | ||
| it("Result Test Successful case", async () => { | ||
| const auth = new CxWrapper(cxScanConfig); | ||
| const cxCommandOutput: CxCommandOutput = await auth.scanList( | ||
| "statuses=Completed" | ||
| ); | ||
| const sampleId = cxCommandOutput.payload.pop().id; | ||
|
|
||
| it('Result Test With Agent Flug Successful case', async () => { | ||
| const auth = new CxWrapper(cxScanConfig); | ||
| const cxCommandOutput: CxCommandOutput = await auth.scanList("statuses=Completed"); | ||
| const sampleId = cxCommandOutput.payload.pop().id; | ||
|
|
||
| auth.getResults(sampleId,"json","jsonList", ".", "jswrapper").then(() => { | ||
| fileExists("./jsonList.json").then(file => expect(file).toBe(true)); | ||
| }); | ||
| 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 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 Test With Agent Flug Successful case", async () => { | ||
| const auth = new CxWrapper(cxScanConfig); | ||
| const cxCommandOutput: CxCommandOutput = await auth.scanList( | ||
| "statuses=Completed" | ||
| ); | ||
| const sampleId = cxCommandOutput.payload.pop().id; | ||
|
|
||
| it('Result summary html file generation successful case', async () => { | ||
| const auth = new CxWrapper(cxScanConfig); | ||
| 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"); | ||
| expect(file).toBe(true); | ||
| auth.getResults(sampleId, "json", "jsonList", ".", "jswrapper").then(() => { | ||
| fileExists("./jsonList.json").then((file) => expect(file).toBe(true)); | ||
| }); | ||
| }); | ||
|
|
||
| it('Result summary html string successful case', async () => { | ||
| const auth = new CxWrapper(cxScanConfig); | ||
| 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); | ||
| }); | ||
| it("Result List Successful case", async () => { | ||
| const auth = new CxWrapper(cxScanConfig); | ||
| 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 codebashing successful case', async () => { | ||
| const auth = new CxWrapper(cxScanConfig); | ||
| const cxCommandOutput: CxCommandOutput = await auth.codeBashingList("79","PHP","Reflected XSS All Clients"); | ||
| expect(cxCommandOutput.payload.length).toBeGreaterThan(0); | ||
| }); | ||
| it("Result summary html file generation successful case", async () => { | ||
| const auth = new CxWrapper(cxScanConfig); | ||
| 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"); | ||
| expect(file).toBe(true); | ||
| }); | ||
|
|
||
| it("Result summary html string successful case", async () => { | ||
| const auth = new CxWrapper(cxScanConfig); | ||
| 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); | ||
| }); | ||
|
|
||
| it("Result codebashing successful case", async () => { | ||
| const auth = new CxWrapper(cxScanConfig); | ||
| const cxCommandOutput: CxCommandOutput = await auth.codeBashingList( | ||
| "79", | ||
| "PHP", | ||
| "Reflected XSS All Clients" | ||
| ); | ||
| expect(cxCommandOutput.payload.length).toBeGreaterThan(0); | ||
| }); | ||
|
|
||
| // The project ID is hardcoded because there is no dynamic way to associate | ||
| // an application with a project through the CLI. | ||
| // link to the our application: https://deu.ast.checkmarx.net/applications/5dff8d1c-d27f-4910-afc1-0b9df02324b4/overview | ||
| it("Risk Management - Successful case", async () => { | ||
| const auth = new CxWrapper(cxScanConfig); | ||
| const projectId = "a5d99fa4-973d-48b5-86c7-6401487e1d52" | ||
|
|
||
| const cxCommandOutput: CxCommandOutput = await auth.riskManagementResults( | ||
| projectId | ||
| ); | ||
|
|
||
| const str = JSON.stringify(cxCommandOutput); | ||
| console.log("Risk Management Result 1: " + str); | ||
| console.log("Risk Management Exit code 1: " + cxCommandOutput.exitCode); | ||
| console.log("Risk Management payload 1: " + cxCommandOutput.payload); | ||
|
|
||
| expect(cxCommandOutput.exitCode).toBe(0); | ||
| expect(Object.keys(cxCommandOutput.payload).length).toBeGreaterThan(0); | ||
| }); | ||
|
|
||
|
|
||
| // The project ID is hardcoded because there is no dynamic way to associate | ||
| // an application with a project through the CLI. | ||
| // link to the our application: https://deu.ast.checkmarx.net/applications/5dff8d1c-d27f-4910-afc1-0b9df02324b4/overview | ||
| it("Risk Management - With Limit", async () => { | ||
| const auth = new CxWrapper(cxScanConfig); | ||
| const projectId = "a5d99fa4-973d-48b5-86c7-6401487e1d52" | ||
| const cxCommandOutput: CxCommandOutput = await auth.riskManagementResults( | ||
| projectId, | ||
| 10 | ||
| ); | ||
|
|
||
| const str = JSON.stringify(cxCommandOutput); | ||
| console.log("Risk Management Result 2: " + str); | ||
| console.log("Risk Management Exit code 2: " + cxCommandOutput.exitCode); | ||
| console.log("Risk Management payload 2: " + cxCommandOutput.payload); | ||
|
|
||
| expect(cxCommandOutput.exitCode).toBe(0); | ||
| expect(Object.keys(cxCommandOutput.payload).length).toBeGreaterThan(0); | ||
| }); | ||
| }); | ||
|
|
||
| const fileExists = (file:string) => { | ||
| return new Promise((resolve) => { | ||
| fs.access(file, fs.constants.F_OK, (err) => { | ||
| err ? resolve(false) : resolve(true) | ||
| }); | ||
| }) | ||
| } | ||
|
|
||
| const fileExists = (file: string) => { | ||
| return new Promise((resolve) => { | ||
| fs.access(file, fs.constants.F_OK, (err) => { | ||
| err ? resolve(false) : resolve(true); | ||
| }); | ||
| }); | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not in 1 command?