@@ -99,4 +99,34 @@ describe('AuthorizeHandler', function() {
9999 . catch ( should . fail ) ;
100100 } ) ;
101101 } ) ;
102+
103+ describe ( 'validateRedirectUri()' , function ( ) {
104+ it ( 'should call `model.validateRedirectUri()`' , function ( ) {
105+ const client = { grants : [ 'authorization_code' ] , redirectUris : [ 'http://example.com/cb' ] } ;
106+ const redirect_uri = 'http://example.com/cb/2' ;
107+ const model = {
108+ getAccessToken : function ( ) { } ,
109+ getClient : sinon . stub ( ) . returns ( client ) ,
110+ saveAuthorizationCode : function ( ) { } ,
111+ validateRedirectUri : sinon . stub ( ) . returns ( true )
112+ } ;
113+ const handler = new AuthorizeHandler ( { authorizationCodeLifetime : 120 , model : model } ) ;
114+ const request = new Request ( { body : { client_id : 12345 , client_secret : 'secret' , redirect_uri } , headers : { } , method : { } , query : { } } ) ;
115+
116+ return handler . getClient ( request )
117+ . then ( function ( ) {
118+ model . getClient . callCount . should . equal ( 1 ) ;
119+ model . getClient . firstCall . args . should . have . length ( 2 ) ;
120+ model . getClient . firstCall . args [ 0 ] . should . equal ( 12345 ) ;
121+ model . getClient . firstCall . thisValue . should . equal ( model ) ;
122+
123+ model . validateRedirectUri . callCount . should . equal ( 1 ) ;
124+ model . validateRedirectUri . firstCall . args . should . have . length ( 2 ) ;
125+ model . validateRedirectUri . firstCall . args [ 0 ] . should . equal ( redirect_uri ) ;
126+ model . validateRedirectUri . firstCall . args [ 1 ] . should . equal ( client . redirectUris ) ;
127+ model . validateRedirectUri . firstCall . thisValue . should . equal ( model ) ;
128+ } )
129+ . catch ( should . fail ) ;
130+ } ) ;
131+ } ) ;
102132} ) ;
0 commit comments