Search in sources :

Example 6 with ActionTokenBO

use of com.nexblocks.authguard.service.model.ActionTokenBO in project AuthGuard by AuthGuard.

the class ActionTokenServiceImplTest method generateFromBasicAuth.

@Test
void generateFromBasicAuth() {
    final AuthRequestBO authRequest = AuthRequestBO.builder().identifier("username").password("password").build();
    final AccountBO account = AccountBO.builder().id("account").build();
    Mockito.when(basicAuthProvider.getAccount(authRequest)).thenReturn(Either.right(account));
    Mockito.when(accountTokensRepository.save(Mockito.any())).thenReturn(CompletableFuture.completedFuture(null));
    final Try<ActionTokenBO> actual = actionTokenService.generateFromBasicAuth(authRequest, "something");
    final ActionTokenBO expected = ActionTokenBO.builder().accountId(account.getId()).validFor(Duration.ofMinutes(5).toSeconds()).build();
    assertThat(actual.isSuccess());
    assertThat(actual.get()).isEqualToIgnoringGivenFields(expected, "token");
    assertThat(actual.get().getToken()).isNotNull();
}
Also used : AccountBO(com.nexblocks.authguard.service.model.AccountBO) AuthRequestBO(com.nexblocks.authguard.service.model.AuthRequestBO) ActionTokenBO(com.nexblocks.authguard.service.model.ActionTokenBO) Test(org.junit.jupiter.api.Test)

Aggregations

ActionTokenBO (com.nexblocks.authguard.service.model.ActionTokenBO)6 Test (org.junit.jupiter.api.Test)5 AccountTokenDO (com.nexblocks.authguard.dal.model.AccountTokenDO)3 ServiceException (com.nexblocks.authguard.service.exceptions.ServiceException)3 AccountBO (com.nexblocks.authguard.service.model.AccountBO)2 AuthRequestBO (com.nexblocks.authguard.service.model.AuthRequestBO)2 ActionTokenRequestDTO (com.nexblocks.authguard.api.dto.requests.ActionTokenRequestDTO)1