@@ -191,19 +191,35 @@ describe('AuthorizeHandler integration', () => {
191191
192192 it ( 'should throw an error if `allowed` is `false`' , ( ) => {
193193 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+ }
197206 } ;
198207 const handler = new AuthorizeHandler ( {
199208 authorizationCodeLifetime : 120 ,
200209 model,
201210 } ) ;
202211 const request = new Request ( {
203- body : { } ,
204- headers : { } ,
212+ body : {
213+ client_id : 'test'
214+ } ,
215+ headers : {
216+ 'Authorization' : 'Bearer foo'
217+ } ,
205218 method : 'ANY' ,
206- query : { allowed : 'false' } ,
219+ query : {
220+ allowed : 'false' ,
221+ state : 'foobar'
222+ }
207223 } ) ;
208224 const response = new Response ( { body : { } , headers : { } } ) ;
209225
@@ -217,6 +233,11 @@ describe('AuthorizeHandler integration', () => {
217233 e . message . should . equal (
218234 'Access denied: user denied access to application' ,
219235 ) ;
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+ ) ;
220241 } ) ;
221242 } ) ;
222243
@@ -419,7 +440,7 @@ describe('AuthorizeHandler integration', () => {
419440 response
420441 . get ( 'location' )
421442 . 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 ' ,
423444 ) ;
424445 } ) ;
425446 } ) ;
@@ -509,7 +530,7 @@ describe('AuthorizeHandler integration', () => {
509530 should . fail ( 'should.fail' , '' ) ;
510531 } )
511532 . 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 ' ) ;
513534 } ) ;
514535 } ) ;
515536
0 commit comments