String redirectUri = resetPasswordResponse.getRedirectUri(); if (!StringUtils.hasText(redirectUri) || redirectUri.equals("home")) { response.sendRedirect(request.getContextPath() + "/login?success=password_reset");
@Test public void test_happy_day_password_reset_with_redirect() throws Exception { reset(service); resetPasswordResponse = new ResetPasswordService.ResetPasswordResponse(user, "http://test.com", null); when(service.resetPassword(any(ExpiringCode.class), eq(password))).thenReturn(resetPasswordResponse); happy_day_password_reset(resetPasswordResponse.getRedirectUri()); }
@Test public void test_happy_day_password_reset_with_null_redirect() throws Exception { reset(service); resetPasswordResponse = new ResetPasswordService.ResetPasswordResponse(user, null, null); when(service.resetPassword(any(ExpiringCode.class), eq(password))).thenReturn(resetPasswordResponse); happy_day_password_reset(resetPasswordResponse.getRedirectUri()); }
@Test public void test_happy_day_password_reset() throws Exception { happy_day_password_reset(resetPasswordResponse.getRedirectUri()); }
@Test public void resetPassword_WithNoClientId() { ExpiringCode code = setupResetPassword("", "redirect.example.com"); ResetPasswordResponse response = uaaResetPasswordService.resetPassword(code, "new_secret"); assertEquals("home", response.getRedirectUri()); }
@Test public void resetPassword_WithInvalidClientId() { ExpiringCode code = setupResetPassword("invalid_client", "redirect.example.com"); doThrow(new NoSuchClientException("no such client")).when(clientDetailsService).loadClientByClientId("invalid_client", "uaa"); ResetPasswordResponse response = uaaResetPasswordService.resetPassword(code, "new_secret"); assertEquals("home", response.getRedirectUri()); }
@Test public void resetPassword_WithNoRedirectUri() { ExpiringCode code = setupResetPassword("example", ""); BaseClientDetails client = new BaseClientDetails(); client.setRegisteredRedirectUri(Collections.singleton("redirect.example.com/*")); when(clientDetailsService.loadClientByClientId("example")).thenReturn(client); ResetPasswordResponse response = uaaResetPasswordService.resetPassword(code, "new_secret"); assertEquals("home", response.getRedirectUri()); } @Test
@Test public void testResetPassword() throws Exception { ExpiringCode code = setupResetPassword("example", "redirect.example.com/login"); BaseClientDetails client = new BaseClientDetails(); client.setRegisteredRedirectUri(Collections.singleton("redirect.example.com/*")); when(clientDetailsService.loadClientByClientId("example", "uaa")).thenReturn(client); ResetPasswordResponse response = uaaResetPasswordService.resetPassword(code, "new_secret"); Assert.assertEquals("usermans-id", response.getUser().getId()); Assert.assertEquals("userman", response.getUser().getUserName()); Assert.assertEquals("redirect.example.com/login", response.getRedirectUri()); }
@Test public void resetPassword_WhereWildcardsDoNotMatch() { ExpiringCode code = setupResetPassword("example", "redirect.example.com"); BaseClientDetails client = new BaseClientDetails(); client.setRegisteredRedirectUri(Collections.singleton("doesnotmatch.example.com/*")); when(clientDetailsService.loadClientByClientId("example", "uaa")).thenReturn(client); ResetPasswordResponse response = uaaResetPasswordService.resetPassword(code, "new_secret"); assertEquals("home", response.getRedirectUri()); }