1- import { CxWrapper } from ' ../main/wrapper/CxWrapper' ;
2- import { CxCommandOutput } from "../main/wrapper/CxCommandOutput" ;
3- import { BaseTest } from "./BaseTest" ;
1+ import { CxWrapper } from " ../main/wrapper/CxWrapper" ;
2+ import { CxCommandOutput } from "../main/wrapper/CxCommandOutput" ;
3+ import { BaseTest } from "./BaseTest" ;
44import * as fs from "fs" ;
55
6- describe ( "Results cases" , ( ) => {
7- const cxScanConfig = new BaseTest ( ) ;
8- it ( 'Result Test Successful case' , async ( ) => {
9- const auth = new CxWrapper ( cxScanConfig ) ;
10- const cxCommandOutput : CxCommandOutput = await auth . scanList ( "statuses=Completed" ) ;
11- const sampleId = cxCommandOutput . payload . pop ( ) . id ;
12-
13- auth . getResults ( sampleId , "json" , "jsonList" , "." ) . then ( ( ) => {
14- fileExists ( "./jsonList.json" ) . then ( file => expect ( file ) . toBe ( true ) ) ;
15- } ) ;
16- } ) ;
6+ describe ( "Results cases" , ( ) => {
7+ const cxScanConfig = new BaseTest ( ) ;
8+ it ( "Result Test Successful case" , async ( ) => {
9+ const auth = new CxWrapper ( cxScanConfig ) ;
10+ const cxCommandOutput : CxCommandOutput = await auth . scanList (
11+ "statuses=Completed"
12+ ) ;
13+ const sampleId = cxCommandOutput . payload . pop ( ) . id ;
1714
18- it ( 'Result Test With Agent Flug Successful case' , async ( ) => {
19- const auth = new CxWrapper ( cxScanConfig ) ;
20- const cxCommandOutput : CxCommandOutput = await auth . scanList ( "statuses=Completed" ) ;
21- const sampleId = cxCommandOutput . payload . pop ( ) . id ;
22-
23- auth . getResults ( sampleId , "json" , "jsonList" , "." , "jswrapper" ) . then ( ( ) => {
24- fileExists ( "./jsonList.json" ) . then ( file => expect ( file ) . toBe ( true ) ) ;
25- } ) ;
15+ auth . getResults ( sampleId , "json" , "jsonList" , "." ) . then ( ( ) => {
16+ fileExists ( "./jsonList.json" ) . then ( ( file ) => expect ( file ) . toBe ( true ) ) ;
2617 } ) ;
18+ } ) ;
2719
28- it ( 'Result List Successful case' , async ( ) => {
29- const auth = new CxWrapper ( cxScanConfig ) ;
30- const scanList : CxCommandOutput = await auth . scanList ( "statuses=Completed" ) ;
31- let output ;
32- while ( ! output && scanList && scanList . payload && scanList . payload . length > 0 ) {
33- const scanId = scanList . payload . pop ( ) . id ;
34- console . log ( "Triage Successful case - ScanId " + scanId ) ;
35- output = await auth . getResultsList ( scanId ) ;
36- if ( output . status == "Error in the json file." ) {
37- output = undefined ;
38- }
39- }
40- expect ( output . status ) . toBeUndefined ( ) ;
41- expect ( output . payload . length ) . toBeGreaterThanOrEqual ( 0 ) ;
42- } ) ;
20+ it ( "Result Test With Agent Flug Successful case" , async ( ) => {
21+ const auth = new CxWrapper ( cxScanConfig ) ;
22+ const cxCommandOutput : CxCommandOutput = await auth . scanList (
23+ "statuses=Completed"
24+ ) ;
25+ const sampleId = cxCommandOutput . payload . pop ( ) . id ;
4326
44- it ( 'Result summary html file generation successful case' , async ( ) => {
45- const auth = new CxWrapper ( cxScanConfig ) ;
46- const cxCommandOutput : CxCommandOutput = await auth . scanList ( "statuses=Completed" ) ;
47- const sampleId = cxCommandOutput . payload . pop ( ) . id ;
48- await auth . getResults ( sampleId , "summaryHTML" , "test" , "." ) ;
49- const file = await fileExists ( "./test.html" ) ;
50- expect ( file ) . toBe ( true ) ;
27+ auth . getResults ( sampleId , "json" , "jsonList" , "." , "jswrapper" ) . then ( ( ) => {
28+ fileExists ( "./jsonList.json" ) . then ( ( file ) => expect ( file ) . toBe ( true ) ) ;
5129 } ) ;
30+ } ) ;
5231
53- it ( 'Result summary html string successful case' , async ( ) => {
54- const auth = new CxWrapper ( cxScanConfig ) ;
55- const cxCommandOutput : CxCommandOutput = await auth . scanList ( "statuses=Completed" ) ;
56- const sampleId = cxCommandOutput . payload . pop ( ) . id ;
57- const written = await auth . getResultsSummary ( sampleId ) ;
58- expect ( written . payload . length ) . toBeGreaterThan ( 0 ) ;
59- } ) ;
32+ it ( "Result List Successful case" , async ( ) => {
33+ const auth = new CxWrapper ( cxScanConfig ) ;
34+ const scanList : CxCommandOutput = await auth . scanList ( "statuses=Completed" ) ;
35+ let output ;
36+ while (
37+ ! output &&
38+ scanList &&
39+ scanList . payload &&
40+ scanList . payload . length > 0
41+ ) {
42+ const scanId = scanList . payload . pop ( ) . id ;
43+ console . log ( "Triage Successful case - ScanId " + scanId ) ;
44+ output = await auth . getResultsList ( scanId ) ;
45+ if ( output . status == "Error in the json file." ) {
46+ output = undefined ;
47+ }
48+ }
49+ expect ( output . status ) . toBeUndefined ( ) ;
50+ expect ( output . payload . length ) . toBeGreaterThanOrEqual ( 0 ) ;
51+ } ) ;
6052
61- it ( 'Result codebashing successful case' , async ( ) => {
62- const auth = new CxWrapper ( cxScanConfig ) ;
63- const cxCommandOutput : CxCommandOutput = await auth . codeBashingList ( "79" , "PHP" , "Reflected XSS All Clients" ) ;
64- expect ( cxCommandOutput . payload . length ) . toBeGreaterThan ( 0 ) ;
65- } ) ;
53+ it ( "Result summary html file generation successful case" , async ( ) => {
54+ const auth = new CxWrapper ( cxScanConfig ) ;
55+ const cxCommandOutput : CxCommandOutput = await auth . scanList (
56+ "statuses=Completed"
57+ ) ;
58+ const sampleId = cxCommandOutput . payload . pop ( ) . id ;
59+ await auth . getResults ( sampleId , "summaryHTML" , "test" , "." ) ;
60+ const file = await fileExists ( "./test.html" ) ;
61+ expect ( file ) . toBe ( true ) ;
62+ } ) ;
63+
64+ it ( "Result summary html string successful case" , async ( ) => {
65+ const auth = new CxWrapper ( cxScanConfig ) ;
66+ const cxCommandOutput : CxCommandOutput = await auth . scanList (
67+ "statuses=Completed"
68+ ) ;
69+ const sampleId = cxCommandOutput . payload . pop ( ) . id ;
70+ const written = await auth . getResultsSummary ( sampleId ) ;
71+ expect ( written . payload . length ) . toBeGreaterThan ( 0 ) ;
72+ } ) ;
73+
74+ it ( "Result codebashing successful case" , async ( ) => {
75+ const auth = new CxWrapper ( cxScanConfig ) ;
76+ const cxCommandOutput : CxCommandOutput = await auth . codeBashingList (
77+ "79" ,
78+ "PHP" ,
79+ "Reflected XSS All Clients"
80+ ) ;
81+ expect ( cxCommandOutput . payload . length ) . toBeGreaterThan ( 0 ) ;
82+ } ) ;
83+
84+ it ( "Risk Management - Successful case" , async ( ) => {
85+ const auth = new CxWrapper ( cxScanConfig ) ;
86+ const projectId = await getProjectId ( auth ) ;
87+
88+ const cxCommandOutput : CxCommandOutput = await auth . riskManagementResults (
89+ projectId
90+ ) ;
91+ console . log ( "Risk Management Results: " + JSON . stringify ( cxCommandOutput ) ) ;
92+
93+ expect ( cxCommandOutput . exitCode ) . toBe ( 0 ) ;
94+ expect ( cxCommandOutput . payload . length ) . toBeGreaterThan ( 0 ) ;
95+ } ) ;
96+
97+ it ( "Risk Management - With Limit" , async ( ) => {
98+ const auth = new CxWrapper ( cxScanConfig ) ;
99+ const projectId = await getProjectId ( auth ) ;
100+ const cxCommandOutput : CxCommandOutput = await auth . riskManagementResults (
101+ projectId ,
102+ 10
103+ ) ;
104+ console . log (
105+ "Risk Management Results with limit 10: " +
106+ JSON . stringify ( cxCommandOutput )
107+ ) ;
108+
109+ expect ( cxCommandOutput . exitCode ) . toBe ( 0 ) ;
110+ expect ( cxCommandOutput . payload . length ) . toBeLessThanOrEqual ( 10 ) ;
111+ } ) ;
66112} ) ;
67113
68- const fileExists = ( file :string ) => {
69- return new Promise ( ( resolve ) => {
70- fs . access ( file , fs . constants . F_OK , ( err ) => {
71- err ? resolve ( false ) : resolve ( true )
72- } ) ;
73- } )
74- }
114+ const getProjectId = async ( auth : CxWrapper ) : Promise < string > => {
115+ const scanList : CxCommandOutput = await auth . scanList ( "statuses=Completed" ) ;
116+ if ( ! scanList . payload . length ) {
117+ throw new Error ( "No completed scans found." ) ;
118+ }
119+ const scan = scanList . payload . find ( ( scan ) => scan . projectID ) ;
120+ if ( ! scan ) {
121+ throw new Error ( "No valid projectId found." ) ;
122+ }
123+ return scan . projectID ;
124+ } ;
125+
126+
127+ const fileExists = ( file : string ) => {
128+ return new Promise ( ( resolve ) => {
129+ fs . access ( file , fs . constants . F_OK , ( err ) => {
130+ err ? resolve ( false ) : resolve ( true ) ;
131+ } ) ;
132+ } ) ;
133+ } ;
0 commit comments