Search in sources :

Example 1 with PasswordValidatorException

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);
}
Also used : MotechUser(org.motechproject.security.domain.MotechUser) PasswordValidatorException(org.motechproject.security.exception.PasswordValidatorException) Test(org.junit.Test)

Example 2 with PasswordValidatorException

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);
}
Also used : PasswordValidatorException(org.motechproject.security.exception.PasswordValidatorException) Test(org.junit.Test)

Example 3 with PasswordValidatorException

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");
}
Also used : PasswordValidatorException(org.motechproject.security.exception.PasswordValidatorException) Test(org.junit.Test)

Example 4 with PasswordValidatorException

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"));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Locale(java.util.Locale) PasswordValidatorException(org.motechproject.security.exception.PasswordValidatorException) UserDto(org.motechproject.security.model.UserDto) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Example 5 with PasswordValidatorException

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");
}
Also used : PasswordValidatorException(org.motechproject.security.exception.PasswordValidatorException) PasswordValidator(org.motechproject.security.validator.PasswordValidator) Test(org.junit.Test)

Aggregations

PasswordValidatorException (org.motechproject.security.exception.PasswordValidatorException)7 Test (org.junit.Test)6 UserDto (org.motechproject.security.model.UserDto)2 Locale (java.util.Locale)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1 MotechUser (org.motechproject.security.domain.MotechUser)1 MotechUserProfile (org.motechproject.security.domain.MotechUserProfile)1 PasswordValidator (org.motechproject.security.validator.PasswordValidator)1 ChangePasswordViewData (org.motechproject.server.web.dto.ChangePasswordViewData)1 ChangePasswordFormValidator (org.motechproject.server.web.validator.ChangePasswordFormValidator)1 LockedException (org.springframework.security.authentication.LockedException)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1