Search in sources :

Example 46 with CertificateValidationContext

use of io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.CertificateValidationContext in project grpc-java by grpc.

the class CertProviderClientSslContextProviderTest method testProviderForClient_sslContextException_onError.

@Test
public void testProviderForClient_sslContextException_onError() throws Exception {
    CertificateValidationContext staticCertValidationContext = CertificateValidationContext.newBuilder().setTrustedCa(DataSource.newBuilder().setInlineString("foo")).build();
    final CertificateProvider.DistributorWatcher[] watcherCaptor = new CertificateProvider.DistributorWatcher[1];
    TestCertificateProvider.createAndRegisterProviderProvider(certificateProviderRegistry, watcherCaptor, "testca", 0);
    CertProviderClientSslContextProvider provider = getSslContextProvider(/* certInstanceName= */
    null, "gcp_id", CommonBootstrapperTestUtils.getTestBootstrapInfo(), /* alpnProtocols= */
    null, staticCertValidationContext);
    TestCallback testCallback = new TestCallback(MoreExecutors.directExecutor());
    provider.addCallback(testCallback);
    try {
        watcherCaptor[0].updateTrustedRoots(ImmutableList.of(getCertFromResourceName(CA_PEM_FILE)));
        fail("exception expected");
    } catch (RuntimeException expected) {
        assertThat(expected).hasMessageThat().contains("only static certificateValidationContext expected");
    }
    assertThat(testCallback.updatedThrowable).isNotNull();
    assertThat(testCallback.updatedThrowable).hasCauseThat().hasMessageThat().contains("only static certificateValidationContext expected");
}
Also used : TestCallback(io.grpc.xds.internal.sds.CommonTlsContextTestsUtil.TestCallback) CertificateValidationContext(io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.CertificateValidationContext) Test(org.junit.Test)

Aggregations

CertificateValidationContext (io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.CertificateValidationContext)45 Test (org.junit.Test)40 X509Certificate (java.security.cert.X509Certificate)30 StringMatcher (io.envoyproxy.envoy.type.matcher.v3.StringMatcher)27 CertificateException (java.security.cert.CertificateException)15 Bootstrapper (io.grpc.xds.Bootstrapper)5 CommonTlsContext (io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.CommonTlsContext)3 CombinedCertificateValidationContext (io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.CommonTlsContext.CombinedCertificateValidationContext)3 UpstreamTlsContext (io.grpc.xds.EnvoyServerProtoData.UpstreamTlsContext)3 CertProviderClientSslContextProvider (io.grpc.xds.internal.certprovider.CertProviderClientSslContextProvider)3 TestCallback (io.grpc.xds.internal.sds.CommonTlsContextTestsUtil.TestCallback)3 CertificateProviderInstance (io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.CommonTlsContext.CertificateProviderInstance)2 DownstreamTlsContext (io.grpc.xds.EnvoyServerProtoData.DownstreamTlsContext)2 CertProviderServerSslContextProvider (io.grpc.xds.internal.certprovider.CertProviderServerSslContextProvider)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 CertificateProviderPluginInstance (io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.CertificateProviderPluginInstance)1 TlsCertificate (io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.TlsCertificate)1 ApplicationProtocolConfig (io.netty.handler.ssl.ApplicationProtocolConfig)1 SslContext (io.netty.handler.ssl.SslContext)1 SslContextBuilder (io.netty.handler.ssl.SslContextBuilder)1