use of com.nexblocks.authguard.basic.config.OtpConfig in project AuthGuard by AuthGuard.
the class OtpVerifierTest method verifyInvalidOtpFormat.
@Test
void verifyInvalidOtpFormat() {
final OtpConfig otpConfig = OtpConfig.builder().mode(OtpMode.ALPHANUMERIC).length(6).lifeTime("5m").build();
setup(otpConfig);
final Either<Exception, String> result = otpVerifier.verifyAccountToken("not a valid OTP");
assertThat(result.isLeft()).isTrue();
assertThat(result.getLeft()).isInstanceOf(ServiceAuthorizationException.class);
}
use of com.nexblocks.authguard.basic.config.OtpConfig in project AuthGuard by AuthGuard.
the class OtpVerifierTest method verifyWrongPassword.
@Test
void verifyWrongPassword() {
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)));
assertThat(otpVerifier.verifyAccountToken(otp.getId() + ":" + "wrong")).isEmpty();
}
use of com.nexblocks.authguard.basic.config.OtpConfig 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.basic.config.OtpConfig 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