@@ -12,8 +12,14 @@ describe('OAuth2Strategy', function() {
12
12
function CustomStore ( ) {
13
13
}
14
14
15
- CustomStore . prototype . store = function ( req , cb ) {
15
+ CustomStore . prototype . store = function ( req , meta , cb ) {
16
+ if ( req . url === '/error' ) { return cb ( new Error ( 'something went wrong storing state' ) ) ; }
17
+ if ( req . url === '/exception' ) { throw new Error ( 'something went horribly wrong storing state' ) ; }
18
+
16
19
if ( req . url !== '/me' ) { return cb ( new Error ( 'incorrect req argument' ) ) ; }
20
+ if ( meta . authorizationURL !== 'https://www.example.com/oauth2/authorize' ) { return cb ( new Error ( 'incorrect meta.authorizationURL argument' ) ) ; }
21
+ if ( meta . tokenURL !== 'https://www.example.com/oauth2/token' ) { return cb ( new Error ( 'incorrect meta.tokenURL argument' ) ) ; }
22
+ if ( meta . clientID !== 'ABC123' ) { return callback ( new Error ( 'incorrect meta.clientID argument' ) ) ; }
17
23
18
24
req . customStoreStoreCalled = req . customStoreStoreCalled ? req . customStoreStoreCalled ++ : 1 ;
19
25
return cb ( null , 'foos7473' ) ;
@@ -60,6 +66,50 @@ describe('OAuth2Strategy', function() {
60
66
} ) ;
61
67
} ) ; // that redirects to service provider
62
68
69
+ describe ( 'that errors due to custom store supplying error' , function ( ) {
70
+ var request , err ;
71
+
72
+ before ( function ( done ) {
73
+ chai . passport . use ( strategy )
74
+ . error ( function ( e ) {
75
+ err = e ;
76
+ done ( ) ;
77
+ } )
78
+ . req ( function ( req ) {
79
+ request = req ;
80
+ req . url = '/error' ;
81
+ } )
82
+ . authenticate ( ) ;
83
+ } ) ;
84
+
85
+ it ( 'should error' , function ( ) {
86
+ expect ( err ) . to . be . an . instanceof ( Error ) ;
87
+ expect ( err . message ) . to . equal ( 'something went wrong storing state' ) ;
88
+ } ) ;
89
+ } ) ; // that errors due to custom store supplying error
90
+
91
+ describe ( 'that errors due to custom store throwing error' , function ( ) {
92
+ var request , err ;
93
+
94
+ before ( function ( done ) {
95
+ chai . passport . use ( strategy )
96
+ . error ( function ( e ) {
97
+ err = e ;
98
+ done ( ) ;
99
+ } )
100
+ . req ( function ( req ) {
101
+ request = req ;
102
+ req . url = '/exception' ;
103
+ } )
104
+ . authenticate ( ) ;
105
+ } ) ;
106
+
107
+ it ( 'should error' , function ( ) {
108
+ expect ( err ) . to . be . an . instanceof ( Error ) ;
109
+ expect ( err . message ) . to . equal ( 'something went horribly wrong storing state' ) ;
110
+ } ) ;
111
+ } ) ; // that errors due to custom store throwing error
112
+
63
113
} ) ; // issuing authorization request
64
114
65
115
} ) ; // with custom state store that accepts meta argument
0 commit comments