Search in sources :

Example 1 with ExchangeService

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

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

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

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

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

the class AuthenticationServiceImplTest method setup.

@BeforeAll
void setup() {
    exchangeService = Mockito.mock(ExchangeService.class);
    accountLocksService = Mockito.mock(AccountLocksService.class);
    final ConfigContext configContext = Mockito.mock(ConfigContext.class);
    final AuthenticationConfig config = AuthenticationConfig.builder().generateToken("accessToken").build();
    Mockito.when(exchangeService.supportsExchange("basic", "accessToken")).thenReturn(true);
    Mockito.when(configContext.asConfigBean(AuthenticationConfig.class)).thenReturn(config);
    authenticationService = new AuthenticationServiceImpl(exchangeService, accountLocksService, configContext);
}
Also used : ExchangeService(com.nexblocks.authguard.service.ExchangeService) AccountLocksService(com.nexblocks.authguard.service.AccountLocksService) AuthenticationConfig(com.nexblocks.authguard.service.config.AuthenticationConfig) ConfigContext(com.nexblocks.authguard.config.ConfigContext) BeforeAll(org.junit.jupiter.api.BeforeAll)

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