Skip to content

Commit ce1f2d0

Browse files
committed
Save changes
1 parent a576df0 commit ce1f2d0

File tree

2 files changed

+55
-3
lines changed

2 files changed

+55
-3
lines changed

xds/src/main/java/io/grpc/xds/internal/security/SslContextProviderSupplier.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,8 @@
1616

1717
package io.grpc.xds.internal.security;
1818

19-
import static com.google.common.base.Preconditions.checkNotNull;
20-
2119
import com.google.common.annotations.VisibleForTesting;
2220
import com.google.common.base.MoreObjects;
23-
import com.google.common.base.Strings;
2421
import io.grpc.xds.EnvoyServerProtoData.BaseTlsContext;
2522
import io.grpc.xds.EnvoyServerProtoData.DownstreamTlsContext;
2623
import io.grpc.xds.EnvoyServerProtoData.UpstreamTlsContext;
@@ -31,6 +28,8 @@
3128
import java.util.Objects;
3229
import java.util.Set;
3330

31+
import static com.google.common.base.Preconditions.checkNotNull;
32+
3433
/**
3534
* Enables Client or server side to initialize this object with the received {@link BaseTlsContext}
3635
* and communicate it to the consumer i.e. {@link SecurityProtocolNegotiators}

xds/src/test/java/io/grpc/xds/internal/security/SecurityProtocolNegotiatorsTest.java

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,59 @@ protected void onException(Throwable throwable) {
197197
.contains("ProtocolNegotiators.ClientTlsHandler");
198198
CommonCertProviderTestUtils.register0();
199199
}
200+
201+
@Test
202+
public void clientSecurityHandler_addLast()
203+
throws InterruptedException, TimeoutException, ExecutionException {
204+
FakeClock executor = new FakeClock();
205+
CommonCertProviderTestUtils.register(executor);
206+
Bootstrapper.BootstrapInfo bootstrapInfoForClient = CommonBootstrapperTestUtils
207+
.buildBootstrapInfo("google_cloud_private_spiffe-client", CLIENT_KEY_FILE, CLIENT_PEM_FILE,
208+
CA_PEM_FILE, null, null, null, null, null);
209+
UpstreamTlsContext upstreamTlsContext =
210+
CommonTlsContextTestsUtil
211+
.buildUpstreamTlsContext("google_cloud_private_spiffe-client", true, null, false);
212+
213+
SslContextProviderSupplier sslContextProviderSupplier =
214+
new SslContextProviderSupplier(upstreamTlsContext,
215+
new TlsContextManagerImpl(bootstrapInfoForClient));
216+
ClientSecurityHandler clientSecurityHandler =
217+
new ClientSecurityHandler(grpcHandler, sslContextProviderSupplier, HOSTNAME);
218+
pipeline.addLast(clientSecurityHandler);
219+
channelHandlerCtx = pipeline.context(clientSecurityHandler);
220+
assertNotNull(channelHandlerCtx);
221+
222+
// kick off protocol negotiation.
223+
pipeline.fireUserEventTriggered(InternalProtocolNegotiationEvent.getDefault());
224+
final SettableFuture<Object> future = SettableFuture.create();
225+
sslContextProviderSupplier
226+
.updateSslContext(new SslContextProvider.Callback(MoreExecutors.directExecutor()) {
227+
@Override
228+
public void updateSslContext(SslContext sslContext) {
229+
future.set(sslContext);
230+
}
231+
232+
@Override
233+
protected void onException(Throwable throwable) {
234+
future.set(throwable);
235+
}
236+
}, null);
237+
assertThat(executor.runDueTasks()).isEqualTo(1);
238+
channel.runPendingTasks();
239+
Object fromFuture = future.get(2, TimeUnit.SECONDS);
240+
assertThat(fromFuture).isInstanceOf(SslContext.class);
241+
channel.runPendingTasks();
242+
channelHandlerCtx = pipeline.context(clientSecurityHandler);
243+
assertThat(channelHandlerCtx).isNull();
244+
245+
// pipeline should have SslHandler and ClientTlsHandler
246+
Iterator<Map.Entry<String, ChannelHandler>> iterator = pipeline.iterator();
247+
assertThat(iterator.next().getValue()).isInstanceOf(SslHandler.class);
248+
// ProtocolNegotiators.ClientTlsHandler.class not accessible, get canonical name
249+
assertThat(iterator.next().getValue().getClass().getCanonicalName())
250+
.contains("ProtocolNegotiators.ClientTlsHandler");
251+
CommonCertProviderTestUtils.register0();
252+
}
200253

201254
@Test
202255
public void sniInClientSecurityHandler_autoHostSniIsTrue_usesEndpointHostname() {

0 commit comments

Comments
 (0)