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