Search in sources :

Example 1 with RevisionMetadata

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));
}
Also used : User(ca.corefacility.bioinformatics.irida.model.user.User) Revision(org.springframework.data.history.Revision) RevisionMetadata(org.springframework.data.history.RevisionMetadata) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 2 with RevisionMetadata

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());
}
Also used : User(ca.corefacility.bioinformatics.irida.model.user.User) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) Date(java.util.Date) RevisionMetadata(org.springframework.data.history.RevisionMetadata) DateTime(org.joda.time.DateTime) Revision(org.springframework.data.history.Revision) Test(org.junit.Test)

Example 3 with RevisionMetadata

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());
}
Also used : User(ca.corefacility.bioinformatics.irida.model.user.User) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) Date(java.util.Date) RevisionMetadata(org.springframework.data.history.RevisionMetadata) DateTime(org.joda.time.DateTime) Revision(org.springframework.data.history.Revision) Test(org.junit.Test)

Example 4 with RevisionMetadata

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());
}
Also used : User(ca.corefacility.bioinformatics.irida.model.user.User) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) Date(java.util.Date) RevisionMetadata(org.springframework.data.history.RevisionMetadata) DateTime(org.joda.time.DateTime) Revision(org.springframework.data.history.Revision) Test(org.junit.Test)

Aggregations

User (ca.corefacility.bioinformatics.irida.model.user.User)4 DateTime (org.joda.time.DateTime)4 Test (org.junit.Test)4 Revision (org.springframework.data.history.Revision)4 RevisionMetadata (org.springframework.data.history.RevisionMetadata)4 Calendar (java.util.Calendar)3 Date (java.util.Date)3 GregorianCalendar (java.util.GregorianCalendar)3