Search in sources :

Example 6 with AccountTokensRepository

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);
}
Also used : AccountTokensRepository(com.nexblocks.authguard.dal.cache.AccountTokensRepository) ServiceAuthorizationException(com.nexblocks.authguard.service.exceptions.ServiceAuthorizationException) Test(org.junit.jupiter.api.Test)

Example 7 with AccountTokensRepository

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);
}
Also used : AccountTokensRepository(com.nexblocks.authguard.dal.cache.AccountTokensRepository) AccountTokenDO(com.nexblocks.authguard.dal.model.AccountTokenDO) Test(org.junit.jupiter.api.Test)

Aggregations

AccountTokensRepository (com.nexblocks.authguard.dal.cache.AccountTokensRepository)7 AccountTokenDO (com.nexblocks.authguard.dal.model.AccountTokenDO)4 Test (org.junit.jupiter.api.Test)4 ServiceMapperImpl (com.nexblocks.authguard.service.mappers.ServiceMapperImpl)3 BeforeEach (org.junit.jupiter.api.BeforeEach)2 PasswordValidator (com.nexblocks.authguard.basic.passwords.PasswordValidator)1 SecurePassword (com.nexblocks.authguard.basic.passwords.SecurePassword)1 SecurePasswordProvider (com.nexblocks.authguard.basic.passwords.SecurePasswordProvider)1 ConfigContext (com.nexblocks.authguard.config.ConfigContext)1 CredentialsAuditRepository (com.nexblocks.authguard.dal.persistence.CredentialsAuditRepository)1 CredentialsRepository (com.nexblocks.authguard.dal.persistence.CredentialsRepository)1 MessageBus (com.nexblocks.authguard.emb.MessageBus)1 EmailProvider (com.nexblocks.authguard.external.email.EmailProvider)1 TokenEncryptorAdapter (com.nexblocks.authguard.jwt.crypto.TokenEncryptorAdapter)1 AccountsService (com.nexblocks.authguard.service.AccountsService)1 IdempotencyService (com.nexblocks.authguard.service.IdempotencyService)1 ServiceAuthorizationException (com.nexblocks.authguard.service.exceptions.ServiceAuthorizationException)1 AccountBO (com.nexblocks.authguard.service.model.AccountBO)1 AuthResponseBO (com.nexblocks.authguard.service.model.AuthResponseBO)1