Search in sources :

Example 1 with SslContextProviderSupplier

use of io.grpc.xds.internal.sds.SslContextProviderSupplier in project grpc-java by grpc.

the class XdsSdsClientServerTest method getBlockingStub.

private SimpleServiceGrpc.SimpleServiceBlockingStub getBlockingStub(final UpstreamTlsContext upstreamTlsContext, String overrideAuthority) throws URISyntaxException {
    ManagedChannelBuilder<?> channelBuilder = Grpc.newChannelBuilder("sdstest://localhost:" + port, XdsChannelCredentials.create(InsecureChannelCredentials.create()));
    if (overrideAuthority != null) {
        channelBuilder = channelBuilder.overrideAuthority(overrideAuthority);
    }
    InetSocketAddress socketAddress = new InetSocketAddress(Inet4Address.getLoopbackAddress(), port);
    tlsContextManagerForClient = new TlsContextManagerImpl(bootstrapInfoForClient);
    Attributes attrs = (upstreamTlsContext != null) ? Attributes.newBuilder().set(InternalXdsAttributes.ATTR_SSL_CONTEXT_PROVIDER_SUPPLIER, new SslContextProviderSupplier(upstreamTlsContext, tlsContextManagerForClient)).build() : Attributes.EMPTY;
    fakeNameResolverFactory.setServers(ImmutableList.of(new EquivalentAddressGroup(socketAddress, attrs)));
    return SimpleServiceGrpc.newBlockingStub(cleanupRule.register(channelBuilder.build()));
}
Also used : InetSocketAddress(java.net.InetSocketAddress) EquivalentAddressGroup(io.grpc.EquivalentAddressGroup) Attributes(io.grpc.Attributes) TlsContextManagerImpl(io.grpc.xds.internal.sds.TlsContextManagerImpl) SslContextProviderSupplier(io.grpc.xds.internal.sds.SslContextProviderSupplier)

Example 2 with SslContextProviderSupplier

use of io.grpc.xds.internal.sds.SslContextProviderSupplier in project grpc-java by grpc.

the class FilterChainMatchingProtocolNegotiatorsTest method nofilterChainMatch_defaultSslContext.

@Test
public void nofilterChainMatch_defaultSslContext() throws Exception {
    ChannelHandler next = captureAttrHandler(sslSet, routingSettable);
    when(mockDelegate.newHandler(grpcHandler)).thenReturn(next);
    SslContextProviderSupplier defaultSsl = new SslContextProviderSupplier(createTls(), tlsContextManager);
    selectorManager.updateSelector(new FilterChainSelector(new HashMap<FilterChain, AtomicReference<ServerRoutingConfig>>(), defaultSsl, noopConfig));
    FilterChainMatchingHandler filterChainMatchingHandler = new FilterChainMatchingHandler(grpcHandler, selectorManager, mockDelegate);
    setupChannel("172.168.1.1", "172.168.1.2", 80, filterChainMatchingHandler);
    ChannelHandlerContext channelHandlerCtx = pipeline.context(filterChainMatchingHandler);
    assertThat(channelHandlerCtx).isNotNull();
    pipeline.fireUserEventTriggered(event);
    channelHandlerCtx = pipeline.context(filterChainMatchingHandler);
    assertThat(channelHandlerCtx).isNull();
    channel.runPendingTasks();
    assertThat(sslSet.isDone()).isTrue();
    assertThat(sslSet.get()).isEqualTo(defaultSsl);
    assertThat(routingSettable.get()).isEqualTo(noopConfig);
    channelHandlerCtx = pipeline.context(next);
    assertThat(channelHandlerCtx).isNotNull();
}
Also used : FilterChainSelector(io.grpc.xds.FilterChainMatchingProtocolNegotiators.FilterChainMatchingHandler.FilterChainSelector) ServerRoutingConfig(io.grpc.xds.XdsServerWrapper.ServerRoutingConfig) FilterChainMatchingHandler(io.grpc.xds.FilterChainMatchingProtocolNegotiators.FilterChainMatchingHandler) HashMap(java.util.HashMap) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ChannelHandler(io.netty.channel.ChannelHandler) SslContextProviderSupplier(io.grpc.xds.internal.sds.SslContextProviderSupplier) Test(org.junit.Test)

Example 3 with SslContextProviderSupplier

use of io.grpc.xds.internal.sds.SslContextProviderSupplier in project grpc-java by grpc.

the class XdsClientWrapperForServerSdsTestMisc method releaseOldSupplierOnPermDeniedError_verifyClose.

@Test
public void releaseOldSupplierOnPermDeniedError_verifyClose() throws Exception {
    SslContextProvider sslContextProvider1 = mock(SslContextProvider.class);
    when(tlsContextManager.findOrCreateServerSslContextProvider(eq(tlsContext1))).thenReturn(sslContextProvider1);
    InetAddress ipLocalAddress = InetAddress.getByName("10.1.2.3");
    localAddress = new InetSocketAddress(ipLocalAddress, PORT);
    sendListenerUpdate(localAddress, tlsContext1, null, tlsContextManager);
    SslContextProviderSupplier returnedSupplier = getSslContextProviderSupplier(selectorManager.getSelectorToUpdateSelector());
    assertThat(returnedSupplier.getTlsContext()).isSameInstanceAs(tlsContext1);
    callUpdateSslContext(returnedSupplier);
    xdsClient.ldsWatcher.onError(Status.PERMISSION_DENIED);
    verify(tlsContextManager, times(1)).releaseServerSslContextProvider(eq(sslContextProvider1));
}
Also used : InetSocketAddress(java.net.InetSocketAddress) SslContextProvider(io.grpc.xds.internal.sds.SslContextProvider) InetAddress(java.net.InetAddress) SslContextProviderSupplier(io.grpc.xds.internal.sds.SslContextProviderSupplier) Test(org.junit.Test)

Example 4 with SslContextProviderSupplier

use of io.grpc.xds.internal.sds.SslContextProviderSupplier in project grpc-java by grpc.

the class XdsClientWrapperForServerSdsTestMisc method releaseOldSupplierOnChangedOnShutdown_verifyClose.

@Test
public void releaseOldSupplierOnChangedOnShutdown_verifyClose() throws Exception {
    SslContextProvider sslContextProvider1 = mock(SslContextProvider.class);
    when(tlsContextManager.findOrCreateServerSslContextProvider(eq(tlsContext1))).thenReturn(sslContextProvider1);
    InetAddress ipLocalAddress = InetAddress.getByName("10.1.2.3");
    localAddress = new InetSocketAddress(ipLocalAddress, PORT);
    sendListenerUpdate(localAddress, tlsContext1, null, tlsContextManager);
    SslContextProviderSupplier returnedSupplier = getSslContextProviderSupplier(selectorManager.getSelectorToUpdateSelector());
    assertThat(returnedSupplier.getTlsContext()).isSameInstanceAs(tlsContext1);
    callUpdateSslContext(returnedSupplier);
    XdsServerTestHelper.generateListenerUpdate(xdsClient, ImmutableList.of(1234), tlsContext2, tlsContext3, tlsContextManager);
    returnedSupplier = getSslContextProviderSupplier(selectorManager.getSelectorToUpdateSelector());
    assertThat(returnedSupplier.getTlsContext()).isSameInstanceAs(tlsContext2);
    verify(tlsContextManager, times(1)).releaseServerSslContextProvider(eq(sslContextProvider1));
    reset(tlsContextManager);
    SslContextProvider sslContextProvider2 = mock(SslContextProvider.class);
    when(tlsContextManager.findOrCreateServerSslContextProvider(eq(tlsContext2))).thenReturn(sslContextProvider2);
    SslContextProvider sslContextProvider3 = mock(SslContextProvider.class);
    when(tlsContextManager.findOrCreateServerSslContextProvider(eq(tlsContext3))).thenReturn(sslContextProvider3);
    callUpdateSslContext(returnedSupplier);
    InetAddress ipRemoteAddress = InetAddress.getByName("10.4.5.6");
    final InetSocketAddress remoteAddress = new InetSocketAddress(ipRemoteAddress, 1111);
    channel = new EmbeddedChannel() {

        @Override
        public SocketAddress localAddress() {
            return localAddress;
        }

        @Override
        public SocketAddress remoteAddress() {
            return remoteAddress;
        }
    };
    pipeline = channel.pipeline();
    returnedSupplier = getSslContextProviderSupplier(selectorManager.getSelectorToUpdateSelector());
    assertThat(returnedSupplier.getTlsContext()).isSameInstanceAs(tlsContext3);
    callUpdateSslContext(returnedSupplier);
    xdsServerWrapper.shutdown();
    assertThat(xdsClient.ldsResource).isNull();
    verify(tlsContextManager, never()).releaseServerSslContextProvider(eq(sslContextProvider1));
    verify(tlsContextManager, times(1)).releaseServerSslContextProvider(eq(sslContextProvider2));
    verify(tlsContextManager, times(1)).releaseServerSslContextProvider(eq(sslContextProvider3));
}
Also used : InetSocketAddress(java.net.InetSocketAddress) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) SslContextProvider(io.grpc.xds.internal.sds.SslContextProvider) SocketAddress(java.net.SocketAddress) InProcessSocketAddress(io.grpc.inprocess.InProcessSocketAddress) InetSocketAddress(java.net.InetSocketAddress) InetAddress(java.net.InetAddress) SslContextProviderSupplier(io.grpc.xds.internal.sds.SslContextProviderSupplier) Test(org.junit.Test)

Example 5 with SslContextProviderSupplier

use of io.grpc.xds.internal.sds.SslContextProviderSupplier in project grpc-java by grpc.

the class XdsClientWrapperForServerSdsTestMisc method releaseOldSupplierOnTemporaryError_noClose.

@Test
public void releaseOldSupplierOnTemporaryError_noClose() throws Exception {
    SslContextProvider sslContextProvider1 = mock(SslContextProvider.class);
    when(tlsContextManager.findOrCreateServerSslContextProvider(eq(tlsContext1))).thenReturn(sslContextProvider1);
    InetAddress ipLocalAddress = InetAddress.getByName("10.1.2.3");
    localAddress = new InetSocketAddress(ipLocalAddress, PORT);
    sendListenerUpdate(localAddress, tlsContext1, null, tlsContextManager);
    SslContextProviderSupplier returnedSupplier = getSslContextProviderSupplier(selectorManager.getSelectorToUpdateSelector());
    assertThat(returnedSupplier.getTlsContext()).isSameInstanceAs(tlsContext1);
    callUpdateSslContext(returnedSupplier);
    xdsClient.ldsWatcher.onError(Status.CANCELLED);
    verify(tlsContextManager, never()).releaseServerSslContextProvider(eq(sslContextProvider1));
}
Also used : InetSocketAddress(java.net.InetSocketAddress) SslContextProvider(io.grpc.xds.internal.sds.SslContextProvider) InetAddress(java.net.InetAddress) SslContextProviderSupplier(io.grpc.xds.internal.sds.SslContextProviderSupplier) Test(org.junit.Test)

Aggregations

SslContextProviderSupplier (io.grpc.xds.internal.sds.SslContextProviderSupplier)10 Test (org.junit.Test)7 InetSocketAddress (java.net.InetSocketAddress)5 SslContextProvider (io.grpc.xds.internal.sds.SslContextProvider)4 InetAddress (java.net.InetAddress)4 EquivalentAddressGroup (io.grpc.EquivalentAddressGroup)2 Server (io.grpc.Server)2 StatusException (io.grpc.StatusException)2 FilterChain (io.grpc.xds.EnvoyServerProtoData.FilterChain)2 FilterChainMatchingHandler (io.grpc.xds.FilterChainMatchingProtocolNegotiators.FilterChainMatchingHandler)2 ServerRoutingConfig (io.grpc.xds.XdsServerWrapper.ServerRoutingConfig)2 ChannelHandler (io.netty.channel.ChannelHandler)2 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)2 IOException (java.io.IOException)2 ExecutionException (java.util.concurrent.ExecutionException)2 TimeoutException (java.util.concurrent.TimeoutException)2 Attributes (io.grpc.Attributes)1 CreateSubchannelArgs (io.grpc.LoadBalancer.CreateSubchannelArgs)1 Subchannel (io.grpc.LoadBalancer.Subchannel)1 LoadBalancerProvider (io.grpc.LoadBalancerProvider)1