use of org.springframework.data.history.RevisionMetadata in project irida by phac-nml.
the class UserServiceImplTest method testUpdateExistingPassword.
@Test(expected = PasswordReusedException.class)
public void testUpdateExistingPassword() {
String password = "Password1";
String oldPassword = "oldPassword";
String encodedPassword = password + "_ENCODED";
User revUser = new User();
revUser.setPassword(oldPassword);
Revision<Integer, User> rev = new Revision(new RevisionMetadata() {
@Override
public Number getRevisionNumber() {
return 1L;
}
@Override
public DateTime getRevisionDate() {
return new DateTime();
}
@Override
public Object getDelegate() {
return null;
}
}, revUser);
when(passwordEncoder.encode(password)).thenReturn(encodedPassword);
when(passwordEncoder.matches(password, oldPassword)).thenReturn(true);
when(userRepository.exists(1L)).thenReturn(true);
when(userRepository.findOne(1L)).thenReturn(user());
when(userRepository.findRevisions(1L)).thenReturn(new Revisions<Integer, User>(Lists.newArrayList(rev)));
userService.changePassword(1L, password);
verify(userRepository, times(0)).save(any(User.class));
}
use of org.springframework.data.history.RevisionMetadata in project irida by phac-nml.
the class PasswordExpiryCheckerTest method testExpiredPassword.
@Test(expected = CredentialsExpiredException.class)
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testExpiredPassword() {
user.setPassword("password1");
revUser.setPassword("password1");
Date today = new Date();
Calendar cal = new GregorianCalendar();
cal.setTime(today);
cal.add(Calendar.DAY_OF_MONTH, -10);
Date expiryDate = cal.getTime();
Revision<Integer, User> revision = new Revision(new RevisionMetadata() {
@Override
public Number getRevisionNumber() {
return 1L;
}
@Override
public DateTime getRevisionDate() {
return new DateTime(expiryDate.getTime());
}
@Override
public Object getDelegate() {
return null;
}
}, revUser);
when(userRepository.findRevisions(user.getId())).thenReturn(new Revisions<Integer, User>(Lists.newArrayList(revision)));
checker.check(user);
verify(userRepository).findRevisions(user.getId());
}
use of org.springframework.data.history.RevisionMetadata in project irida by phac-nml.
the class PasswordExpiryCheckerTest method testChangedPassword.
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testChangedPassword() {
user.setPassword("password1");
revUser.setPassword("password2");
Date today = new Date();
Calendar cal = new GregorianCalendar();
cal.setTime(today);
cal.add(Calendar.DAY_OF_MONTH, -10);
Date expiryDate = cal.getTime();
Revision<Integer, User> revision = new Revision(new RevisionMetadata() {
@Override
public Number getRevisionNumber() {
return 1L;
}
@Override
public DateTime getRevisionDate() {
return new DateTime(expiryDate.getTime());
}
@Override
public Object getDelegate() {
return null;
}
}, revUser);
when(userRepository.findRevisions(user.getId())).thenReturn(new Revisions<Integer, User>(Lists.newArrayList(revision)));
checker.check(user);
verify(userRepository).findRevisions(user.getId());
}
use of org.springframework.data.history.RevisionMetadata in project irida by phac-nml.
the class PasswordExpiryCheckerTest method testNonExpiredLogin.
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testNonExpiredLogin() {
Date today = new Date();
Calendar cal = new GregorianCalendar();
cal.setTime(today);
cal.add(Calendar.DAY_OF_MONTH, -1);
Date expiryDate = cal.getTime();
Revision<Integer, User> revision = new Revision(new RevisionMetadata() {
@Override
public Number getRevisionNumber() {
return 1L;
}
@Override
public DateTime getRevisionDate() {
return new DateTime(expiryDate.getTime());
}
@Override
public Object getDelegate() {
return null;
}
}, revUser);
when(userRepository.findRevisions(user.getId())).thenReturn(new Revisions<Integer, User>(Lists.newArrayList(revision)));
checker.check(user);
verify(userRepository).findRevisions(user.getId());
}
Aggregations