use of org.motechproject.security.exception.PasswordValidatorException in project motech by motech.
the class MotechUserServiceTest method shouldValidateNewPasswordWhenOldHasBeenExpired.
@Test(expected = PasswordValidatorException.class)
public void shouldValidateNewPasswordWhenOldHasBeenExpired() {
MotechUser motechUser = new MotechUser();
motechUser.setUserStatus(UserStatus.MUST_CHANGE_PASSWORD);
motechUser.setPassword(PASSWORD);
motechUser.setUserName(USER);
when(motechUsersDao.findByUserName(USER)).thenReturn(motechUser);
doThrow(new PasswordValidatorException("wrong")).when(validator).validate(NEW_PASSWORD);
motechUserService.changeExpiredPassword(USER, PASSWORD, NEW_PASSWORD);
}
use of org.motechproject.security.exception.PasswordValidatorException in project motech by motech.
the class MotechUserServiceTest method shouldValidatePasswordOnRegistration.
@Test(expected = PasswordValidatorException.class)
public void shouldValidatePasswordOnRegistration() {
doThrow(new PasswordValidatorException("error")).when(validator).validate("wrong");
motechUserService.register("user", "wrong", "email@gmail.com", "", Collections.<String>emptyList(), Locale.ENGLISH);
}
use of org.motechproject.security.exception.PasswordValidatorException in project motech by motech.
the class MotechUserServiceTest method shouldValidatePasswordOnChange.
@Test(expected = PasswordValidatorException.class)
public void shouldValidatePasswordOnChange() {
when(motechUsersDao.findByUserName("user")).thenReturn(user);
doThrow(new PasswordValidatorException("error")).when(validator).validate("wrong");
motechUserService.changePassword("user", "old", "wrong");
}
use of org.motechproject.security.exception.PasswordValidatorException in project motech by motech.
the class UserControllerTest method shouldPrintErrorsFromValidators.
@Test
public void shouldPrintErrorsFromValidators() throws Exception {
when(localeService.getUserLocale(any(HttpServletRequest.class))).thenReturn(Locale.GERMAN);
when(settingService.getPasswordValidator()).thenReturn(validator);
when(validator.getValidationError(Locale.GERMAN)).thenReturn("Error from validator");
doThrow(new PasswordValidatorException("error")).when(userService).register(eq("john"), eq("invalid"), eq("john@gmail.com"), eq(""), anyListOf(String.class), any(Locale.class));
UserDto userDto = new UserDto();
userDto.setUserName("john");
userDto.setEmail("john@gmail.com");
userDto.setPassword("invalid");
mockMvc.perform(post("/users/create").body(new ObjectMapper().writeValueAsBytes(userDto)).contentType(MediaType.APPLICATION_JSON)).andExpect(status().isBadRequest()).andExpect(content().string("literal:Error from validator"));
}
use of org.motechproject.security.exception.PasswordValidatorException in project motech by motech.
the class MinLengthValidatorDecoratorTest method shouldThrowExceptionFromInnerValidator.
@Test(expected = PasswordValidatorException.class)
public void shouldThrowExceptionFromInnerValidator() {
PasswordValidator decoratedValidator = new MinLengthValidatorDecorator(validator, 3);
doThrow(new PasswordValidatorException("wrong")).when(validator).validate("password");
decoratedValidator.validate("password");
}
Aggregations