@@ -128,5 +128,51 @@ describe('AuthorizeHandler', function() {
128
128
} )
129
129
. catch ( should . fail ) ;
130
130
} ) ;
131
+
132
+ it ( 'should be successful validation' , function ( ) {
133
+ const client = { grants : [ 'authorization_code' ] , redirectUris : [ 'http://example.com/cb' ] } ;
134
+ const redirect_uri = 'http://example.com/cb' ;
135
+ const model = {
136
+ getAccessToken : function ( ) { } ,
137
+ getClient : sinon . stub ( ) . returns ( client ) ,
138
+ saveAuthorizationCode : function ( ) { } ,
139
+ validateRedirectUri : function ( redirectUri , client ) {
140
+ return client . redirectUris . includes ( redirectUri ) ;
141
+ }
142
+ } ;
143
+
144
+ const handler = new AuthorizeHandler ( { authorizationCodeLifetime : 120 , model : model } ) ;
145
+ const request = new Request ( { body : { client_id : 12345 , client_secret : 'secret' , redirect_uri } , headers : { } , method : { } , query : { } } ) ;
146
+
147
+ return handler . getClient ( request )
148
+ . then ( ( client ) => {
149
+ client . should . equal ( client ) ;
150
+ } ) ;
151
+ } ) ;
152
+
153
+ it ( 'should be unsuccessful validation' , function ( ) {
154
+ const client = { grants : [ 'authorization_code' ] , redirectUris : [ 'http://example.com/cb' ] } ;
155
+ const redirect_uri = 'http://example.com/callback' ;
156
+ const model = {
157
+ getAccessToken : function ( ) { } ,
158
+ getClient : sinon . stub ( ) . returns ( client ) ,
159
+ saveAuthorizationCode : function ( ) { } ,
160
+ validateRedirectUri : function ( redirectUri , client ) {
161
+ return client . redirectUris . includes ( redirectUri ) ;
162
+ }
163
+ } ;
164
+
165
+ const handler = new AuthorizeHandler ( { authorizationCodeLifetime : 120 , model : model } ) ;
166
+ const request = new Request ( { body : { client_id : 12345 , client_secret : 'secret' , redirect_uri } , headers : { } , method : { } , query : { } } ) ;
167
+
168
+ return handler . getClient ( request )
169
+ . then ( ( ) => {
170
+ throw Error ( 'should not resolve' ) ;
171
+ } )
172
+ . catch ( ( err ) => {
173
+ err . name . should . equal ( 'invalid_client' ) ;
174
+ err . message . should . equal ( 'Invalid client: `redirect_uri` does not match client value' ) ;
175
+ } ) ;
176
+ } ) ;
131
177
} ) ;
132
178
} ) ;
0 commit comments