@@ -400,6 +400,56 @@ describe('OAuth2Strategy subclass', function() {
400
400
} ) ;
401
401
} ) ; // skipping user profile due to skipUserProfile asynchronously returning true
402
402
403
+ describe ( 'error due to skipUserProfile asynchronously returning error' , function ( ) {
404
+ var strategy = new FooOAuth2Strategy ( {
405
+ authorizationURL : 'https://www.example.com/oauth2/authorize' ,
406
+ tokenURL : 'https://www.example.com/oauth2/token' ,
407
+ clientID : 'ABC123' ,
408
+ clientSecret : 'secret' ,
409
+ callbackURL : 'https://www.example.net/auth/example/callback' ,
410
+ skipUserProfile : function ( accessToken , done ) {
411
+ return done ( new Error ( 'something went wrong' ) ) ;
412
+ }
413
+ } ,
414
+ function ( accessToken , refreshToken , profile , done ) {
415
+ if ( accessToken !== '2YotnFZFEjr1zCsicMWpAA' ) { return done ( new Error ( 'incorrect accessToken argument' ) ) ; }
416
+ if ( refreshToken !== 'tGzv3JOkF0XG5Qx2TlKWIA' ) { return done ( new Error ( 'incorrect refreshToken argument' ) ) ; }
417
+ if ( profile !== undefined ) { return done ( new Error ( 'incorrect profile argument' ) ) ; }
418
+
419
+ return done ( null , { id : '1234' } , { message : 'Hello' } ) ;
420
+ } ) ;
421
+
422
+ strategy . _oauth2 . getOAuthAccessToken = function ( code , options , callback ) {
423
+ if ( code !== 'SplxlOBeZQQYbYS6WxSbIA' ) { return callback ( new Error ( 'incorrect code argument' ) ) ; }
424
+ if ( options . grant_type !== 'authorization_code' ) { return callback ( new Error ( 'incorrect options.grant_type argument' ) ) ; }
425
+ if ( options . redirect_uri !== 'https://www.example.net/auth/example/callback' ) { return callback ( new Error ( 'incorrect options.redirect_uri argument' ) ) ; }
426
+
427
+ return callback ( null , '2YotnFZFEjr1zCsicMWpAA' , 'tGzv3JOkF0XG5Qx2TlKWIA' , { token_type : 'example' } ) ;
428
+ }
429
+
430
+
431
+ var request
432
+ , err ;
433
+
434
+ before ( function ( done ) {
435
+ chai . passport . use ( strategy )
436
+ . error ( function ( e ) {
437
+ err = e ;
438
+ done ( ) ;
439
+ } )
440
+ . req ( function ( req ) {
441
+ req . query = { } ;
442
+ req . query . code = 'SplxlOBeZQQYbYS6WxSbIA' ;
443
+ } )
444
+ . authenticate ( ) ;
445
+ } ) ;
446
+
447
+ it ( 'should error' , function ( ) {
448
+ expect ( err ) . to . be . an . instanceof ( Error )
449
+ expect ( err . message ) . to . equal ( 'something went wrong' ) ;
450
+ } ) ;
451
+ } ) ; // error due to skipUserProfile asynchronously returning error
452
+
403
453
} ) ; // that overrides userProfile
404
454
405
455
} ) ;
0 commit comments