示例#1
0
  @Test
  public void assertThatUserCanResetPassword() {

    User user =
        userService.createUserInformation(
            "johndoe", "johndoe", "John", "Doe", "john.doe@localhost", "en-US", new Date());

    String oldPassword = user.getPassword();

    DateTime daysAgo = DateTime.now().minusHours(2);
    String resetKey = RandomUtil.generateResetKey();
    user.setActivated(true);
    user.setResetDate(daysAgo);
    user.setResetKey(resetKey);

    userRepository.save(user);

    Optional<User> maybeUser = userService.completePasswordReset("johndoe2", user.getResetKey());

    assertThat(maybeUser.isPresent()).isTrue();
    assertThat(maybeUser.get().getResetDate()).isNull();
    assertThat(maybeUser.get().getResetKey()).isNull();
    assertThat(maybeUser.get().getPassword()).isNotEqualTo(oldPassword);

    userRepository.delete(user);
  }
示例#2
0
 @Test
 public void testFindNotActivatedUsersByCreationDateBefore() {
   userService.removeNotActivatedUsers();
   DateTime now = new DateTime();
   List<User> users =
       userRepository.findAllByActivatedIsFalseAndCreatedDateBefore(now.minusDays(3));
   assertThat(users).isEmpty();
 }
示例#3
0
 @Test
 public void assertThatOnlyActivatedUserCanRequestPasswordReset() {
   User user =
       userService.createUserInformation(
           "johndoe", "johndoe", "John", "Doe", "john.doe@localhost", "en-US", new Date());
   Optional<User> maybeUser = userService.requestPasswordReset("john.doe@localhost");
   assertThat(maybeUser.isPresent()).isFalse();
   userRepository.delete(user);
 }
示例#4
0
  @Test
  public void assertThatResetKeyMustBeValid() {

    User user =
        userService.createUserInformation(
            "johndoe", "johndoe", "John", "Doe", "john.doe@localhost", "en-US", new Date());

    DateTime daysAgo = DateTime.now().minusHours(25);
    user.setActivated(true);
    user.setResetDate(daysAgo);
    user.setResetKey("1234");

    userRepository.save(user);

    Optional<User> maybeUser = userService.completePasswordReset("johndoe2", user.getResetKey());

    assertThat(maybeUser.isPresent()).isFalse();

    userRepository.delete(user);
  }