@@ -6,36 +6,87 @@ import {CxConstants} from '../main/wrapper/CxConstants';
6
6
7
7
describe ( "Triage cases" , ( ) => {
8
8
const cxScanConfig = new BaseTest ( ) ;
9
-
10
- it ( 'Triage Successful case' , async ( ) => {
11
- const auth = new CxWrapper ( cxScanConfig ) ;
12
-
9
+ const auth = new CxWrapper ( cxScanConfig ) ;
10
+ const getScanAndResult = async ( ) : Promise < { scan : any , result : CxResult } > => {
13
11
const scanList : CxCommandOutput = await auth . scanList ( "statuses=Completed,limit=100" ) ;
14
- let result : CxResult ;
15
- let scan , output ;
16
- while ( ! output && scanList && scanList . payload && scanList . payload . length > 0 ) {
17
- scan = scanList . payload . pop ( )
18
- console . log ( "Triage Successful case - ScanId " + scan . id )
19
- output = await auth . getResultsList ( scan . id )
20
- if ( output . status == "Error in the json file." ) {
12
+ let scan , output , result ;
13
+ while ( ! output && scanList ?. payload ?. length > 0 ) {
14
+ scan = scanList . payload . pop ( ) ;
15
+ console . log ( "Triage case - ScanId " + scan . id ) ;
16
+ output = await auth . getResultsList ( scan . id ) ;
17
+ if ( output . status === "Error in the json file." ) {
21
18
output = undefined ;
22
19
} else {
23
- result = output . payload . find ( res => res . type == CxConstants . SAST )
24
- if ( ! result || ! result . similarityId ) {
20
+ result = output . payload . find ( res => res . type === CxConstants . SAST ) ;
21
+ if ( ! result ? .similarityId ) {
25
22
output = undefined ;
26
23
}
27
24
}
28
25
}
26
+ return { scan, result } ;
27
+ } ;
29
28
29
+ const handleTriageShow = async ( scan : any , result : CxResult ) => {
30
30
const cxShow : CxCommandOutput = await auth . triageShow ( scan . projectID , result . similarityId , result . type ) ;
31
-
32
31
expect ( cxShow . exitCode ) . toEqual ( 0 ) ;
32
+ }
33
33
34
- const cxUpdate : CxCommandOutput = await
35
- auth . triageUpdate ( scan . projectID , result . similarityId , result . type , result . state ,
36
- "Edited via JavascriptWrapper" ,
37
- result . severity . toLowerCase ( ) == "high" ? CxConstants . SEVERITY_MEDIUM : CxConstants . SEVERITY_HIGH ) ;
38
-
34
+ const handleTriageUpdate = async ( scan : any , result : CxResult , newState : string , newSeverity : string , newStateId = "" ) => {
35
+ const cxUpdate : CxCommandOutput = await auth . triageUpdate (
36
+ scan . projectID , result . similarityId , result . type , newState ,
37
+ "Edited via JavascriptWrapper" ,
38
+ newSeverity , newStateId
39
+ ) ;
39
40
expect ( cxUpdate . exitCode ) . toEqual ( 0 ) ;
41
+ } ;
42
+ const handlegetStates = async ( ) => {
43
+ const cxCommandOutput : CxCommandOutput = await auth . triageGetStates ( false ) ;
44
+ console . log ( "Json object from states successful case: " + JSON . stringify ( cxCommandOutput ) ) ;
45
+ expect ( cxCommandOutput . payload . length ) . toBeGreaterThanOrEqual ( 1 ) ;
46
+ expect ( cxCommandOutput . exitCode ) . toBe ( 0 ) ;
47
+ return cxCommandOutput
48
+ } ;
49
+
50
+ it ( 'Triage Successful case' , async ( ) => {
51
+ const { scan, result } = await getScanAndResult ( ) ;
52
+ await handleTriageShow ( scan , result ) ;
53
+ await handleTriageUpdate ( scan , result , result . state , result . severity . toLowerCase ( ) === "high" ? CxConstants . SEVERITY_MEDIUM : CxConstants . SEVERITY_HIGH ) ;
54
+ } ) ;
55
+
56
+ it . skip ( 'Triage with custom state Successful case' , async ( ) => {
57
+ const { scan, result } = await getScanAndResult ( ) ;
58
+
59
+ const cxCommandOutput = await handlegetStates ( ) ;
60
+
61
+ let customState = cxCommandOutput . payload [ 0 ] . name
62
+
63
+ if ( result . state == customState ) {
64
+ if ( cxCommandOutput . payload . length > 1 ) {
65
+ customState = cxCommandOutput . payload [ 1 ] . name
66
+ } else {
67
+ await handleTriageUpdate ( scan , result , CxConstants . STATE_CONFIRMED , CxConstants . SEVERITY_MEDIUM ) ;
68
+ }
69
+ }
70
+ await handleTriageUpdate ( scan , result , customState , CxConstants . SEVERITY_MEDIUM ) ;
71
+
72
+ } ) ;
73
+
74
+ it . skip ( 'Triage with custom state id Successful case' , async ( ) => {
75
+ const { scan, result } = await getScanAndResult ( ) ;
76
+
77
+ const cxCommandOutput = await handlegetStates ( ) ;
78
+
79
+ const allStates = cxCommandOutput . payload ;
80
+ let customStateId = allStates [ 0 ] . id
81
+ const customStateName = allStates [ 0 ] . name
82
+
83
+ if ( result . state == customStateName ) {
84
+ if ( allStates . length > 1 ) {
85
+ customStateId = allStates [ 1 ] . id
86
+ } else {
87
+ await handleTriageUpdate ( scan , result , CxConstants . STATE_CONFIRMED , CxConstants . SEVERITY_MEDIUM ) ;
88
+ }
89
+ }
90
+ await handleTriageUpdate ( scan , result , "" , CxConstants . SEVERITY_MEDIUM , customStateId . toString ( ) ) ;
40
91
} ) ;
41
92
} ) ;
0 commit comments