Search in sources :

Example 6 with OneTimePasswordDO

use of com.nexblocks.authguard.dal.model.OneTimePasswordDO in project AuthGuard by AuthGuard.

the class OtpServiceImplTest method authenticate.

@Test
void authenticate() {
    final OtpConfig otpConfig = OtpConfig.builder().generateToken("accessToken").build();
    setup(otpConfig);
    final OneTimePasswordDO otp = random.nextObject(OneTimePasswordDO.class);
    final AuthResponseBO tokens = random.nextObject(AuthResponseBO.class);
    final String otpToken = otp.getId() + ":" + otp.getPassword();
    final AuthRequestBO authRequest = AuthRequestBO.builder().token(otpToken).build();
    final RequestContextBO requestContext = RequestContextBO.builder().build();
    Mockito.when(mockExchangeService.exchange(authRequest, "otp", otpConfig.getGenerateToken(), requestContext)).thenReturn(tokens);
    final AuthResponseBO generated = otpService.authenticate(otp.getId(), otp.getPassword(), requestContext);
    assertThat(generated).isEqualTo(tokens);
}
Also used : RequestContextBO(com.nexblocks.authguard.service.model.RequestContextBO) AuthResponseBO(com.nexblocks.authguard.service.model.AuthResponseBO) OtpConfig(com.nexblocks.authguard.basic.config.OtpConfig) OneTimePasswordDO(com.nexblocks.authguard.dal.model.OneTimePasswordDO) AuthRequestBO(com.nexblocks.authguard.service.model.AuthRequestBO) Test(org.junit.jupiter.api.Test)

Example 7 with OneTimePasswordDO

use of com.nexblocks.authguard.dal.model.OneTimePasswordDO in project AuthGuard by AuthGuard.

the class OtpVerifierTest method verify.

@Test
void verify() {
    final OtpConfig otpConfig = OtpConfig.builder().mode(OtpMode.ALPHANUMERIC).length(6).lifeTime("5m").build();
    setup(otpConfig);
    final OneTimePasswordDO otp = random.nextObject(OneTimePasswordDO.class);
    Mockito.when(mockOtpRepository.getById(otp.getId())).thenReturn(CompletableFuture.completedFuture(Optional.of(otp)));
    final Either<Exception, String> generated = otpVerifier.verifyAccountToken(otp.getId() + ":" + otp.getPassword());
    assertThat(generated.get()).isEqualTo(otp.getAccountId());
}
Also used : OtpConfig(com.nexblocks.authguard.basic.config.OtpConfig) OneTimePasswordDO(com.nexblocks.authguard.dal.model.OneTimePasswordDO) ServiceAuthorizationException(com.nexblocks.authguard.service.exceptions.ServiceAuthorizationException) Test(org.junit.jupiter.api.Test)

Aggregations

OtpConfig (com.nexblocks.authguard.basic.config.OtpConfig)7 OneTimePasswordDO (com.nexblocks.authguard.dal.model.OneTimePasswordDO)7 Test (org.junit.jupiter.api.Test)7 AuthResponseBO (com.nexblocks.authguard.service.model.AuthResponseBO)4 AccountBO (com.nexblocks.authguard.service.model.AccountBO)3 ServiceAuthorizationException (com.nexblocks.authguard.service.exceptions.ServiceAuthorizationException)2 AuthRequestBO (com.nexblocks.authguard.service.model.AuthRequestBO)1 RequestContextBO (com.nexblocks.authguard.service.model.RequestContextBO)1