use of com.squareup.okhttp.ConnectionSpec in project grpc-java by grpc.
the class Http2OkHttpTest method wrongHostNameFailHostnameVerification.
@Test(timeout = 10000)
public void wrongHostNameFailHostnameVerification() throws Exception {
OkHttpChannelBuilder builder = OkHttpChannelBuilder.forAddress("127.0.0.1", getPort()).connectionSpec(new ConnectionSpec.Builder(OkHttpChannelBuilder.DEFAULT_CONNECTION_SPEC).cipherSuites(TestUtils.preferredTestCiphers().toArray(new String[0])).tlsVersions(ConnectionSpec.MODERN_TLS.tlsVersions().toArray(new TlsVersion[0])).build()).overrideAuthority(GrpcUtil.authorityFromHostAndPort("I.am.a.bad.hostname", getPort()));
ManagedChannel channel = builder.sslSocketFactory(TestUtils.newSslSocketFactoryForCa(Platform.get().getProvider(), TestUtils.loadCert("ca.pem"))).build();
TestServiceGrpc.TestServiceBlockingStub blockingStub = TestServiceGrpc.newBlockingStub(channel);
try {
blockingStub.emptyCall(Empty.getDefaultInstance());
fail("The rpc should have been failed due to hostname verification");
} catch (Throwable t) {
Throwable cause = Throwables.getRootCause(t);
assertTrue("Failed by unexpected exception: " + cause, cause instanceof SSLPeerUnverifiedException);
}
channel.shutdown();
}
use of com.squareup.okhttp.ConnectionSpec in project grpc-java by grpc.
the class Http2OkHttpTest method createChannel.
@Override
protected ManagedChannel createChannel() {
OkHttpChannelBuilder builder = OkHttpChannelBuilder.forAddress("127.0.0.1", getPort()).maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE).connectionSpec(new ConnectionSpec.Builder(OkHttpChannelBuilder.DEFAULT_CONNECTION_SPEC).cipherSuites(TestUtils.preferredTestCiphers().toArray(new String[0])).tlsVersions(ConnectionSpec.MODERN_TLS.tlsVersions().toArray(new TlsVersion[0])).build()).overrideAuthority(GrpcUtil.authorityFromHostAndPort(TestUtils.TEST_SERVER_HOST, getPort()));
io.grpc.internal.TestingAccessor.setStatsContextFactory(builder, getClientStatsFactory());
try {
builder.sslSocketFactory(TestUtils.newSslSocketFactoryForCa(Platform.get().getProvider(), TestUtils.loadCert("ca.pem")));
} catch (Exception e) {
throw new RuntimeException(e);
}
return builder.build();
}
Aggregations