use of com.nexblocks.authguard.dal.cache.AccountTokensRepository in project AuthGuard by AuthGuard.
the class AuthorizationCodeVerifierTest method nonExistingToken.
@Test
void nonExistingToken() {
final AccountTokensRepository accountTokensRepository = Mockito.mock(AccountTokensRepository.class);
final AuthorizationCodeVerifier authorizationCodeVerifier = new AuthorizationCodeVerifier(accountTokensRepository);
final String authorizationCode = "authorization-code";
Mockito.when(accountTokensRepository.getByToken(authorizationCode)).thenReturn(CompletableFuture.completedFuture(Optional.empty()));
final Either<Exception, String> result = authorizationCodeVerifier.verifyAccountToken(authorizationCode);
assertThat(result.isLeft());
assertThat(result.getLeft()).isInstanceOf(ServiceAuthorizationException.class);
}
use of com.nexblocks.authguard.dal.cache.AccountTokensRepository in project AuthGuard by AuthGuard.
the class AuthorizationCodeVerifierTest method verifyAccountToken.
@Test
void verifyAccountToken() {
final AccountTokensRepository accountTokensRepository = Mockito.mock(AccountTokensRepository.class);
final AuthorizationCodeVerifier authorizationCodeVerifier = new AuthorizationCodeVerifier(accountTokensRepository);
final String accountId = "account-id";
final String authorizationCode = "authorization-code";
final AccountTokenDO accountToken = AccountTokenDO.builder().expiresAt(OffsetDateTime.now().plus(Duration.ofMinutes(5))).associatedAccountId(accountId).token(authorizationCode).build();
Mockito.when(accountTokensRepository.getByToken(authorizationCode)).thenReturn(CompletableFuture.completedFuture(Optional.of(accountToken)));
assertThat(authorizationCodeVerifier.verifyAccountToken(authorizationCode)).contains(accountId);
}
Aggregations