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