Search in sources :

Example 1 with SecondFactorToken

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);
}
Also used : User(uk.gov.pay.adminusers.model.User) SecondFactorToken(uk.gov.pay.adminusers.model.SecondFactorToken) UserEntity(uk.gov.pay.adminusers.persistence.entity.UserEntity) Test(org.junit.jupiter.api.Test)

Example 2 with SecondFactorToken

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));
}
Also used : User(uk.gov.pay.adminusers.model.User) SecondFactorToken(uk.gov.pay.adminusers.model.SecondFactorToken) UserEntity(uk.gov.pay.adminusers.persistence.entity.UserEntity) Test(org.junit.jupiter.api.Test)

Example 3 with SecondFactorToken

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"));
}
Also used : User(uk.gov.pay.adminusers.model.User) SecondFactorToken(uk.gov.pay.adminusers.model.SecondFactorToken) UserEntity(uk.gov.pay.adminusers.persistence.entity.UserEntity) Test(org.junit.jupiter.api.Test)

Example 4 with SecondFactorToken

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"));
}
Also used : User(uk.gov.pay.adminusers.model.User) SecondFactorToken(uk.gov.pay.adminusers.model.SecondFactorToken) UserEntity(uk.gov.pay.adminusers.persistence.entity.UserEntity) Test(org.junit.jupiter.api.Test)

Example 5 with SecondFactorToken

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"));
}
Also used : User(uk.gov.pay.adminusers.model.User) SecondFactorToken(uk.gov.pay.adminusers.model.SecondFactorToken) UserEntity(uk.gov.pay.adminusers.persistence.entity.UserEntity) Test(org.junit.jupiter.api.Test)

Aggregations

SecondFactorToken (uk.gov.pay.adminusers.model.SecondFactorToken)8 Test (org.junit.jupiter.api.Test)7 User (uk.gov.pay.adminusers.model.User)7 UserEntity (uk.gov.pay.adminusers.persistence.entity.UserEntity)7 Provider (com.google.inject.Provider)1 Optional (java.util.Optional)1 Inject (javax.inject.Inject)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 UserDao (uk.gov.pay.adminusers.persistence.dao.UserDao)1 CHANGE_SIGN_IN_2FA_TO_SMS (uk.gov.pay.adminusers.service.NotificationService.OtpNotifySmsTemplateId.CHANGE_SIGN_IN_2FA_TO_SMS)1 SIGN_IN (uk.gov.pay.adminusers.service.NotificationService.OtpNotifySmsTemplateId.SIGN_IN)1