@@ -153,16 +153,42 @@ describe('middlewares', () => {
153
153
} ) ;
154
154
155
155
it ( 'can allow all with masterKeyIPs' , async ( ) => {
156
- const logger = require ( '../lib/logger' ) . logger ;
157
- spyOn ( logger , 'error' ) . and . callFake ( ( ) => { } ) ;
158
- AppCache . put ( fakeReq . body . _ApplicationId , {
159
- masterKey : 'masterKey' ,
160
- masterKeyIps : [ '::/0' ] ,
161
- } ) ;
162
- fakeReq . ip = '::ffff:192.168.0.101' ;
163
- fakeReq . headers [ 'x-parse-master-key' ] = 'masterKey' ;
164
- await new Promise ( resolve => middlewares . handleParseHeaders ( fakeReq , fakeRes , resolve ) ) ;
165
- expect ( fakeReq . auth . isMaster ) . toBe ( true ) ;
156
+ const combinations = [
157
+ {
158
+ masterKeyIps : [ '::/0' ] ,
159
+ ips : [ '::ffff:192.168.0.101' , '192.168.0.101' ] ,
160
+ id : 'allowAllIpV6' ,
161
+ } ,
162
+ {
163
+ masterKeyIps : [ '0.0.0.0' ] ,
164
+ ips : [ '192.168.0.101' ] ,
165
+ id : 'allowAllIpV4' ,
166
+ } ,
167
+ ] ;
168
+ for ( const combination of combinations ) {
169
+ AppCache . put ( combination . id , {
170
+ masterKey : 'masterKey' ,
171
+ masterKeyIps : combination . masterKeyIps ,
172
+ } ) ;
173
+ await new Promise ( resolve => setTimeout ( resolve , 10 ) ) ;
174
+ for ( const ip of combination . ips ) {
175
+ fakeReq = {
176
+ originalUrl : 'http://example.com/parse/' ,
177
+ url : 'http://example.com/' ,
178
+ body : {
179
+ _ApplicationId : combination . id ,
180
+ } ,
181
+ headers : { } ,
182
+ get : key => {
183
+ return fakeReq . headers [ key . toLowerCase ( ) ] ;
184
+ } ,
185
+ } ;
186
+ fakeReq . ip = ip ;
187
+ fakeReq . headers [ 'x-parse-master-key' ] = 'masterKey' ;
188
+ await new Promise ( resolve => middlewares . handleParseHeaders ( fakeReq , fakeRes , resolve ) ) ;
189
+ expect ( fakeReq . auth . isMaster ) . toBe ( true ) ;
190
+ }
191
+ }
166
192
} ) ;
167
193
168
194
it ( 'can allow localhost with masterKeyIPs' , async ( ) => {
0 commit comments