Search in sources :

Example 1 with Resource

use of io.helidon.common.configurable.Resource in project helidon by oracle.

the class SslIT method shouldConnectWithClientCertsFor2Way.

@Test
public void shouldConnectWithClientCertsFor2Way() throws Exception {
    Resource tlsCaCert = Resource.create(CA_CERT);
    Resource tlsClientCert = Resource.create(CLIENT_CERT);
    Resource tlsClientKey = Resource.create(CLIENT_KEY);
    SslContext sslContext = clientSslContext(tlsCaCert, tlsClientCert, tlsClientKey);
    Channel channel = NettyChannelBuilder.forAddress("localhost", grpcServer_2WaySSL.port()).negotiationType(NegotiationType.TLS).sslContext(sslContext).build();
    // call the gRPC Echo service
    Echo.EchoResponse response = EchoServiceGrpc.newBlockingStub(channel).echo(Echo.EchoRequest.newBuilder().setMessage("foo").build());
    assertThat(response.getMessage(), is("foo"));
    ((ManagedChannel) channel).shutdown().awaitTermination(5, TimeUnit.SECONDS);
}
Also used : Echo(io.helidon.grpc.server.test.Echo) ManagedChannel(io.grpc.ManagedChannel) Channel(io.grpc.Channel) Resource(io.helidon.common.configurable.Resource) SslContext(io.netty.handler.ssl.SslContext) Test(org.junit.jupiter.api.Test)

Example 2 with Resource

use of io.helidon.common.configurable.Resource in project helidon by oracle.

the class SslIT method shouldConnectWithoutClientCertsFor1Way.

// ----- test methods ---------------------------------------------------
@Test
public void shouldConnectWithoutClientCertsFor1Way() throws Exception {
    Resource tlsCaCert = Resource.create(CA_CERT);
    // client do not have to provide certs for 1way ssl
    SslContext sslContext = clientSslContext(tlsCaCert, null, null);
    Channel channel = NettyChannelBuilder.forAddress("localhost", grpcServer_1WaySSL.port()).negotiationType(NegotiationType.TLS).sslContext(sslContext).build();
    // call the gRPC Echo service suggestion
    Echo.EchoResponse response = EchoServiceGrpc.newBlockingStub(channel).echo(Echo.EchoRequest.newBuilder().setMessage("foo").build());
    assertThat(response.getMessage(), is("foo"));
    ((ManagedChannel) channel).shutdown().awaitTermination(5, TimeUnit.SECONDS);
}
Also used : Echo(io.helidon.grpc.server.test.Echo) ManagedChannel(io.grpc.ManagedChannel) Channel(io.grpc.Channel) Resource(io.helidon.common.configurable.Resource) SslContext(io.netty.handler.ssl.SslContext) Test(org.junit.jupiter.api.Test)

Example 3 with Resource

use of io.helidon.common.configurable.Resource in project helidon by oracle.

the class SslIT method shouldNotConnectWithoutCAFor2Way.

@Test
public void shouldNotConnectWithoutCAFor2Way() throws Exception {
    Resource tlsClientCert = Resource.create(CLIENT_CERT);
    Resource tlsClientKey = Resource.create(CLIENT_KEY);
    SslContext sslContext = clientSslContext(null, tlsClientCert, tlsClientKey);
    Channel channel = NettyChannelBuilder.forAddress("localhost", grpcServer_2WaySSL.port()).negotiationType(NegotiationType.TLS).sslContext(sslContext).build();
    // call the gRPC Echo service should throw
    Assertions.assertThrows(StatusRuntimeException.class, () -> EchoServiceGrpc.newBlockingStub(channel).echo(Echo.EchoRequest.newBuilder().setMessage("foo").build()));
    ((ManagedChannel) channel).shutdown().awaitTermination(5, TimeUnit.SECONDS);
}
Also used : ManagedChannel(io.grpc.ManagedChannel) Channel(io.grpc.Channel) Resource(io.helidon.common.configurable.Resource) SslContext(io.netty.handler.ssl.SslContext) Test(org.junit.jupiter.api.Test)

Example 4 with Resource

use of io.helidon.common.configurable.Resource in project helidon by oracle.

the class GrpcChannelsProviderTest method testDefaultPortSsl.

@Test
public void testDefaultPortSsl() {
    GrpcChannelDescriptor chCfg = grpcConfig.channels().get(DEFAULT_PORT_SSL_CFG);
    assertThat(chCfg.host(), equalTo("non_default_host.com"));
    assertThat(chCfg.port(), equalTo(1408));
    Resource keyResource = Resource.create(CLIENT_KEY);
    Resource certResource = Resource.create(CLIENT_CERT);
    Resource trustResource = Resource.create(CA_CERT);
    Optional<GrpcTlsDescriptor> descriptor = chCfg.tlsDescriptor();
    assertThat(descriptor.isPresent(), is(true));
    GrpcTlsDescriptor ssl = descriptor.get();
    assertThat(ssl, notNullValue());
    assertThat(ssl.isEnabled(), equalTo(true));
    assertThat(ssl.tlsKey(), is(notNullValue()));
    assertThat(ssl.tlsKey().location(), is(keyResource.location()));
    assertThat(ssl.tlsCert(), is(notNullValue()));
    assertThat(ssl.tlsCert().location(), endsWith(certResource.location()));
    assertThat(ssl.tlsCaCert(), is(notNullValue()));
    assertThat(ssl.tlsCaCert().location(), endsWith(trustResource.location()));
}
Also used : Resource(io.helidon.common.configurable.Resource) GrpcTlsDescriptor(io.helidon.grpc.core.GrpcTlsDescriptor) Test(org.junit.jupiter.api.Test)

Example 5 with Resource

use of io.helidon.common.configurable.Resource in project helidon by oracle.

the class GrpcChannelsProviderTest method testDefaultHostSslOneWay.

@Test
public void testDefaultHostSslOneWay() {
    GrpcChannelDescriptor chCfg = grpcConfig.channels().get(DEFAULT_HOST_SSL_ONE_WAY_CFG);
    assertThat(chCfg.host(), equalTo("localhost"));
    assertThat(chCfg.port(), equalTo(4096));
    Resource trustResource = Resource.create(CA_CERT);
    Optional<GrpcTlsDescriptor> descriptor = chCfg.tlsDescriptor();
    assertThat(descriptor.isPresent(), is(true));
    GrpcTlsDescriptor ssl = descriptor.get();
    assertThat(ssl, notNullValue());
    assertThat(ssl.isEnabled(), equalTo(true));
    assertThat(ssl.tlsKey(), nullValue());
    assertThat(ssl.tlsCert(), nullValue());
    assertThat(ssl.tlsCaCert(), is(notNullValue()));
    assertThat(ssl.tlsCaCert().location(), endsWith(trustResource.location()));
}
Also used : Resource(io.helidon.common.configurable.Resource) GrpcTlsDescriptor(io.helidon.grpc.core.GrpcTlsDescriptor) Test(org.junit.jupiter.api.Test)

Aggregations

Resource (io.helidon.common.configurable.Resource)14 Test (org.junit.jupiter.api.Test)10 Channel (io.grpc.Channel)6 ManagedChannel (io.grpc.ManagedChannel)6 GrpcTlsDescriptor (io.helidon.grpc.core.GrpcTlsDescriptor)6 SslContext (io.netty.handler.ssl.SslContext)6 Echo (io.helidon.grpc.server.test.Echo)3 StatusRuntimeException (io.grpc.StatusRuntimeException)1 LogConfig (io.helidon.common.LogConfig)1 Config (io.helidon.config.Config)1 GrpcRouting (io.helidon.grpc.server.GrpcRouting)1 GrpcServerConfiguration (io.helidon.grpc.server.GrpcServerConfiguration)1 SslContextBuilder (io.netty.handler.ssl.SslContextBuilder)1 CertificateException (java.security.cert.CertificateException)1 X509Certificate (java.security.cert.X509Certificate)1 EchoService (services.EchoService)1 TreeMapService (services.TreeMapService)1