Search in sources :

Example 1 with SecuredService

use of io.scalecube.services.sut.security.SecuredService in project scalecube by scalecube.

the class ServiceAuthRemoteTest method failedAuthenticationWithEmptyCredentials.

@Test
@DisplayName("Authentication failed with empty credentials")
void failedAuthenticationWithEmptyCredentials() {
    Microservices caller = newEmptyCredentialsCaller();
    try {
        SecuredService securedService = caller.call().api(SecuredService.class);
        Consumer<Throwable> verifyError = th -> {
            assertEquals(UnauthorizedException.class, th.getClass());
            assertEquals("Authentication failed", th.getMessage());
        };
        StepVerifier.create(securedService.helloWithRequest("Bob")).expectErrorSatisfies(verifyError).verify();
        StepVerifier.create(securedService.helloWithPrincipal()).expectErrorSatisfies(verifyError).verify();
        StepVerifier.create(securedService.helloWithRequestAndPrincipal("Bob")).expectErrorSatisfies(verifyError).verify();
    } finally {
        caller.shutdown().block(TIMEOUT);
    }
}
Also used : SecuredService(io.scalecube.services.sut.security.SecuredService) PartiallySecuredService(io.scalecube.services.sut.security.PartiallySecuredService) AnotherSecuredService(io.scalecube.services.sut.security.AnotherSecuredService) StepVerifier(reactor.test.StepVerifier) HashMap(java.util.HashMap) RejectedSetupException(io.rsocket.exceptions.RejectedSetupException) PartiallySecuredServiceImpl(io.scalecube.services.sut.security.PartiallySecuredServiceImpl) SecuredServiceImpl(io.scalecube.services.sut.security.SecuredServiceImpl) Authenticator(io.scalecube.services.auth.Authenticator) AfterAll(org.junit.jupiter.api.AfterAll) SecuredService(io.scalecube.services.sut.security.SecuredService) UserProfile(io.scalecube.services.sut.security.UserProfile) BeforeAll(org.junit.jupiter.api.BeforeAll) Duration(java.time.Duration) Map(java.util.Map) PartiallySecuredService(io.scalecube.services.sut.security.PartiallySecuredService) WebsocketTransportFactory(io.scalecube.transport.netty.websocket.WebsocketTransportFactory) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) UnauthorizedException(io.scalecube.services.exceptions.UnauthorizedException) ScalecubeServiceDiscovery(io.scalecube.services.discovery.ScalecubeServiceDiscovery) AnotherSecuredService(io.scalecube.services.sut.security.AnotherSecuredService) Mono(reactor.core.publisher.Mono) AnotherSecuredServiceImpl(io.scalecube.services.sut.security.AnotherSecuredServiceImpl) ServiceDiscovery(io.scalecube.services.discovery.api.ServiceDiscovery) DisplayName(org.junit.jupiter.api.DisplayName) PrincipalMapper(io.scalecube.services.auth.PrincipalMapper) RSocketServiceTransport(io.scalecube.services.transport.rsocket.RSocketServiceTransport) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) Collections(java.util.Collections) UnauthorizedException(io.scalecube.services.exceptions.UnauthorizedException) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 2 with SecuredService

use of io.scalecube.services.sut.security.SecuredService in project scalecube by scalecube.

the class ServiceAuthRemoteTest method successfulAuthentication.

@Test
@DisplayName("Successful authentication")
void successfulAuthentication() {
    Microservices caller = newCaller();
    try {
        SecuredService securedService = caller.call().api(SecuredService.class);
        StepVerifier.create(securedService.helloWithRequest("Bob")).assertNext(response -> assertEquals("Hello, Bob", response)).verifyComplete();
        StepVerifier.create(securedService.helloWithPrincipal()).assertNext(response -> assertEquals("Hello, Alice", response)).verifyComplete();
        StepVerifier.create(securedService.helloWithRequestAndPrincipal("Bob")).assertNext(response -> assertEquals("Hello, Bob and Alice", response)).verifyComplete();
    } finally {
        caller.shutdown().block(TIMEOUT);
    }
}
Also used : SecuredService(io.scalecube.services.sut.security.SecuredService) PartiallySecuredService(io.scalecube.services.sut.security.PartiallySecuredService) AnotherSecuredService(io.scalecube.services.sut.security.AnotherSecuredService) StepVerifier(reactor.test.StepVerifier) HashMap(java.util.HashMap) RejectedSetupException(io.rsocket.exceptions.RejectedSetupException) PartiallySecuredServiceImpl(io.scalecube.services.sut.security.PartiallySecuredServiceImpl) SecuredServiceImpl(io.scalecube.services.sut.security.SecuredServiceImpl) Authenticator(io.scalecube.services.auth.Authenticator) AfterAll(org.junit.jupiter.api.AfterAll) SecuredService(io.scalecube.services.sut.security.SecuredService) UserProfile(io.scalecube.services.sut.security.UserProfile) BeforeAll(org.junit.jupiter.api.BeforeAll) Duration(java.time.Duration) Map(java.util.Map) PartiallySecuredService(io.scalecube.services.sut.security.PartiallySecuredService) WebsocketTransportFactory(io.scalecube.transport.netty.websocket.WebsocketTransportFactory) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) UnauthorizedException(io.scalecube.services.exceptions.UnauthorizedException) ScalecubeServiceDiscovery(io.scalecube.services.discovery.ScalecubeServiceDiscovery) AnotherSecuredService(io.scalecube.services.sut.security.AnotherSecuredService) Mono(reactor.core.publisher.Mono) AnotherSecuredServiceImpl(io.scalecube.services.sut.security.AnotherSecuredServiceImpl) ServiceDiscovery(io.scalecube.services.discovery.api.ServiceDiscovery) DisplayName(org.junit.jupiter.api.DisplayName) PrincipalMapper(io.scalecube.services.auth.PrincipalMapper) RSocketServiceTransport(io.scalecube.services.transport.rsocket.RSocketServiceTransport) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) Collections(java.util.Collections) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 3 with SecuredService

use of io.scalecube.services.sut.security.SecuredService in project scalecube by scalecube.

the class ServiceAuthRemoteTest method failedAuthenticationWhenAuthenticatorNotProvided.

@Test
@DisplayName("Authentication failed if authenticator not provided")
void failedAuthenticationWhenAuthenticatorNotProvided() {
    Microservices caller = newCaller();
    try {
        AnotherSecuredService securedService = caller.call().api(AnotherSecuredService.class);
        Consumer<Throwable> verifyError = th -> {
            assertEquals(UnauthorizedException.class, th.getClass());
            assertEquals("Authentication failed", th.getMessage());
        };
        StepVerifier.create(securedService.helloWithRequest("Bob")).expectErrorSatisfies(verifyError).verify();
        StepVerifier.create(securedService.helloWithPrincipal()).expectErrorSatisfies(verifyError).verify();
        StepVerifier.create(securedService.helloWithRequestAndPrincipal("Bob")).expectErrorSatisfies(verifyError).verify();
    } finally {
        caller.shutdown().block(TIMEOUT);
    }
}
Also used : StepVerifier(reactor.test.StepVerifier) HashMap(java.util.HashMap) RejectedSetupException(io.rsocket.exceptions.RejectedSetupException) PartiallySecuredServiceImpl(io.scalecube.services.sut.security.PartiallySecuredServiceImpl) SecuredServiceImpl(io.scalecube.services.sut.security.SecuredServiceImpl) Authenticator(io.scalecube.services.auth.Authenticator) AfterAll(org.junit.jupiter.api.AfterAll) SecuredService(io.scalecube.services.sut.security.SecuredService) UserProfile(io.scalecube.services.sut.security.UserProfile) BeforeAll(org.junit.jupiter.api.BeforeAll) Duration(java.time.Duration) Map(java.util.Map) PartiallySecuredService(io.scalecube.services.sut.security.PartiallySecuredService) WebsocketTransportFactory(io.scalecube.transport.netty.websocket.WebsocketTransportFactory) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) UnauthorizedException(io.scalecube.services.exceptions.UnauthorizedException) ScalecubeServiceDiscovery(io.scalecube.services.discovery.ScalecubeServiceDiscovery) AnotherSecuredService(io.scalecube.services.sut.security.AnotherSecuredService) Mono(reactor.core.publisher.Mono) AnotherSecuredServiceImpl(io.scalecube.services.sut.security.AnotherSecuredServiceImpl) ServiceDiscovery(io.scalecube.services.discovery.api.ServiceDiscovery) DisplayName(org.junit.jupiter.api.DisplayName) PrincipalMapper(io.scalecube.services.auth.PrincipalMapper) RSocketServiceTransport(io.scalecube.services.transport.rsocket.RSocketServiceTransport) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) Collections(java.util.Collections) UnauthorizedException(io.scalecube.services.exceptions.UnauthorizedException) AnotherSecuredService(io.scalecube.services.sut.security.AnotherSecuredService) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 4 with SecuredService

use of io.scalecube.services.sut.security.SecuredService in project scalecube by scalecube.

the class ServiceAuthRemoteTest method failedAuthenticationWithInvalidCredentials.

@Test
@DisplayName("Authentication failed with invalid credentials")
void failedAuthenticationWithInvalidCredentials() {
    Microservices caller = newInvalidCredentialsCaller();
    try {
        SecuredService securedService = caller.call().api(SecuredService.class);
        Consumer<Throwable> verifyError = th -> {
            assertEquals(RejectedSetupException.class, th.getClass());
            assertEquals("Authentication failed (username or password incorrect)", th.getMessage());
        };
        StepVerifier.create(securedService.helloWithRequest("Bob")).expectErrorSatisfies(verifyError).verify();
        StepVerifier.create(securedService.helloWithPrincipal()).expectErrorSatisfies(verifyError).verify();
        StepVerifier.create(securedService.helloWithRequestAndPrincipal("Bob")).expectErrorSatisfies(verifyError).verify();
    } finally {
        caller.shutdown().block(TIMEOUT);
    }
}
Also used : SecuredService(io.scalecube.services.sut.security.SecuredService) PartiallySecuredService(io.scalecube.services.sut.security.PartiallySecuredService) AnotherSecuredService(io.scalecube.services.sut.security.AnotherSecuredService) StepVerifier(reactor.test.StepVerifier) HashMap(java.util.HashMap) RejectedSetupException(io.rsocket.exceptions.RejectedSetupException) PartiallySecuredServiceImpl(io.scalecube.services.sut.security.PartiallySecuredServiceImpl) SecuredServiceImpl(io.scalecube.services.sut.security.SecuredServiceImpl) Authenticator(io.scalecube.services.auth.Authenticator) AfterAll(org.junit.jupiter.api.AfterAll) SecuredService(io.scalecube.services.sut.security.SecuredService) UserProfile(io.scalecube.services.sut.security.UserProfile) BeforeAll(org.junit.jupiter.api.BeforeAll) Duration(java.time.Duration) Map(java.util.Map) PartiallySecuredService(io.scalecube.services.sut.security.PartiallySecuredService) WebsocketTransportFactory(io.scalecube.transport.netty.websocket.WebsocketTransportFactory) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) UnauthorizedException(io.scalecube.services.exceptions.UnauthorizedException) ScalecubeServiceDiscovery(io.scalecube.services.discovery.ScalecubeServiceDiscovery) AnotherSecuredService(io.scalecube.services.sut.security.AnotherSecuredService) Mono(reactor.core.publisher.Mono) AnotherSecuredServiceImpl(io.scalecube.services.sut.security.AnotherSecuredServiceImpl) ServiceDiscovery(io.scalecube.services.discovery.api.ServiceDiscovery) DisplayName(org.junit.jupiter.api.DisplayName) PrincipalMapper(io.scalecube.services.auth.PrincipalMapper) RSocketServiceTransport(io.scalecube.services.transport.rsocket.RSocketServiceTransport) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) Collections(java.util.Collections) RejectedSetupException(io.rsocket.exceptions.RejectedSetupException) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

RejectedSetupException (io.rsocket.exceptions.RejectedSetupException)4 Authenticator (io.scalecube.services.auth.Authenticator)4 PrincipalMapper (io.scalecube.services.auth.PrincipalMapper)4 ScalecubeServiceDiscovery (io.scalecube.services.discovery.ScalecubeServiceDiscovery)4 ServiceDiscovery (io.scalecube.services.discovery.api.ServiceDiscovery)4 UnauthorizedException (io.scalecube.services.exceptions.UnauthorizedException)4 AnotherSecuredService (io.scalecube.services.sut.security.AnotherSecuredService)4 AnotherSecuredServiceImpl (io.scalecube.services.sut.security.AnotherSecuredServiceImpl)4 PartiallySecuredService (io.scalecube.services.sut.security.PartiallySecuredService)4 PartiallySecuredServiceImpl (io.scalecube.services.sut.security.PartiallySecuredServiceImpl)4 SecuredService (io.scalecube.services.sut.security.SecuredService)4 SecuredServiceImpl (io.scalecube.services.sut.security.SecuredServiceImpl)4 UserProfile (io.scalecube.services.sut.security.UserProfile)4 RSocketServiceTransport (io.scalecube.services.transport.rsocket.RSocketServiceTransport)4 WebsocketTransportFactory (io.scalecube.transport.netty.websocket.WebsocketTransportFactory)4 Duration (java.time.Duration)4 Collections (java.util.Collections)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Consumer (java.util.function.Consumer)4