@@ -29,7 +29,61 @@ class Api extends Sut {
2929 // ...
3030
3131 #createSchema( ) {
32- this . #sutSchema = Joi . object ( { } ) ;
32+ this . #sutSchema = Joi . object ( {
33+ sUtType : Joi . string ( ) . required ( ) . valid ( 'Api' ) ,
34+ protocol : Joi . string ( ) . required ( ) . valid ( 'https' , 'http' ) ,
35+ ip : Joi . string ( ) . hostname ( ) . required ( ) ,
36+ port : Joi . number ( ) . port ( ) . required ( ) ,
37+ // eslint-disable-next-line no-underscore-dangle
38+ browser : Joi . string ( ) . valid ( ...this . #configSchemaProps. sut . _cvtProperties . browser . format ) . lowercase ( ) . default ( this . config . get ( 'sut.browser' ) ) , // Todo: Remove once selenium containers are removed.
39+ loggedInIndicator : Joi . string ( ) ,
40+ loggedOutIndicator : Joi . string ( ) ,
41+ context : Joi . object ( { // Zap context
42+ id : Joi . number ( ) . integer ( ) . positive ( ) , // Provided by Zap.
43+ name : Joi . string ( ) . token ( ) // Created in the app.js model.
44+ } ) ,
45+ userId : Joi . number ( ) . integer ( ) . positive ( ) , // Provided by Zap.
46+ authentication : Joi . object ( {
47+ emissaryAuthenticationStrategy : Joi . string ( ) . min ( 2 ) . regex ( / ^ [ - \w / ] { 1 , 200 } $ / ) . default ( 'MaintainJwt' ) ,
48+ route : Joi . string ( ) . min ( 2 ) . regex ( / ^ \/ [ - ? & = \w / ] { 1 , 1000 } $ / )
49+ } ) ,
50+ testSession : Joi . object ( {
51+ type : Joi . string ( ) . valid ( 'appScanner' ) . required ( ) ,
52+ id : Joi . string ( ) . alphanum ( ) . required ( ) ,
53+ attributes : Joi . object ( {
54+ sitesTreePopulationStrategy : Joi . string ( ) . min ( 2 ) . regex ( / ^ [ - \w / ] { 1 , 200 } $ / ) . default ( 'ImportUrls' ) ,
55+ spiderStrategy : Joi . string ( ) . min ( 2 ) . regex ( / ^ [ - \w / ] { 1 , 200 } $ / ) . default ( 'Standard' ) ,
56+ scannersStrategy : Joi . string ( ) . min ( 2 ) . regex ( / ^ [ - \w / ] { 1 , 200 } $ / ) . default ( 'ApiStandard' ) ,
57+ scanningStrategy : Joi . string ( ) . min ( 2 ) . regex ( / ^ [ - \w / ] { 1 , 200 } $ / ) . default ( 'ApiStandard' ) ,
58+ postScanningStrategy : Joi . string ( ) . min ( 2 ) . regex ( / ^ [ - \w / ] { 1 , 200 } $ / ) . default ( 'ApiStandard' ) ,
59+ reportingStrategy : Joi . string ( ) . min ( 2 ) . regex ( / ^ [ - \w / ] { 1 , 200 } $ / ) . default ( 'Standard' ) ,
60+ username : Joi . string ( ) . min ( 2 ) . required ( ) ,
61+ openApi : Joi . object ( {
62+ importFileContentBase64 : Joi . string ( ) . base64 ( { paddingRequired : true } ) ,
63+ importUrl : Joi . string ( ) . uri ( { scheme : [ 'https' , 'http' ] , domain : { allowUnicode : false } } )
64+ } ) . xor ( 'importFileContentBase64' , 'importUrl' ) ,
65+ soap : Joi . object ( {
66+ importFileContentBase64 : Joi . string ( ) . base64 ( { paddingRequired : true } ) ,
67+ importUrl : Joi . string ( ) . uri ( { scheme : [ 'https' , 'http' ] , domain : { allowUnicode : false } } )
68+ } ) . xor ( 'importFileContentBase64' , 'importUrl' ) ,
69+ graphQl : Joi . object ( {
70+ importFileContentBase64 : Joi . string ( ) . base64 ( { paddingRequired : true } ) ,
71+ importUrl : Joi . string ( ) . uri ( { scheme : [ 'https' , 'http' ] , domain : { allowUnicode : false } } ) ,
72+ maxQueryDepth : Joi . number ( ) . integer ( ) . positive ( ) , // Zaproxy default: 5
73+ maxArgsDepth : Joi . number ( ) . integer ( ) . positive ( ) , // Zaproxy default: 5
74+ optionalArgsEnabled : Joi . boolean ( ) . default ( true ) , // Zaproxy default: true
75+ argsType : Joi . string ( ) . valid ( 'INLINE' , 'VARIABLES' , 'BOTH' ) , // Zaproxy default: 'BOTH'
76+ querySplitType : Joi . string ( ) . valid ( 'LEAF' , 'ROOT_FIELD' , 'OPERATION' ) , // Zaproxy default: 'LEAF'
77+ requestMethod : Joi . string ( ) . valid ( 'POST_JSON' , 'POST_GRAPHQL' , 'GET' ) // Zaproxy default: 'POST_JSON'
78+ } ) . xor ( 'importFileContentBase64' , 'importUrl' ) ,
79+ importUrls : Joi . object ( { importFileContentBase64 : Joi . string ( ) . base64 ( { paddingRequired : true } ) . required ( ) } ) ,
80+ aScannerAttackStrength : Joi . string ( ) . valid ( ...this . #configSchemaProps. sut . _cvtProperties . aScannerAttackStrength . format ) . uppercase ( ) . default ( this . config . get ( 'sut.aScannerAttackStrength' ) ) , // eslint-disable-line no-underscore-dangle
81+ aScannerAlertThreshold : Joi . string ( ) . valid ( ...this . #configSchemaProps. sut . _cvtProperties . aScannerAlertThreshold . format ) . uppercase ( ) . default ( this . config . get ( 'sut.aScannerAlertThreshold' ) ) , // eslint-disable-line no-underscore-dangle
82+ alertThreshold : Joi . number ( ) . integer ( ) . min ( 0 ) . max ( 1000 ) . default ( this . config . get ( 'sut.alertThreshold' ) ) ,
83+ excludedRoutes : Joi . array ( ) . items ( Joi . string ( ) ) . default ( [ ] )
84+ } ) . xor ( 'openApi' , 'graphQl' , 'soap' , 'importUrls' )
85+ } )
86+ } ) . xor ( 'loggedInIndicator' , 'loggedOutIndicator' ) ;
3387 }
3488
3589 async #selectStrategies( ) {
@@ -38,8 +92,6 @@ class Api extends Sut {
3892
3993 async initialise ( ) { // eslint-disable-line class-methods-use-this
4094 // Todo: Populate as required.
41-
42-
4395 }
4496
4597 constructor ( { log, publisher, sutProperties } ) {
@@ -57,49 +109,83 @@ class Api extends Sut {
57109 getSitesTreePopulationStrategy ( ) {
58110 return {
59111 ...super . getSitesTreePopulationStrategy ( ) ,
60- args : { /* Todo: args specific to the API specific strategy */ }
112+ args : {
113+ log : this . log ,
114+ publisher : this . publisher ,
115+ baseUrl : this . baseUrl ( ) ,
116+ sutPropertiesSubSet : this . getProperties ( [ 'testSession' , 'context' ] ) ,
117+ setContextId : ( id ) => { this . properties . context . id = id ; }
118+ }
61119 } ;
62120 }
63121
64122 getEmissaryAuthenticationStrategy ( ) {
65123 return {
66124 ...super . getEmissaryAuthenticationStrategy ( ) ,
67- args : { /* Todo: args specific to the API specific strategy */ }
125+ args : {
126+ log : this . log ,
127+ publisher : this . publisher ,
128+ baseUrl : this . baseUrl ( ) ,
129+ sutPropertiesSubSet : this . getProperties ( [ 'authentication' , 'loggedInIndicator' , 'loggedOutIndicator' , 'testSession' , 'context' ] ) ,
130+ setUserId : ( id ) => { this . properties . userId = id ; }
131+ }
68132 } ;
69133 }
70134
71135 getSpiderStrategy ( ) {
72136 return {
73137 ...super . getSpiderStrategy ( ) ,
74- args : { /* Todo: args specific to the API specific strategy */ }
138+ args : {
139+ publisher : this . publisher ,
140+ baseUrl : this . baseUrl ( ) ,
141+ sutPropertiesSubSet : this . getProperties ( 'testSession' )
142+ }
75143 } ;
76144 }
77145
78146 getScannersStrategy ( ) {
79147 return {
80148 ...super . getScannersStrategy ( ) ,
81- args : { /* Todo: args specific to the API specific strategy */ }
149+ args : {
150+ log : this . log ,
151+ publisher : this . publisher ,
152+ baseUrl : this . baseUrl ( ) ,
153+ sutPropertiesSubSet : this . getProperties ( 'testSession' )
154+ }
82155 } ;
83156 }
84157
85158 getScanningStrategy ( ) {
86159 return {
87160 ...super . getScanningStrategy ( ) ,
88- args : { /* Todo: args specific to the API specific strategy */ }
161+ args : {
162+ log : this . log ,
163+ publisher : this . publisher ,
164+ baseUrl : this . baseUrl ( ) ,
165+ sutPropertiesSubSet : this . getProperties ( [ 'testSession' , 'context' , 'userId' ] )
166+ }
89167 } ;
90168 }
91169
92170 getPostScanningStrategy ( ) {
93171 return {
94172 ...super . getPostScanningStrategy ( ) ,
95- args : { /* Todo: args specific to the API specific strategy */ }
173+ args : {
174+ publisher : this . publisher ,
175+ baseUrl : this . baseUrl ( ) ,
176+ sutPropertiesSubSet : this . getProperties ( 'testSession' )
177+ }
96178 } ;
97179 }
98180
99181 getReportingStrategy ( ) {
100182 return {
101183 ...super . getReportingStrategy ( ) ,
102- args : { /* Todo: args specific to the API specific strategy */ }
184+ args : {
185+ log : this . log ,
186+ publisher : this . publisher ,
187+ sutPropertiesSubSet : this . getProperties ( 'testSession' )
188+ }
103189 } ;
104190 }
105191}
0 commit comments