Search in sources :

Example 6 with ExchangeService

use of com.nexblocks.authguard.service.ExchangeService in project AuthGuard by AuthGuard.

the class ExchangeServiceImplTest method exchange.

@Test
void exchange() {
    final MessageBus emb = Mockito.mock(MessageBus.class);
    final ExchangeAttemptsService exchangeAttemptsService = Mockito.mock(ExchangeAttemptsService.class);
    final ExchangeService exchangeService = new ExchangeServiceImpl(Arrays.asList(new ValidExchange(), new InvalidExchange(), new ExceptionExchange()), Collections.emptyList(), exchangeAttemptsService, emb);
    final String basic = "Basic the-rest";
    final AuthRequestBO authRequest = AuthRequestBO.builder().token(basic).deviceId("user-device").externalSessionId("external-session").build();
    final RequestContextBO requestContext = RequestContextBO.builder().clientId("client").source("10.0.0.2").build();
    final AuthResponseBO expected = AuthResponseBO.builder().type("Basic").token(basic).entityType(EntityType.ACCOUNT).entityId("account").build();
    Assertions.assertThat(exchangeService.exchange(authRequest, "basic", "basic", requestContext)).isEqualTo(expected);
    Mockito.verify(exchangeAttemptsService).create(ExchangeAttemptBO.builder().successful(true).exchangeFrom("basic").exchangeTo("basic").entityId("account").clientId("client").sourceIp("10.0.0.2").deviceId("user-device").externalSessionId("external-session").build());
    Mockito.verify(emb).publish(Mockito.eq(ExchangeServiceImpl.CHANNEL), Mockito.any());
}
Also used : ExchangeService(com.nexblocks.authguard.service.ExchangeService) MessageBus(com.nexblocks.authguard.emb.MessageBus) ExchangeAttemptsService(com.nexblocks.authguard.service.ExchangeAttemptsService) Test(org.junit.jupiter.api.Test)

Aggregations

ExchangeService (com.nexblocks.authguard.service.ExchangeService)6 MessageBus (com.nexblocks.authguard.emb.MessageBus)5 ExchangeAttemptsService (com.nexblocks.authguard.service.ExchangeAttemptsService)5 Test (org.junit.jupiter.api.Test)5 ConfigContext (com.nexblocks.authguard.config.ConfigContext)1 AccountLocksService (com.nexblocks.authguard.service.AccountLocksService)1 AuthenticationConfig (com.nexblocks.authguard.service.config.AuthenticationConfig)1 BeforeAll (org.junit.jupiter.api.BeforeAll)1