@@ -25,7 +25,9 @@ describe('OAuth2Strategy', function() {
25
25
return cb ( null , 'foos7473' ) ;
26
26
} ;
27
27
28
- CustomStore . prototype . verify = function ( req , state , meta , cb ) {
28
+ CustomStore . prototype . verify = function ( req , state , cb ) {
29
+ req . customStoreVerifyCalled = req . customStoreVerifyCalled ? req . customStoreVerifyCalled ++ : 1 ;
30
+ return cb ( null , true ) ;
29
31
} ;
30
32
31
33
@@ -61,7 +63,7 @@ describe('OAuth2Strategy', function() {
61
63
expect ( url ) . to . equal ( 'https://www.example.com/oauth2/authorize?response_type=code&redirect_uri=https%3A%2F%2Fwww.example.net%2Fauth%2Fexample%2Fcallback&state=foos7473&client_id=ABC123' ) ;
62
64
} ) ;
63
65
64
- it ( 'should store request token in custom store' , function ( ) {
66
+ it ( 'should serialize state using custom store' , function ( ) {
65
67
expect ( request . customStoreStoreCalled ) . to . equal ( 1 ) ;
66
68
} ) ;
67
69
} ) ; // that redirects to service provider
@@ -112,6 +114,73 @@ describe('OAuth2Strategy', function() {
112
114
113
115
} ) ; // issuing authorization request
114
116
117
+
118
+ describe ( 'processing response to authorization request' , function ( ) {
119
+ var strategy = new OAuth2Strategy ( {
120
+ authorizationURL : 'https://www.example.com/oauth2/authorize' ,
121
+ tokenURL : 'https://www.example.com/oauth2/token' ,
122
+ clientID : 'ABC123' ,
123
+ clientSecret : 'secret' ,
124
+ callbackURL : 'https://www.example.net/auth/example/callback' ,
125
+ store : new CustomStore ( )
126
+ } ,
127
+ function ( accessToken , refreshToken , profile , done ) {
128
+ if ( accessToken !== '2YotnFZFEjr1zCsicMWpAA' ) { return done ( new Error ( 'incorrect accessToken argument' ) ) ; }
129
+ if ( refreshToken !== 'tGzv3JOkF0XG5Qx2TlKWIA' ) { return done ( new Error ( 'incorrect refreshToken argument' ) ) ; }
130
+ if ( typeof profile !== 'object' ) { return done ( new Error ( 'incorrect profile argument' ) ) ; }
131
+ if ( Object . keys ( profile ) . length !== 0 ) { return done ( new Error ( 'incorrect profile argument' ) ) ; }
132
+
133
+ return done ( null , { id : '1234' } , { message : 'Hello' } ) ;
134
+ } ) ;
135
+
136
+ strategy . _oauth2 . getOAuthAccessToken = function ( code , options , callback ) {
137
+ if ( code !== 'SplxlOBeZQQYbYS6WxSbIA' ) { return callback ( new Error ( 'incorrect code argument' ) ) ; }
138
+ if ( options . grant_type !== 'authorization_code' ) { return callback ( new Error ( 'incorrect options.grant_type argument' ) ) ; }
139
+ if ( options . redirect_uri !== 'https://www.example.net/auth/example/callback' ) { return callback ( new Error ( 'incorrect options.redirect_uri argument' ) ) ; }
140
+
141
+ return callback ( null , '2YotnFZFEjr1zCsicMWpAA' , 'tGzv3JOkF0XG5Qx2TlKWIA' , { token_type : 'example' } ) ;
142
+ }
143
+
144
+
145
+ describe ( 'that was approved' , function ( ) {
146
+ var request
147
+ , user
148
+ , info ;
149
+
150
+ before ( function ( done ) {
151
+ chai . passport . use ( strategy )
152
+ . success ( function ( u , i ) {
153
+ user = u ;
154
+ info = i ;
155
+ done ( ) ;
156
+ } )
157
+ . req ( function ( req ) {
158
+ request = req ;
159
+
160
+ req . query = { } ;
161
+ req . query . code = 'SplxlOBeZQQYbYS6WxSbIA' ;
162
+ req . query . state = 'foos7473' ;
163
+ } )
164
+ . authenticate ( ) ;
165
+ } ) ;
166
+
167
+ it ( 'should supply user' , function ( ) {
168
+ expect ( user ) . to . be . an . object ;
169
+ expect ( user . id ) . to . equal ( '1234' ) ;
170
+ } ) ;
171
+
172
+ it ( 'should supply info' , function ( ) {
173
+ expect ( info ) . to . be . an . object ;
174
+ expect ( info . message ) . to . equal ( 'Hello' ) ;
175
+ } ) ;
176
+
177
+ it ( 'should verify state using custom store' , function ( ) {
178
+ expect ( request . customStoreVerifyCalled ) . to . equal ( 1 ) ;
179
+ } ) ;
180
+ } ) ; // that was approved
181
+
182
+ } ) ; // processing response to authorization request
183
+
115
184
} ) ; // with custom state store that accepts meta argument
116
185
117
186
} ) ;
0 commit comments