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);
}
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());
}
Aggregations