@@ -25,7 +25,16 @@ describe('OAuth2Strategy', function() {
25
25
return cb ( null , 'foos7473' ) ;
26
26
} ;
27
27
28
- CustomStore . prototype . verify = function ( req , state , cb ) {
28
+ CustomStore . prototype . verify = function ( req , state , meta , cb ) {
29
+ if ( req . url === '/error' ) { return cb ( new Error ( 'something went wrong verifying state' ) ) ; }
30
+ if ( req . url === '/exception' ) { throw new Error ( 'something went horribly wrong verifying state' ) ; }
31
+
32
+ if ( req . url !== '/auth/example/callback' ) { return cb ( new Error ( 'incorrect req argument' ) ) ; }
33
+ if ( state !== 'foos7473' ) { return cb ( new Error ( 'incorrect state argument' ) ) ; }
34
+ if ( meta . authorizationURL !== 'https://www.example.com/oauth2/authorize' ) { return cb ( new Error ( 'incorrect meta.authorizationURL argument' ) ) ; }
35
+ if ( meta . tokenURL !== 'https://www.example.com/oauth2/token' ) { return cb ( new Error ( 'incorrect meta.tokenURL argument' ) ) ; }
36
+ if ( meta . clientID !== 'ABC123' ) { return callback ( new Error ( 'incorrect meta.clientID argument' ) ) ; }
37
+
29
38
req . customStoreVerifyCalled = req . customStoreVerifyCalled ? req . customStoreVerifyCalled ++ : 1 ;
30
39
return cb ( null , true ) ;
31
40
} ;
@@ -157,6 +166,7 @@ describe('OAuth2Strategy', function() {
157
166
. req ( function ( req ) {
158
167
request = req ;
159
168
169
+ req . url = '/auth/example/callback' ;
160
170
req . query = { } ;
161
171
req . query . code = 'SplxlOBeZQQYbYS6WxSbIA' ;
162
172
req . query . state = 'foos7473' ;
@@ -179,6 +189,60 @@ describe('OAuth2Strategy', function() {
179
189
} ) ;
180
190
} ) ; // that was approved
181
191
192
+ describe ( 'that errors due to custom store supplying error' , function ( ) {
193
+ var request
194
+ , err ;
195
+
196
+ before ( function ( done ) {
197
+ chai . passport . use ( strategy )
198
+ . error ( function ( e ) {
199
+ err = e ;
200
+ done ( ) ;
201
+ } )
202
+ . req ( function ( req ) {
203
+ request = req ;
204
+
205
+ req . url = '/error' ;
206
+ req . query = { } ;
207
+ req . query . code = 'SplxlOBeZQQYbYS6WxSbIA' ;
208
+ req . query . state = 'foos7473' ;
209
+ } )
210
+ . authenticate ( ) ;
211
+ } ) ;
212
+
213
+ it ( 'should error' , function ( ) {
214
+ expect ( err ) . to . be . an . instanceof ( Error ) ;
215
+ expect ( err . message ) . to . equal ( 'something went wrong verifying state' ) ;
216
+ } ) ;
217
+ } ) ; // that errors due to custom store supplying error
218
+
219
+ describe ( 'that errors due to custom store throwing error' , function ( ) {
220
+ var request
221
+ , err ;
222
+
223
+ before ( function ( done ) {
224
+ chai . passport . use ( strategy )
225
+ . error ( function ( e ) {
226
+ err = e ;
227
+ done ( ) ;
228
+ } )
229
+ . req ( function ( req ) {
230
+ request = req ;
231
+
232
+ req . url = '/exception' ;
233
+ req . query = { } ;
234
+ req . query . code = 'SplxlOBeZQQYbYS6WxSbIA' ;
235
+ req . query . state = 'foos7473' ;
236
+ } )
237
+ . authenticate ( ) ;
238
+ } ) ;
239
+
240
+ it ( 'should error' , function ( ) {
241
+ expect ( err ) . to . be . an . instanceof ( Error ) ;
242
+ expect ( err . message ) . to . equal ( 'something went horribly wrong verifying state' ) ;
243
+ } ) ;
244
+ } ) ; // that errors due to custom store throwing error
245
+
182
246
} ) ; // processing response to authorization request
183
247
184
248
} ) ; // with custom state store that accepts meta argument
0 commit comments