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);
}
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());
}
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());
}
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());
}
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);
}
Aggregations