use of uk.gov.pay.adminusers.persistence.entity.UserEntity in project pay-adminusers by alphagov.
the class UserServicesTest method shouldReturnEmptyAndDisable_whenAuthenticate2FA_ifUnsuccessfulMaxRetry.
@Test
void shouldReturnEmptyAndDisable_whenAuthenticate2FA_ifUnsuccessfulMaxRetry() {
User user = aUser();
user.setLoginCounter(3);
UserEntity userEntity = aUserEntityWithTrimmings(user);
when(userDao.findByExternalId(user.getExternalId())).thenReturn(Optional.of(userEntity));
when(secondFactorAuthenticator.authorize(user.getOtpKey(), 123456)).thenReturn(false);
when(userDao.merge(userEntityArgumentCaptor.capture())).thenReturn(mock(UserEntity.class));
Optional<User> tokenOptional = userServices.authenticateSecondFactor(user.getExternalId(), 123456);
assertFalse(tokenOptional.isPresent());
UserEntity savedUser = userEntityArgumentCaptor.getValue();
assertThat(savedUser.getLoginCounter(), is(4));
assertThat(savedUser.isDisabled(), is(true));
}
use of uk.gov.pay.adminusers.persistence.entity.UserEntity in project pay-adminusers by alphagov.
the class UserServicesTest method shouldReturnUser_whenActivateNewOtpKey_ifUserDisabled.
@Test
void shouldReturnUser_whenActivateNewOtpKey_ifUserDisabled() {
User user = aUser();
UserEntity userEntity = UserEntity.from(user);
userEntity.setSecondFactor(SecondFactorMethod.SMS);
userEntity.setOtpKey("Original OTP key");
userEntity.setProvisionalOtpKey("New OTP key");
userEntity.setProvisionalOtpKeyCreatedAt(ZonedDateTime.now(ZoneOffset.UTC).minusMinutes(89));
userEntity.setDisabled(true);
when(userDao.findByExternalId(user.getExternalId())).thenReturn(Optional.of(userEntity));
Optional<User> result = userServices.activateNewOtpKey(user.getExternalId(), SecondFactorMethod.APP, 123456);
assertFalse(result.isPresent());
assertThat(userEntity.getOtpKey(), is("Original OTP key"));
assertThat(userEntity.getSecondFactor(), is(SecondFactorMethod.SMS));
verify(userDao, never()).merge(any(UserEntity.class));
}
use of uk.gov.pay.adminusers.persistence.entity.UserEntity in project pay-adminusers by alphagov.
the class UserServicesTest method shouldFindAUserByUserName.
@Test
void shouldFindAUserByUserName() {
User user = aUser();
UserEntity userEntity = aUserEntityWithTrimmings(user);
Optional<UserEntity> userEntityOptional = Optional.of(userEntity);
when(userDao.findByUsername(USER_USERNAME)).thenReturn(userEntityOptional);
Optional<User> userOptional = userServices.findUserByUsername(USER_USERNAME);
assertTrue(userOptional.isPresent());
assertThat(userOptional.get().getUsername(), is(USER_USERNAME));
}
use of uk.gov.pay.adminusers.persistence.entity.UserEntity in project pay-adminusers by alphagov.
the class UserServicesTest method shouldFindAUserByExternalId.
@Test
void shouldFindAUserByExternalId() {
User user = aUser();
UserEntity userEntity = aUserEntityWithTrimmings(user);
Optional<UserEntity> userEntityOptional = Optional.of(userEntity);
when(userDao.findByExternalId(USER_EXTERNAL_ID)).thenReturn(userEntityOptional);
Optional<User> userOptional = userServices.findUserByExternalId(USER_EXTERNAL_ID);
assertTrue(userOptional.isPresent());
assertThat(userOptional.get().getExternalId(), is(USER_EXTERNAL_ID));
}
use of uk.gov.pay.adminusers.persistence.entity.UserEntity in project pay-adminusers by alphagov.
the class UserServicesTest method shouldReturnUser_whenActivateNewOtpKey_ifCodeIncorrect.
@Test
void shouldReturnUser_whenActivateNewOtpKey_ifCodeIncorrect() {
User user = aUser();
UserEntity userEntity = UserEntity.from(user);
userEntity.setSecondFactor(SecondFactorMethod.SMS);
userEntity.setOtpKey("Original OTP key");
userEntity.setProvisionalOtpKey("New OTP key");
userEntity.setProvisionalOtpKeyCreatedAt(ZonedDateTime.now(ZoneOffset.UTC).minusMinutes(89));
when(userDao.findByExternalId(user.getExternalId())).thenReturn(Optional.of(userEntity));
when(secondFactorAuthenticator.authorize("New OTP key", 123456)).thenReturn(false);
Optional<User> result = userServices.activateNewOtpKey(user.getExternalId(), SecondFactorMethod.APP, 123456);
assertFalse(result.isPresent());
assertThat(userEntity.getOtpKey(), is("Original OTP key"));
assertThat(userEntity.getSecondFactor(), is(SecondFactorMethod.SMS));
verify(userDao, never()).merge(any(UserEntity.class));
}
Aggregations