@@ -17,6 +17,7 @@ if(vm){console.log('VERBOSE MODE: ON \n Feature to test EXTRA_HEADER #FEH');}
17
17
// Time to wait to check the status of the task
18
18
var TIMEOUT = 100 ;
19
19
var CREATED = 201 ; // 200 for older versions
20
+ var INVALID_HEADERS = 400 ;
20
21
var describeTimeout = 5000 ;
21
22
DEFAULT_PERSISTENCE = 'BODY' ;
22
23
@@ -188,6 +189,47 @@ function _invalidScenario(data){
188
189
} ) ;
189
190
}
190
191
192
+ function _invalidHeadersValue ( data ) {
193
+ it ( data . name + data . protocol . toUpperCase ( ) + ' /' + data . method + ' #FEH' , function ( done ) {
194
+ var agent = superagent . agent ( ) ;
195
+ var id ;
196
+
197
+ var method ;
198
+ switch ( data . method ) {
199
+ case 'DELETE' :
200
+ method = 'del' ;
201
+ break ;
202
+ default :
203
+ method = data . method . toLowerCase ( )
204
+ }
205
+
206
+ //SET UP the request to the advancedServer
207
+ var req = agent
208
+ [ method ] ( RUSHENDPOINT + data . path )
209
+ . set ( 'x-relayer-host' , ENDPOINT ) //Always the same endpoint
210
+ . set ( 'x-relayer-persistence' , DEFAULT_PERSISTENCE )
211
+ . set ( 'content-type' , 'application/json' )
212
+ . set ( data . headers )
213
+ if ( data . method . toUpperCase ( ) === 'POST' || data . method . toUpperCase ( ) === 'PUT' ) {
214
+ req = req . send ( data . body ) ;
215
+ }
216
+ req . end ( function ( err , res ) {
217
+ expect ( err ) . to . not . exist ;
218
+ expect ( res . statusCode ) . to . eql ( INVALID_HEADERS ) ;
219
+ expect ( res . body ) . to . exist ;
220
+ expect ( res . body . exceptionId ) . to . eql ( 'SVC0002' ) ;
221
+ expect ( res . body . exceptionText ) . to . eql ( 'Invalid parameter value: x-relayer-header' ) ;
222
+
223
+ expect ( res . body . userMessage ) . to . eql ( 'Value for header ' + data . invalidHeader + ' is not defined' ) ;
224
+
225
+ if ( vm ) { console . log ( res . body . userMessage ) ; }
226
+
227
+ done ( ) ;
228
+ } ) ;
229
+
230
+ } ) ;
231
+ }
232
+
191
233
192
234
193
235
describe ( 'Single Feature: Extra header ' + '#FEH' , function ( ) {
@@ -218,28 +260,48 @@ describe('Single Feature: Extra header ' + '#FEH', function() {
218
260
219
261
describe ( 'Retrieve request with a valid header policy request using HTTPS #FEH' , function ( ) {
220
262
221
- var responseHeaders = {
263
+ var responseHeaders1 = {
222
264
'Fake-User-Agent' :'Mozilla/5.0 (Macintosh++; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.57 ' ,
223
265
'Accept-Language' :'es-ES,es;q=0.8' ,
224
266
'x' : 'X-relayer-NoHost:localhost:8000'
225
267
} ;
226
- var extraHeaders = {
268
+ var extraHeaders1 = {
227
269
'X-Relayer-Protocol' :'https' ,
228
270
'X-Relayer-Header' : [
229
271
encodeURIComponent ( 'X: X-relayer-NoHost:localhost:8000' ) ,
230
272
encodeURIComponent ( 'Fake-User-Agent:Mozilla/5.0 (Macintosh++; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.57 ' ) ,
231
273
encodeURIComponent ( 'Accept-Language:es-ES,es;q=0.8' )
232
274
] . join ( ', ' ) } ;
275
+ var responseHeaders2 = {
276
+ 'Fake-User-Agent' :'Mozilla/5.0 (Macintosh++; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.57 ' ,
277
+ 'Accept-Language' :'' ,
278
+ 'x' : 'X-relayer-NoHost:localhost:8000'
279
+ } ;
280
+ var extraHeaders2 = {
281
+ 'X-Relayer-Protocol' :'https' ,
282
+ 'X-Relayer-Header' : [
283
+ encodeURIComponent ( 'X: X-relayer-NoHost:localhost:8000' ) ,
284
+ encodeURIComponent ( 'Fake-User-Agent:Mozilla/5.0 (Macintosh++; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.57 ' ) ,
285
+ encodeURIComponent ( 'Accept-Language:' )
286
+ ] . join ( ', ' ) } ;
233
287
234
288
var dataSetHTTPS = [
235
- { protocol : 'HTTPS' , method : 'GET' , path : '/' , headers : extraHeaders , body : { } ,
236
- name : '1 Should accept the request using ' , responseHeaders : responseHeaders } ,
237
- { protocol : 'HTTPS' , method : 'POST' , path : '/' , headers : extraHeaders , body : { } ,
238
- name : '2 Should accept the request using ' , responseHeaders : responseHeaders } ,
239
- { protocol : 'HTTPS' , method : 'PUT' , path : '/' , headers : extraHeaders , body : { } ,
240
- name : '3 Should accept the request using ' , responseHeaders : responseHeaders } ,
241
- { protocol : 'HTTPS' , method : 'DELETE' , path : '/' , headers : extraHeaders , body : { } ,
242
- name : '4 Should accept the request using ' , responseHeaders : responseHeaders }
289
+ { protocol : 'HTTPS' , method : 'GET' , path : '/' , headers : extraHeaders1 , body : { } ,
290
+ name : '1 Should accept the request using ' , responseHeaders : responseHeaders1 } ,
291
+ { protocol : 'HTTPS' , method : 'POST' , path : '/' , headers : extraHeaders1 , body : { } ,
292
+ name : '2 Should accept the request using ' , responseHeaders : responseHeaders1 } ,
293
+ { protocol : 'HTTPS' , method : 'PUT' , path : '/' , headers : extraHeaders1 , body : { } ,
294
+ name : '3 Should accept the request using ' , responseHeaders : responseHeaders1 } ,
295
+ { protocol : 'HTTPS' , method : 'DELETE' , path : '/' , headers : extraHeaders1 , body : { } ,
296
+ name : '4 Should accept the request using ' , responseHeaders : responseHeaders1 } ,
297
+ { protocol : 'HTTPS' , method : 'GET' , path : '/' , headers : extraHeaders2 , body : { } ,
298
+ name : '5 Should accept the request using ' , responseHeaders : responseHeaders2 } ,
299
+ { protocol : 'HTTPS' , method : 'POST' , path : '/' , headers : extraHeaders2 , body : { } ,
300
+ name : '6 Should accept the request using ' , responseHeaders : responseHeaders2 } ,
301
+ { protocol : 'HTTPS' , method : 'PUT' , path : '/' , headers : extraHeaders2 , body : { } ,
302
+ name : '7 Should accept the request using ' , responseHeaders : responseHeaders2 } ,
303
+ { protocol : 'HTTPS' , method : 'DELETE' , path : '/' , headers : extraHeaders2 , body : { } ,
304
+ name : '8 Should accept the request using ' , responseHeaders : responseHeaders2 }
243
305
] ;
244
306
245
307
for ( i = 0 ; i < dataSetHTTPS . length ; i ++ ) {
@@ -335,6 +397,33 @@ describe('Single Feature: Extra header ' + '#FEH', function() {
335
397
}
336
398
} ) ;
337
399
400
+ describe ( 'Retrieve request with an invalid ExtraHeader #FEH' , function ( ) {
401
+
402
+ var INVALID_HEADER = 'Accept-Value' ;
403
+
404
+ var extraHeaders = {
405
+ 'X-Relayer-Header' : [
406
+ encodeURIComponent ( 'X: X-relayer-NoHost:localhost:8000' ) ,
407
+ encodeURIComponent ( 'Fake-User-Agent:Mozilla/5.0 (Macintosh++; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.57 ' ) ,
408
+ encodeURIComponent ( INVALID_HEADER )
409
+ ] . join ( ', ' ) } ;
410
+
411
+ var dataSetHTTP = [
412
+ { protocol : 'http' , method : 'GET' , path : '/' , headers : extraHeaders , body : { } ,
413
+ name : '1 Should not accept the request: ' + INVALID_HEADER + ' has not a defined value using ' , invalidHeader : INVALID_HEADER } ,
414
+ { protocol : 'http' , method : 'POST' , path : '/' , headers : extraHeaders , body : { } ,
415
+ name : '2 Should not accept the request: ' + INVALID_HEADER + ' has not a defined value using ' , invalidHeader : INVALID_HEADER } ,
416
+ { protocol : 'http' , method : 'PUT' , path : '/' , headers : extraHeaders , body : { } ,
417
+ name : '3 Should not accept the request: ' + INVALID_HEADER + ' has not a defined value using ' , invalidHeader : INVALID_HEADER } ,
418
+ { protocol : 'http' , method : 'DELETE' , path : '/' , headers : extraHeaders , body : { } ,
419
+ name : '4 Should not accept the request: ' + INVALID_HEADER + ' has not a defined value using ' , invalidHeader : INVALID_HEADER }
420
+ ] ;
421
+
422
+ for ( i = 0 ; i < dataSetHTTP . length ; i ++ ) {
423
+ _invalidHeadersValue ( dataSetHTTP [ i ] ) ; //Launch every test in data set
424
+ }
425
+ } ) ;
426
+
338
427
339
428
} ) ;
340
429
0 commit comments