@@ -108,7 +108,8 @@ public void when_response_type_not_supported_return_error_unsupported_response_t
108108 HttpRequest req = mock (HttpRequest .class );
109109 willReturn ("http://localhost/oauth20/authorize?client_id=1232&response_type=no" ).given (req )
110110 .getUri ();
111- willReturn (true ).given (authServer ).isActiveClientId ("1232" );
111+ ClientCredentials client = new ClientCredentials ();
112+ willReturn (client ).given (authServer ).getActiveClientCredentials ("1232" );
112113
113114 // WHEN
114115 HttpResponseStatus status = null ;
@@ -132,7 +133,8 @@ public void when_redirect_uri_not_valid_return_error_invalid_redirect_uri() {
132133 willReturn (
133134 "http://localhost/oauth20/authorize?client_id=1232&response_type=code&redirect_uri=tp%3A%2F%2Fexample.com" )
134135 .given (req ).getUri ();
135- willReturn (true ).given (authServer ).isActiveClientId ("1232" );
136+ ClientCredentials client = new ClientCredentials ();
137+ willReturn (client ).given (authServer ).getActiveClientCredentials ("1232" );
136138
137139 // WHEN
138140 HttpResponseStatus status = null ;
@@ -201,36 +203,36 @@ public void when_valid_client_id_and_active_status_return_true() throws Exceptio
201203 given (authServer .db .findClientCredentials (clientId )).willReturn (creds );
202204
203205 // WHEN
204- boolean result = authServer .isActiveClientId (clientId );
206+ ClientCredentials result = authServer .getActiveClientCredentials (clientId );
205207
206208 // THEN
207- assertTrue (result );
209+ assertNotNull (result );
208210 }
209211
210212 @ Test
211- public void when_valid_client_id_and_inactive_status_return_true () throws Exception {
213+ public void when_valid_client_id_and_inactive_status_return_null () throws Exception {
212214 // GIVEN
213215 ClientCredentials creds = mock (ClientCredentials .class );
214216 given (creds .getStatus ()).willReturn (ClientCredentials .INACTIVE_STATUS );
215217 given (authServer .db .findClientCredentials (clientId )).willReturn (creds );
216218
217219 // WHEN
218- boolean result = authServer .isActiveClientId (clientId );
220+ ClientCredentials result = authServer .getActiveClientCredentials (clientId );
219221
220222 // THEN
221- assertFalse (result );
223+ assertNull (result );
222224 }
223225
224226 @ Test
225- public void when_not_valid_client_id_return_false () throws Exception {
227+ public void when_not_valid_client_id_return_null () throws Exception {
226228 // GIVEN
227229 String clienId = "203598599234220" ;
228230
229231 // WHEN
230- boolean result = authServer .isActiveClientId ( clienId );
232+ ClientCredentials result = authServer .getActiveClientCredentials ( clientId );
231233
232234 // THEN
233- assertFalse (result );
235+ assertNull (result );
234236 }
235237
236238 @ Test
@@ -241,7 +243,6 @@ public void when_issue_auth_code_validate_client_id() throws Exception {
241243 mock (ClientCredentials .class ));
242244 given (req .getUri ())
243245 .willReturn ("http://example.com/oauth20/authorize?client_id=" + clientId );
244- String response ="" ;
245246
246247 // WHEN
247248 try {
@@ -251,7 +252,7 @@ public void when_issue_auth_code_validate_client_id() throws Exception {
251252 }
252253
253254 // THEN
254- verify (authServer ).isActiveClientId (clientId );
255+ verify (authServer ).getActiveClientCredentials (clientId );
255256 }
256257
257258 @ Test
@@ -298,6 +299,55 @@ public void when_issue_auth_code_verify_state_returned() throws Exception {
298299 assertTrue (response .contains (state ));
299300 }
300301
302+ @ Test
303+ public void when_issue_auth_code_if_no_redirect_uri_use_client_app_redirect_uri () throws Exception {
304+ // GIVEN
305+ HttpRequest req = mock (HttpRequest .class );
306+ ClientCredentials client = mock (ClientCredentials .class );
307+ String state = "someState" ;
308+ given (client .getStatus ()).willReturn (ClientCredentials .ACTIVE_STATUS );
309+ given (client .getUri ()).willReturn ("http://localhost:8080" );
310+ given (authServer .db .findClientCredentials (clientId )).willReturn (client );
311+
312+ given (req .getUri ())
313+ .willReturn (
314+ "http://example.com/oauth20/authorize?response_type=code&client_id=" +
315+ clientId + "&state=" + state );
316+ willReturn ("basic" ).given (authServer .scopeService ).getValidScope (null , clientId );
317+
318+ // WHEN
319+ String response = authServer .issueAuthorizationCode (req );
320+
321+ // THEN
322+ verify (authServer ).generateCode ();
323+ assertTrue (response .contains ("http://localhost:8080" ));
324+ }
325+
326+ @ Test
327+ public void when_issue_auth_code_with_redirect_uri_use_that_uri_in_response () throws Exception {
328+ // GIVEN
329+ HttpRequest req = mock (HttpRequest .class );
330+ ClientCredentials client = mock (ClientCredentials .class );
331+ String state = "someState" ;
332+ given (client .getStatus ()).willReturn (ClientCredentials .ACTIVE_STATUS );
333+ given (client .getUri ()).willReturn ("http://localhost:8080" );
334+ given (authServer .db .findClientCredentials (clientId )).willReturn (client );
335+ String redirectUri = "http://localhost:5000" ;
336+
337+ given (req .getUri ())
338+ .willReturn (
339+ "http://example.com/oauth20/authorize?response_type=code&redirect_uri=" + redirectUri +
340+ "&client_id=" + clientId + "&state=" + state );
341+ willReturn ("basic" ).given (authServer .scopeService ).getValidScope (null , clientId );
342+
343+ // WHEN
344+ String response = authServer .issueAuthorizationCode (req );
345+
346+ // THEN
347+ verify (authServer ).generateCode ();
348+ assertTrue (response .contains (redirectUri ));
349+ }
350+
301351 @ Test
302352 public void when_issue_token_and_client_id_not_the_same_as_token_return_error ()
303353 throws Exception {
0 commit comments