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