Search in sources :

Example 1 with ExchangeAttemptsService

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

the class ExchangeServiceImplTest method exchangeUnknownTokenTypes.

@Test
void exchangeUnknownTokenTypes() {
    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).build();
    final RequestContextBO requestContext = RequestContextBO.builder().build();
    assertThatThrownBy(() -> exchangeService.exchange(authRequest, "unknown", "unknown", requestContext)).isInstanceOf(ServiceException.class);
}
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)

Example 2 with ExchangeAttemptsService

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

the class ExchangeServiceImplTest method exchangeNoTokensGenerated.

@Test
void exchangeNoTokensGenerated() {
    final MessageBus emb = Mockito.mock(MessageBus.class);
    final ExchangeAttemptsService exchangeAttemptsService = Mockito.mock(ExchangeAttemptsService.class);
    final ExchangeService exchangeService = new ExchangeServiceImpl(Collections.singletonList(new EmptyExchange()), Collections.emptyList(), exchangeAttemptsService, emb);
    final String basic = "Basic the-rest";
    final AuthRequestBO authRequest = AuthRequestBO.builder().token(basic).build();
    final RequestContextBO requestContext = RequestContextBO.builder().build();
    assertThatThrownBy(() -> exchangeService.exchange(authRequest, "basic", "empty", requestContext)).isInstanceOf(ServiceException.class);
    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)

Example 3 with ExchangeAttemptsService

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

the class ExchangeServiceImplTest method exchangeWithOverriddenProperties.

@Test
void exchangeWithOverriddenProperties() {
    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").userAgent("user-agent").sourceIp("10.0.0.3").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.3").deviceId("user-device").externalSessionId("external-session").userAgent("user-agent").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)

Example 4 with ExchangeAttemptsService

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

the class ExchangeServiceImplTest method exchangeServiceAuthorizationException.

@Test
void exchangeServiceAuthorizationException() {
    final MessageBus emb = Mockito.mock(MessageBus.class);
    final ExchangeAttemptsService exchangeAttemptsService = Mockito.mock(ExchangeAttemptsService.class);
    final ExchangeService exchangeService = new ExchangeServiceImpl(Collections.singletonList(new ExceptionExchange()), Collections.emptyList(), exchangeAttemptsService, emb);
    final String basic = "Basic the-rest";
    final AuthRequestBO authRequest = AuthRequestBO.builder().token(basic).build();
    final RequestContextBO requestContext = RequestContextBO.builder().build();
    assertThatThrownBy(() -> exchangeService.exchange(authRequest, "basic", "exception", requestContext)).isInstanceOf(ServiceAuthorizationException.class);
    Mockito.verify(exchangeAttemptsService).create(ExchangeAttemptBO.builder().successful(false).exchangeFrom("basic").exchangeTo("exception").entityId("account").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)

Example 5 with ExchangeAttemptsService

use of com.nexblocks.authguard.service.ExchangeAttemptsService 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

MessageBus (com.nexblocks.authguard.emb.MessageBus)5 ExchangeAttemptsService (com.nexblocks.authguard.service.ExchangeAttemptsService)5 ExchangeService (com.nexblocks.authguard.service.ExchangeService)5 Test (org.junit.jupiter.api.Test)5