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