Search in sources :

Example 1 with TlsNegotiator

use of io.grpc.netty.ProtocolNegotiators.TlsNegotiator in project grpc-java by grpc.

the class NettyChannelBuilderTest method createProtocolNegotiator_tlsWithClientContext.

@Test
public void createProtocolNegotiator_tlsWithClientContext() throws SSLException {
    ProtocolNegotiator negotiator = NettyChannelBuilder.createProtocolNegotiator("authority:1234", NegotiationType.TLS, GrpcSslContexts.forClient().build());
    assertTrue(negotiator instanceof ProtocolNegotiators.TlsNegotiator);
    ProtocolNegotiators.TlsNegotiator n = (TlsNegotiator) negotiator;
    assertEquals("authority", n.getHost());
    assertEquals(1234, n.getPort());
}
Also used : TlsNegotiator(io.grpc.netty.ProtocolNegotiators.TlsNegotiator) TlsNegotiator(io.grpc.netty.ProtocolNegotiators.TlsNegotiator) Test(org.junit.Test)

Example 2 with TlsNegotiator

use of io.grpc.netty.ProtocolNegotiators.TlsNegotiator in project grpc-java by grpc.

the class NettyChannelBuilderTest method createProtocolNegotiator_tlsWithNoContext.

@Test
public void createProtocolNegotiator_tlsWithNoContext() {
    ProtocolNegotiator negotiator = NettyChannelBuilder.createProtocolNegotiator("authority:1234", NegotiationType.TLS, noSslContext);
    assertTrue(negotiator instanceof ProtocolNegotiators.TlsNegotiator);
    ProtocolNegotiators.TlsNegotiator n = (TlsNegotiator) negotiator;
    assertEquals("authority", n.getHost());
    assertEquals(1234, n.getPort());
}
Also used : TlsNegotiator(io.grpc.netty.ProtocolNegotiators.TlsNegotiator) TlsNegotiator(io.grpc.netty.ProtocolNegotiators.TlsNegotiator) Test(org.junit.Test)

Example 3 with TlsNegotiator

use of io.grpc.netty.ProtocolNegotiators.TlsNegotiator in project grpc-java by grpc.

the class ProtocolNegotiatorsTest method tls_hostAndPort.

@Test
public void tls_hostAndPort() throws SSLException {
    SslContext ctx = GrpcSslContexts.forClient().build();
    TlsNegotiator negotiator = (TlsNegotiator) ProtocolNegotiators.tls(ctx, "authority:1234");
    assertEquals("authority", negotiator.getHost());
    assertEquals(1234, negotiator.getPort());
}
Also used : TlsNegotiator(io.grpc.netty.ProtocolNegotiators.TlsNegotiator) SslContext(io.netty.handler.ssl.SslContext) Test(org.junit.Test)

Example 4 with TlsNegotiator

use of io.grpc.netty.ProtocolNegotiators.TlsNegotiator in project grpc-java by grpc.

the class ProtocolNegotiatorsTest method tls_invalidHost.

@Test
public void tls_invalidHost() throws SSLException {
    SslContext ctx = GrpcSslContexts.forClient().build();
    TlsNegotiator negotiator = (TlsNegotiator) ProtocolNegotiators.tls(ctx, "bad_host:1234");
    // Even though it looks like a port, we treat it as part of the authority, since the host is
    // invalid.
    assertEquals("bad_host:1234", negotiator.getHost());
    assertEquals(-1, negotiator.getPort());
}
Also used : TlsNegotiator(io.grpc.netty.ProtocolNegotiators.TlsNegotiator) SslContext(io.netty.handler.ssl.SslContext) Test(org.junit.Test)

Example 5 with TlsNegotiator

use of io.grpc.netty.ProtocolNegotiators.TlsNegotiator in project grpc-java by grpc.

the class NettyChannelBuilderTest method createProtocolNegotiator_tlsWithAuthorityFallback.

@Test
public void createProtocolNegotiator_tlsWithAuthorityFallback() {
    ProtocolNegotiator negotiator = NettyChannelBuilder.createProtocolNegotiator("bad_authority", NegotiationType.TLS, noSslContext);
    assertTrue(negotiator instanceof ProtocolNegotiators.TlsNegotiator);
    ProtocolNegotiators.TlsNegotiator n = (TlsNegotiator) negotiator;
    assertEquals("bad_authority", n.getHost());
    assertEquals(-1, n.getPort());
}
Also used : TlsNegotiator(io.grpc.netty.ProtocolNegotiators.TlsNegotiator) TlsNegotiator(io.grpc.netty.ProtocolNegotiators.TlsNegotiator) Test(org.junit.Test)

Aggregations

TlsNegotiator (io.grpc.netty.ProtocolNegotiators.TlsNegotiator)6 Test (org.junit.Test)6 SslContext (io.netty.handler.ssl.SslContext)3