@@ -191,19 +191,35 @@ describe('AuthorizeHandler integration', () => {
191
191
192
192
it ( 'should throw an error if `allowed` is `false`' , ( ) => {
193
193
const model = {
194
- getAccessToken : ( ) => { } ,
195
- getClient : ( ) => { } ,
196
- saveAuthorizationCode : ( ) => { } ,
194
+ getAccessToken : function ( ) {
195
+ return {
196
+ user : { } ,
197
+ accessTokenExpiresAt : new Date ( new Date ( ) . getTime ( ) + 10000 )
198
+ } ;
199
+ } ,
200
+ getClient : function ( ) {
201
+ return { grants : [ 'authorization_code' ] , redirectUris : [ 'http://example.com/cb' ] } ;
202
+ } ,
203
+ saveAuthorizationCode : function ( ) {
204
+ throw new Error ( 'Unhandled exception' ) ;
205
+ }
197
206
} ;
198
207
const handler = new AuthorizeHandler ( {
199
208
authorizationCodeLifetime : 120 ,
200
209
model,
201
210
} ) ;
202
211
const request = new Request ( {
203
- body : { } ,
204
- headers : { } ,
212
+ body : {
213
+ client_id : 'test'
214
+ } ,
215
+ headers : {
216
+ 'Authorization' : 'Bearer foo'
217
+ } ,
205
218
method : 'ANY' ,
206
- query : { allowed : 'false' } ,
219
+ query : {
220
+ allowed : 'false' ,
221
+ state : 'foobar'
222
+ }
207
223
} ) ;
208
224
const response = new Response ( { body : { } , headers : { } } ) ;
209
225
@@ -217,6 +233,11 @@ describe('AuthorizeHandler integration', () => {
217
233
e . message . should . equal (
218
234
'Access denied: user denied access to application' ,
219
235
) ;
236
+ response
237
+ . get ( 'location' )
238
+ . should . equal (
239
+ 'http://example.com/cb?error=access_denied&error_description=Access%20denied%3A%20user%20denied%20access%20to%20application&state=foobar' ,
240
+ ) ;
220
241
} ) ;
221
242
} ) ;
222
243
@@ -419,7 +440,7 @@ describe('AuthorizeHandler integration', () => {
419
440
response
420
441
. get ( 'location' )
421
442
. should . equal (
422
- 'http://example.com/cb?error=invalid_scope&error_description=Invalid%20parameter%3A%20%60scope%60' ,
443
+ 'http://example.com/cb?error=invalid_scope&error_description=Invalid%20parameter%3A%20%60scope%60&state=foobar ' ,
423
444
) ;
424
445
} ) ;
425
446
} ) ;
@@ -509,7 +530,7 @@ describe('AuthorizeHandler integration', () => {
509
530
should . fail ( 'should.fail' , '' ) ;
510
531
} )
511
532
. catch ( function ( ) {
512
- response . get ( 'location' ) . should . equal ( 'http://example.com/cb?error=invalid_scope&error_description=Invalid%20scope%3A%20Requested%20scope%20is%20invalid' ) ;
533
+ response . get ( 'location' ) . should . equal ( 'http://example.com/cb?error=invalid_scope&error_description=Invalid%20scope%3A%20Requested%20scope%20is%20invalid&state=foobar ' ) ;
513
534
} ) ;
514
535
} ) ;
515
536
0 commit comments