@@ -17,6 +17,7 @@ describe('middlewares', () => {
17
17
return fakeReq . headers [ key . toLowerCase ( ) ]
18
18
}
19
19
} ;
20
+ fakeRes = jasmine . createSpyObj ( 'fakeRes' , [ 'end' , 'status' ] ) ;
20
21
AppCache . put ( fakeReq . body . _ApplicationId , { } ) ;
21
22
} ) ;
22
23
@@ -35,6 +36,59 @@ describe('middlewares', () => {
35
36
} ) ;
36
37
} ) ;
37
38
39
+ it ( 'should give invalid response when keys are configured but no key supplied' , ( ) => {
40
+ AppCache . put ( fakeReq . body . _ApplicationId , {
41
+ masterKey : 'masterKey' ,
42
+ restAPIKey : 'restAPIKey'
43
+ } ) ;
44
+ middlewares . handleParseHeaders ( fakeReq , fakeRes ) ;
45
+ expect ( fakeRes . status ) . toHaveBeenCalledWith ( 403 ) ;
46
+ } ) ;
47
+
48
+ it ( 'should give invalid response when keys are configured but supplied key is incorrect' , ( ) => {
49
+ AppCache . put ( fakeReq . body . _ApplicationId , {
50
+ masterKey : 'masterKey' ,
51
+ restAPIKey : 'restAPIKey'
52
+ } ) ;
53
+ fakeReq . headers [ 'x-parse-rest-api-key' ] = 'wrongKey' ;
54
+ middlewares . handleParseHeaders ( fakeReq , fakeRes ) ;
55
+ expect ( fakeRes . status ) . toHaveBeenCalledWith ( 403 ) ;
56
+ } ) ;
57
+
58
+ it ( 'should give invalid response when keys are configured but different key is supplied' , ( ) => {
59
+ AppCache . put ( fakeReq . body . _ApplicationId , {
60
+ masterKey : 'masterKey' ,
61
+ restAPIKey : 'restAPIKey'
62
+ } ) ;
63
+ fakeReq . headers [ 'x-parse-client-key' ] = 'clientKey' ;
64
+ middlewares . handleParseHeaders ( fakeReq , fakeRes ) ;
65
+ expect ( fakeRes . status ) . toHaveBeenCalledWith ( 403 ) ;
66
+ } ) ;
67
+
68
+
69
+ it ( 'should succeed when any one of the configured keys supplied' , ( done ) => {
70
+ AppCache . put ( fakeReq . body . _ApplicationId , {
71
+ clientKey : 'clientKey' ,
72
+ masterKey : 'masterKey' ,
73
+ restAPIKey : 'restAPIKey'
74
+ } ) ;
75
+ fakeReq . headers [ 'x-parse-rest-api-key' ] = 'restAPIKey' ;
76
+ middlewares . handleParseHeaders ( fakeReq , fakeRes , ( ) => {
77
+ expect ( fakeRes . status ) . not . toHaveBeenCalled ( ) ;
78
+ done ( ) ;
79
+ } ) ;
80
+ } ) ;
81
+
82
+ it ( 'should succeed when no keys are configured and none supplied' , ( done ) => {
83
+ AppCache . put ( fakeReq . body . _ApplicationId , {
84
+ masterKey : 'masterKey'
85
+ } ) ;
86
+ middlewares . handleParseHeaders ( fakeReq , fakeRes , ( ) => {
87
+ expect ( fakeRes . status ) . not . toHaveBeenCalled ( ) ;
88
+ done ( ) ;
89
+ } ) ;
90
+ } ) ;
91
+
38
92
const BodyParams = {
39
93
clientVersion : '_ClientVersion' ,
40
94
installationId : '_InstallationId' ,
0 commit comments