use of uk.gov.pay.adminusers.model.SecondFactorToken in project pay-adminusers by alphagov.
the class ExistingUserOtpDispatcherTest method shouldNotSendChangeSignInOtpIfProvisionalOtpKeyNotSet.
@Test
public void shouldNotSendChangeSignInOtpIfProvisionalOtpKeyNotSet() {
User user = aUser();
UserEntity userEntity = UserEntity.from(user);
when(userDao.findByExternalId(user.getExternalId())).thenReturn(Optional.of(userEntity));
Optional<SecondFactorToken> tokenOptional = existingUserOtpDispatcher.sendChangeSignMethodToSmsOtp(user.getExternalId());
assertFalse(tokenOptional.isPresent());
verifyNoInteractions(secondFactorAuthenticator);
}
use of uk.gov.pay.adminusers.model.SecondFactorToken in project pay-adminusers by alphagov.
the class ExistingUserOtpDispatcherTest method shouldSendChangeSignInMethodOtpIfUserFound.
@Test
public void shouldSendChangeSignInMethodOtpIfUserFound() {
User user = aUserWithProvisionalOtpKey();
UserEntity userEntity = UserEntity.from(user);
when(userDao.findByExternalId(user.getExternalId())).thenReturn(Optional.of(userEntity));
when(secondFactorAuthenticator.newPassCode(user.getProvisionalOtpKey())).thenReturn(654321);
when(notificationService.sendSecondFactorPasscodeSms(any(String.class), eq("654321"), eq(CHANGE_SIGN_IN_2FA_TO_SMS))).thenReturn("random-notify-id");
Optional<SecondFactorToken> tokenOptional = existingUserOtpDispatcher.sendChangeSignMethodToSmsOtp(user.getExternalId());
assertTrue(tokenOptional.isPresent());
assertThat(tokenOptional.get().getPasscode(), is("654321"));
verify(notificationService, never()).sendSecondFactorPasscodeSms(any(String.class), eq(user.getOtpKey()), any(NotificationService.OtpNotifySmsTemplateId.class));
}
use of uk.gov.pay.adminusers.model.SecondFactorToken in project pay-adminusers by alphagov.
the class ExistingUserOtpDispatcherTest method shouldSendSignInOtpIfUserFound.
@Test
public void shouldSendSignInOtpIfUserFound() {
User user = aUser();
UserEntity userEntity = UserEntity.from(user);
when(userDao.findByExternalId(user.getExternalId())).thenReturn(Optional.of(userEntity));
when(secondFactorAuthenticator.newPassCode(user.getOtpKey())).thenReturn(123456);
when(notificationService.sendSecondFactorPasscodeSms(any(String.class), eq("123456"), eq(SIGN_IN))).thenReturn("random-notify-id");
Optional<SecondFactorToken> tokenOptional = existingUserOtpDispatcher.sendSignInOtp(user.getExternalId());
assertTrue(tokenOptional.isPresent());
assertThat(tokenOptional.get().getPasscode(), is("123456"));
}
use of uk.gov.pay.adminusers.model.SecondFactorToken in project pay-adminusers by alphagov.
the class ExistingUserOtpDispatcherTest method shouldPadChangeSignInMethodOtpToSixDigits.
@Test
public void shouldPadChangeSignInMethodOtpToSixDigits() {
User user = aUserWithProvisionalOtpKey();
UserEntity userEntity = UserEntity.from(user);
when(userDao.findByExternalId(user.getExternalId())).thenReturn(Optional.of(userEntity));
when(secondFactorAuthenticator.newPassCode(user.getProvisionalOtpKey())).thenReturn(12345);
when(notificationService.sendSecondFactorPasscodeSms(any(String.class), eq("012345"), eq(CHANGE_SIGN_IN_2FA_TO_SMS))).thenReturn("random-notify-id");
Optional<SecondFactorToken> tokenOptional = existingUserOtpDispatcher.sendChangeSignMethodToSmsOtp(user.getExternalId());
assertTrue(tokenOptional.isPresent());
assertThat(tokenOptional.get().getPasscode(), is("012345"));
}
use of uk.gov.pay.adminusers.model.SecondFactorToken in project pay-adminusers by alphagov.
the class ExistingUserOtpDispatcherTest method shouldGracefullyHandleNotifyErrorSendingChangeSignInOtp.
@Test
public void shouldGracefullyHandleNotifyErrorSendingChangeSignInOtp() {
User user = aUserWithProvisionalOtpKey();
UserEntity userEntity = UserEntity.from(user);
when(userDao.findByExternalId(user.getExternalId())).thenReturn(Optional.of(userEntity));
when(secondFactorAuthenticator.newPassCode(user.getProvisionalOtpKey())).thenReturn(654321);
when(notificationService.sendSecondFactorPasscodeSms(any(String.class), eq("654321"), eq(CHANGE_SIGN_IN_2FA_TO_SMS))).thenThrow(AdminUsersExceptions.userNotificationError());
Optional<SecondFactorToken> tokenOptional = existingUserOtpDispatcher.sendChangeSignMethodToSmsOtp(user.getExternalId());
assertTrue(tokenOptional.isPresent());
assertThat(tokenOptional.get().getPasscode(), is("654321"));
}
Aggregations