Search in sources :

Example 56 with ServerContext

use of io.servicetalk.transport.api.ServerContext in project servicetalk by apple.

the class GrpcSslAndNonSslConnectionsTest method noSniClientDefaultServerFallbackFailExpected.

@Test
void noSniClientDefaultServerFallbackFailExpected() throws Exception {
    try (ServerContext serverContext = GrpcServers.forAddress(localAddress(0)).initializeHttp(builder -> builder.sslConfig(untrustedServerConfig(), singletonMap(getLoopbackAddress().getHostName(), trustedServerConfig()))).listenAndAwait(serviceFactory());
        BlockingTesterClient client = GrpcClients.forAddress(getLoopbackAddress().getHostName(), serverHostAndPort(serverContext).port()).initializeHttp(builder -> builder.sslConfig(new ClientSslConfigBuilder(DefaultTestCerts::loadServerCAPem).build()).inferPeerHost(false).inferSniHostname(false)).buildBlocking(clientFactory())) {
        GrpcStatusException e = assertThrows(GrpcStatusException.class, () -> client.test(REQUEST));
        assertThat(e.getCause(), instanceOf(SSLHandshakeException.class));
    }
}
Also used : BlockingTesterClient(io.servicetalk.grpc.netty.TesterProto.Tester.BlockingTesterClient) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) AddressUtils.localAddress(io.servicetalk.transport.netty.internal.AddressUtils.localAddress) ServerContext(io.servicetalk.transport.api.ServerContext) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) ServerSslConfigBuilder(io.servicetalk.transport.api.ServerSslConfigBuilder) InetSocketAddress(java.net.InetSocketAddress) DefaultTestCerts.serverPemHostname(io.servicetalk.test.resources.DefaultTestCerts.serverPemHostname) Test(org.junit.jupiter.api.Test) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) GrpcStatusException(io.servicetalk.grpc.api.GrpcStatusException) ServerSslConfig(io.servicetalk.transport.api.ServerSslConfig) DEFAULT_STRATEGY_ASYNC_SERVICE(io.servicetalk.grpc.netty.ExecutionStrategyTestServices.DEFAULT_STRATEGY_ASYNC_SERVICE) StacklessClosedChannelException(io.servicetalk.transport.netty.internal.StacklessClosedChannelException) ClientSslConfigBuilder(io.servicetalk.transport.api.ClientSslConfigBuilder) AddressUtils.serverHostAndPort(io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort) Collections.singletonMap(java.util.Collections.singletonMap) Matchers.is(org.hamcrest.Matchers.is) DefaultTestCerts(io.servicetalk.test.resources.DefaultTestCerts) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) GrpcClientBuilder(io.servicetalk.grpc.api.GrpcClientBuilder) HostAndPort(io.servicetalk.transport.api.HostAndPort) InetAddress.getLoopbackAddress(java.net.InetAddress.getLoopbackAddress) GrpcStatusException(io.servicetalk.grpc.api.GrpcStatusException) ServerContext(io.servicetalk.transport.api.ServerContext) DefaultTestCerts(io.servicetalk.test.resources.DefaultTestCerts) ClientSslConfigBuilder(io.servicetalk.transport.api.ClientSslConfigBuilder) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) BlockingTesterClient(io.servicetalk.grpc.netty.TesterProto.Tester.BlockingTesterClient) Test(org.junit.jupiter.api.Test)

Example 57 with ServerContext

use of io.servicetalk.transport.api.ServerContext in project servicetalk by apple.

the class GrpcSslAndNonSslConnectionsTest method noSniClientDefaultServerFallbackSuccess.

@Test
void noSniClientDefaultServerFallbackSuccess() throws Exception {
    try (ServerContext serverContext = GrpcServers.forAddress(localAddress(0)).initializeHttp(builder -> builder.sslConfig(trustedServerConfig(), singletonMap(getLoopbackAddress().getHostName(), untrustedServerConfig()))).listenAndAwait(serviceFactory());
        BlockingTesterClient client = GrpcClients.forAddress(getLoopbackAddress().getHostName(), serverHostAndPort(serverContext).port()).initializeHttp(builder -> builder.sslConfig(new ClientSslConfigBuilder(DefaultTestCerts::loadServerCAPem).build()).inferPeerHost(false).inferSniHostname(false)).buildBlocking(clientFactory())) {
        final TesterProto.TestResponse response = client.test(REQUEST);
        assertThat(response, is(notNullValue()));
        assertThat(response.getMessage(), is(notNullValue()));
    }
}
Also used : BlockingTesterClient(io.servicetalk.grpc.netty.TesterProto.Tester.BlockingTesterClient) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) AddressUtils.localAddress(io.servicetalk.transport.netty.internal.AddressUtils.localAddress) ServerContext(io.servicetalk.transport.api.ServerContext) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) ServerSslConfigBuilder(io.servicetalk.transport.api.ServerSslConfigBuilder) InetSocketAddress(java.net.InetSocketAddress) DefaultTestCerts.serverPemHostname(io.servicetalk.test.resources.DefaultTestCerts.serverPemHostname) Test(org.junit.jupiter.api.Test) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) GrpcStatusException(io.servicetalk.grpc.api.GrpcStatusException) ServerSslConfig(io.servicetalk.transport.api.ServerSslConfig) DEFAULT_STRATEGY_ASYNC_SERVICE(io.servicetalk.grpc.netty.ExecutionStrategyTestServices.DEFAULT_STRATEGY_ASYNC_SERVICE) StacklessClosedChannelException(io.servicetalk.transport.netty.internal.StacklessClosedChannelException) ClientSslConfigBuilder(io.servicetalk.transport.api.ClientSslConfigBuilder) AddressUtils.serverHostAndPort(io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort) Collections.singletonMap(java.util.Collections.singletonMap) Matchers.is(org.hamcrest.Matchers.is) DefaultTestCerts(io.servicetalk.test.resources.DefaultTestCerts) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) GrpcClientBuilder(io.servicetalk.grpc.api.GrpcClientBuilder) HostAndPort(io.servicetalk.transport.api.HostAndPort) InetAddress.getLoopbackAddress(java.net.InetAddress.getLoopbackAddress) ServerContext(io.servicetalk.transport.api.ServerContext) DefaultTestCerts(io.servicetalk.test.resources.DefaultTestCerts) ClientSslConfigBuilder(io.servicetalk.transport.api.ClientSslConfigBuilder) BlockingTesterClient(io.servicetalk.grpc.netty.TesterProto.Tester.BlockingTesterClient) Test(org.junit.jupiter.api.Test)

Example 58 with ServerContext

use of io.servicetalk.transport.api.ServerContext in project servicetalk by apple.

the class GrpcSslAndNonSslConnectionsTest method secureClientToNonSecureServerClosesConnection.

@Test
void secureClientToNonSecureServerClosesConnection() throws Exception {
    try (ServerContext serverContext = nonSecureGrpcServer();
        BlockingTesterClient client = secureGrpcClient(serverContext, new ClientSslConfigBuilder(DefaultTestCerts::loadServerCAPem).peerHost(serverPemHostname())).buildBlocking(clientFactory())) {
        GrpcStatusException e = assertThrows(GrpcStatusException.class, () -> client.test(REQUEST));
        assertThat(e.getCause(), instanceOf(SSLHandshakeException.class));
    }
}
Also used : GrpcStatusException(io.servicetalk.grpc.api.GrpcStatusException) ServerContext(io.servicetalk.transport.api.ServerContext) ClientSslConfigBuilder(io.servicetalk.transport.api.ClientSslConfigBuilder) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) BlockingTesterClient(io.servicetalk.grpc.netty.TesterProto.Tester.BlockingTesterClient) Test(org.junit.jupiter.api.Test)

Example 59 with ServerContext

use of io.servicetalk.transport.api.ServerContext in project servicetalk by apple.

the class GrpcUdsTest method udsRoundTrip.

@Test
void udsRoundTrip() throws Exception {
    Assumptions.assumeTrue(ioExecutor.isUnixDomainSocketSupported());
    String greetingPrefix = "Hello ";
    String name = "foo";
    String expectedResponse = greetingPrefix + name;
    try (ServerContext serverContext = forAddress(newSocketAddress()).initializeHttp(builder -> builder.ioExecutor(ioExecutor)).listenAndAwait((GreeterService) (ctx, request) -> succeeded(HelloReply.newBuilder().setMessage(greetingPrefix + request.getName()).build()));
        BlockingGreeterClient client = forResolvedAddress(serverContext.listenAddress()).buildBlocking(new ClientFactory())) {
        assertEquals(expectedResponse, client.sayHello(HelloRequest.newBuilder().setName(name).build()).getMessage());
    }
}
Also used : AddressUtils.newSocketAddress(io.servicetalk.transport.netty.internal.AddressUtils.newSocketAddress) ServerContext(io.servicetalk.transport.api.ServerContext) ClientFactory(io.grpc.examples.helloworld.Greeter.ClientFactory) GreeterService(io.grpc.examples.helloworld.Greeter.GreeterService) HelloRequest(io.grpc.examples.helloworld.HelloRequest) GrpcClients.forResolvedAddress(io.servicetalk.grpc.netty.GrpcClients.forResolvedAddress) AfterAll(org.junit.jupiter.api.AfterAll) Test(org.junit.jupiter.api.Test) ExecutionException(java.util.concurrent.ExecutionException) BlockingGreeterClient(io.grpc.examples.helloworld.Greeter.BlockingGreeterClient) GrpcServers.forAddress(io.servicetalk.grpc.netty.GrpcServers.forAddress) IoExecutor(io.servicetalk.transport.api.IoExecutor) Assumptions(org.junit.jupiter.api.Assumptions) BeforeAll(org.junit.jupiter.api.BeforeAll) NettyIoExecutors.createIoExecutor(io.servicetalk.transport.netty.NettyIoExecutors.createIoExecutor) Single.succeeded(io.servicetalk.concurrent.api.Single.succeeded) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) HelloReply(io.grpc.examples.helloworld.HelloReply) Nullable(javax.annotation.Nullable) ServerContext(io.servicetalk.transport.api.ServerContext) ClientFactory(io.grpc.examples.helloworld.Greeter.ClientFactory) BlockingGreeterClient(io.grpc.examples.helloworld.Greeter.BlockingGreeterClient) Test(org.junit.jupiter.api.Test)

Example 60 with ServerContext

use of io.servicetalk.transport.api.ServerContext in project servicetalk by apple.

the class ProtocolCompatibilityTest method grpcJavaToServiceTalkClientTimeout.

@ParameterizedTest
@MethodSource("sslStreamingAndCompressionParams")
void grpcJavaToServiceTalkClientTimeout(final boolean ssl, final boolean streaming, final String compression) throws Exception {
    final TestServerContext server = serviceTalkServer(ErrorMode.NONE, ssl, compression, null);
    try (ServerContext proxyCtx = buildTimeoutProxy(server.listenAddress(), null, ssl)) {
        final CompatClient client = grpcJavaClient(proxyCtx.listenAddress(), compression, ssl, DEFAULT_DEADLINE);
        testGrpcError(client, server, false, streaming, compression, DEADLINE_EXCEEDED, null);
    }
}
Also used : HttpServerContext(io.servicetalk.http.api.HttpServerContext) ServerContext(io.servicetalk.transport.api.ServerContext) BlockingCompatClient(io.servicetalk.grpc.netty.CompatProto.Compat.BlockingCompatClient) CompatClient(io.servicetalk.grpc.netty.CompatProto.Compat.CompatClient) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

ServerContext (io.servicetalk.transport.api.ServerContext)106 Test (org.junit.jupiter.api.Test)57 BlockingHttpClient (io.servicetalk.http.api.BlockingHttpClient)42 HttpResponse (io.servicetalk.http.api.HttpResponse)39 AddressUtils.serverHostAndPort (io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort)34 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)34 AddressUtils.localAddress (io.servicetalk.transport.netty.internal.AddressUtils.localAddress)33 StreamingHttpResponse (io.servicetalk.http.api.StreamingHttpResponse)28 InetSocketAddress (java.net.InetSocketAddress)27 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)26 StreamingHttpRequest (io.servicetalk.http.api.StreamingHttpRequest)24 MethodSource (org.junit.jupiter.params.provider.MethodSource)22 HostAndPort (io.servicetalk.transport.api.HostAndPort)20 Single (io.servicetalk.concurrent.api.Single)19 Single.succeeded (io.servicetalk.concurrent.api.Single.succeeded)19 StreamingHttpClient (io.servicetalk.http.api.StreamingHttpClient)16 ClientSslConfigBuilder (io.servicetalk.transport.api.ClientSslConfigBuilder)15 OK (io.servicetalk.http.api.HttpResponseStatus.OK)14 DefaultTestCerts (io.servicetalk.test.resources.DefaultTestCerts)14 AtomicReference (java.util.concurrent.atomic.AtomicReference)14