@@ -12,7 +12,7 @@ describe('middlewares', () => {
12
12
_ApplicationId : 'FakeAppId' ,
13
13
} ,
14
14
headers : { } ,
15
- get : key => {
15
+ get : ( key ) => {
16
16
return fakeReq . headers [ key . toLowerCase ( ) ] ;
17
17
} ,
18
18
} ;
@@ -24,7 +24,7 @@ describe('middlewares', () => {
24
24
AppCache . del ( fakeReq . body . _ApplicationId ) ;
25
25
} ) ;
26
26
27
- it ( 'should use _ContentType if provided' , done => {
27
+ it ( 'should use _ContentType if provided' , ( done ) => {
28
28
expect ( fakeReq . headers [ 'content-type' ] ) . toEqual ( undefined ) ;
29
29
const contentType = 'image/jpeg' ;
30
30
fakeReq . body . _ContentType = contentType ;
@@ -64,7 +64,7 @@ describe('middlewares', () => {
64
64
expect ( fakeRes . status ) . toHaveBeenCalledWith ( 403 ) ;
65
65
} ) ;
66
66
67
- it ( 'should succeed when any one of the configured keys supplied' , done => {
67
+ it ( 'should succeed when any one of the configured keys supplied' , ( done ) => {
68
68
AppCache . put ( fakeReq . body . _ApplicationId , {
69
69
clientKey : 'clientKey' ,
70
70
masterKey : 'masterKey' ,
@@ -77,7 +77,7 @@ describe('middlewares', () => {
77
77
} ) ;
78
78
} ) ;
79
79
80
- it ( 'should succeed when client key supplied but empty' , done => {
80
+ it ( 'should succeed when client key supplied but empty' , ( done ) => {
81
81
AppCache . put ( fakeReq . body . _ApplicationId , {
82
82
clientKey : '' ,
83
83
masterKey : 'masterKey' ,
@@ -90,7 +90,7 @@ describe('middlewares', () => {
90
90
} ) ;
91
91
} ) ;
92
92
93
- it ( 'should succeed when no keys are configured and none supplied' , done => {
93
+ it ( 'should succeed when no keys are configured and none supplied' , ( done ) => {
94
94
AppCache . put ( fakeReq . body . _ApplicationId , {
95
95
masterKey : 'masterKey' ,
96
96
} ) ;
@@ -110,22 +110,22 @@ describe('middlewares', () => {
110
110
111
111
const BodyKeys = Object . keys ( BodyParams ) ;
112
112
113
- BodyKeys . forEach ( infoKey => {
113
+ BodyKeys . forEach ( ( infoKey ) => {
114
114
const bodyKey = BodyParams [ infoKey ] ;
115
115
const keyValue = 'Fake' + bodyKey ;
116
116
// javascriptKey is the only one that gets defaulted,
117
117
const otherKeys = BodyKeys . filter (
118
- otherKey => otherKey !== infoKey && otherKey !== 'javascriptKey'
118
+ ( otherKey ) => otherKey !== infoKey && otherKey !== 'javascriptKey'
119
119
) ;
120
120
121
- it ( `it should pull ${ bodyKey } into req.info` , done => {
121
+ it ( `it should pull ${ bodyKey } into req.info` , ( done ) => {
122
122
fakeReq . body [ bodyKey ] = keyValue ;
123
123
124
124
middlewares . handleParseHeaders ( fakeReq , fakeRes , ( ) => {
125
125
expect ( fakeReq . body [ bodyKey ] ) . toEqual ( undefined ) ;
126
126
expect ( fakeReq . info [ infoKey ] ) . toEqual ( keyValue ) ;
127
127
128
- otherKeys . forEach ( otherKey => {
128
+ otherKeys . forEach ( ( otherKey ) => {
129
129
expect ( fakeReq . info [ otherKey ] ) . toEqual ( undefined ) ;
130
130
} ) ;
131
131
@@ -145,7 +145,7 @@ describe('middlewares', () => {
145
145
expect ( fakeRes . status ) . toHaveBeenCalledWith ( 403 ) ;
146
146
} ) ;
147
147
148
- it ( 'should succeed if the ip does belong to masterKeyIps list' , done => {
148
+ it ( 'should succeed if the ip does belong to masterKeyIps list' , ( done ) => {
149
149
AppCache . put ( fakeReq . body . _ApplicationId , {
150
150
masterKey : 'masterKey' ,
151
151
masterKeyIps : [ 'ip1' , 'ip2' ] ,
@@ -169,7 +169,7 @@ describe('middlewares', () => {
169
169
expect ( fakeRes . status ) . toHaveBeenCalledWith ( 403 ) ;
170
170
} ) ;
171
171
172
- it ( 'should succeed if the connection.remoteAddress does belong to masterKeyIps list' , done => {
172
+ it ( 'should succeed if the connection.remoteAddress does belong to masterKeyIps list' , ( done ) => {
173
173
AppCache . put ( fakeReq . body . _ApplicationId , {
174
174
masterKey : 'masterKey' ,
175
175
masterKeyIps : [ 'ip1' , 'ip2' ] ,
@@ -193,7 +193,7 @@ describe('middlewares', () => {
193
193
expect ( fakeRes . status ) . toHaveBeenCalledWith ( 403 ) ;
194
194
} ) ;
195
195
196
- it ( 'should succeed if the socket.remoteAddress does belong to masterKeyIps list' , done => {
196
+ it ( 'should succeed if the socket.remoteAddress does belong to masterKeyIps list' , ( done ) => {
197
197
AppCache . put ( fakeReq . body . _ApplicationId , {
198
198
masterKey : 'masterKey' ,
199
199
masterKeyIps : [ 'ip1' , 'ip2' ] ,
@@ -217,7 +217,7 @@ describe('middlewares', () => {
217
217
expect ( fakeRes . status ) . toHaveBeenCalledWith ( 403 ) ;
218
218
} ) ;
219
219
220
- it ( 'should succeed if the connection.socket.remoteAddress does belong to masterKeyIps list' , done => {
220
+ it ( 'should succeed if the connection.socket.remoteAddress does belong to masterKeyIps list' , ( done ) => {
221
221
AppCache . put ( fakeReq . body . _ApplicationId , {
222
222
masterKey : 'masterKey' ,
223
223
masterKeyIps : [ 'ip1' , 'ip2' ] ,
@@ -230,7 +230,7 @@ describe('middlewares', () => {
230
230
} ) ;
231
231
} ) ;
232
232
233
- it ( 'should allow any ip to use masterKey if masterKeyIps is empty' , done => {
233
+ it ( 'should allow any ip to use masterKey if masterKeyIps is empty' , ( done ) => {
234
234
AppCache . put ( fakeReq . body . _ApplicationId , {
235
235
masterKey : 'masterKey' ,
236
236
masterKeyIps : [ ] ,
@@ -243,7 +243,7 @@ describe('middlewares', () => {
243
243
} ) ;
244
244
} ) ;
245
245
246
- it ( 'should succeed if xff header does belong to masterKeyIps' , done => {
246
+ it ( 'should succeed if xff header does belong to masterKeyIps' , ( done ) => {
247
247
AppCache . put ( fakeReq . body . _ApplicationId , {
248
248
masterKey : 'masterKey' ,
249
249
masterKeyIps : [ 'ip1' ] ,
@@ -256,7 +256,7 @@ describe('middlewares', () => {
256
256
} ) ;
257
257
} ) ;
258
258
259
- it ( 'should succeed if xff header with one ip does belong to masterKeyIps' , done => {
259
+ it ( 'should succeed if xff header with one ip does belong to masterKeyIps' , ( done ) => {
260
260
AppCache . put ( fakeReq . body . _ApplicationId , {
261
261
masterKey : 'masterKey' ,
262
262
masterKeyIps : [ 'ip1' ] ,
@@ -357,7 +357,7 @@ describe('middlewares', () => {
357
357
) ;
358
358
} ) ;
359
359
360
- it ( 'should use user provided on field userFromJWT' , done => {
360
+ it ( 'should use user provided on field userFromJWT' , ( done ) => {
361
361
AppCache . put ( fakeReq . body . _ApplicationId , {
362
362
masterKey : 'masterKey' ,
363
363
} ) ;
@@ -367,4 +367,17 @@ describe('middlewares', () => {
367
367
done ( ) ;
368
368
} ) ;
369
369
} ) ;
370
+
371
+ it ( 'should give invalid response when upload file without x-parse-application-id in header' , ( ) => {
372
+ AppCache . put ( fakeReq . body . _ApplicationId , {
373
+ masterKey : 'masterKey' ,
374
+ } ) ;
375
+ fakeReq . body = Buffer . from ( 'fake-file' ) ;
376
+ console . log ( 'fakeReq.body.constructor' ) ;
377
+ console . log ( fakeReq . body . constructor ) ;
378
+ console . log ( 'fakeReq.body instanceof Buffer' ) ;
379
+ console . log ( fakeReq . body instanceof Buffer ) ;
380
+ middlewares . handleParseHeaders ( fakeReq , fakeRes ) ;
381
+ expect ( fakeRes . status ) . toHaveBeenCalledWith ( 403 ) ;
382
+ } ) ;
370
383
} ) ;
0 commit comments