Search in sources :

Example 21 with DefaultTestCerts

use of io.servicetalk.test.resources.DefaultTestCerts 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)

Aggregations

DefaultTestCerts (io.servicetalk.test.resources.DefaultTestCerts)21 ClientSslConfigBuilder (io.servicetalk.transport.api.ClientSslConfigBuilder)20 ServerContext (io.servicetalk.transport.api.ServerContext)15 ServerSslConfigBuilder (io.servicetalk.transport.api.ServerSslConfigBuilder)14 BlockingHttpClient (io.servicetalk.http.api.BlockingHttpClient)12 HostAndPort (io.servicetalk.transport.api.HostAndPort)9 AddressUtils.serverHostAndPort (io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort)9 HttpResponse (io.servicetalk.http.api.HttpResponse)8 DefaultTestCerts.serverPemHostname (io.servicetalk.test.resources.DefaultTestCerts.serverPemHostname)8 AddressUtils.localAddress (io.servicetalk.transport.netty.internal.AddressUtils.localAddress)8 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)8 Matchers.is (org.hamcrest.Matchers.is)8 Nullable (javax.annotation.Nullable)6 Matchers.instanceOf (org.hamcrest.Matchers.instanceOf)6 AfterEach (org.junit.jupiter.api.AfterEach)6 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)6 Test (org.junit.jupiter.api.Test)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 Single (io.servicetalk.concurrent.api.Single)5 OK (io.servicetalk.http.api.HttpResponseStatus.OK)5