@@ -88,6 +88,7 @@ public class SecurityProtocolNegotiatorsTest {
8888
8989 private static final String HOSTNAME = "hostname" ;
9090 private static final String SNI_IN_UTC = "sni-in-upstream-tls-context" ;
91+ private static final String FAKE_AUTHORITY = "authority" ;
9192
9293 private final GrpcHttp2ConnectionHandler grpcHandler =
9394 FakeGrpcHttp2ConnectionHandler .newHandler ();
@@ -269,6 +270,29 @@ public void sniInClientSecurityHandler_autoHostSniIsFalse_usesSniFromUpstreamTls
269270 assertThat (clientSecurityHandler .getSni ()).isEqualTo (SNI_IN_UTC );
270271 }
271272
273+ @ Test
274+ public void emptySni_useChannelAuthorityIfNoSniApplicableIsTrue_usesChannelAuthority () {
275+ SecurityProtocolNegotiators .useChannelAuthorityIfNoSniApplicable = true ;
276+ try {
277+ Bootstrapper .BootstrapInfo bootstrapInfoForClient = CommonBootstrapperTestUtils
278+ .buildBootstrapInfo ("google_cloud_private_spiffe-client" , CLIENT_KEY_FILE , CLIENT_PEM_FILE ,
279+ CA_PEM_FILE , null , null , null , null , null );
280+ UpstreamTlsContext upstreamTlsContext =
281+ CommonTlsContextTestsUtil
282+ .buildUpstreamTlsContext ("google_cloud_private_spiffe-client" , true , "" , false );
283+ SslContextProviderSupplier sslContextProviderSupplier =
284+ new SslContextProviderSupplier (upstreamTlsContext ,
285+ new TlsContextManagerImpl (bootstrapInfoForClient ));
286+
287+ ClientSecurityHandler clientSecurityHandler =
288+ new ClientSecurityHandler (grpcHandler , sslContextProviderSupplier , HOSTNAME );
289+
290+ assertThat (clientSecurityHandler .getSni ()).isEqualTo (FAKE_AUTHORITY );
291+ } finally {
292+ SecurityProtocolNegotiators .useChannelAuthorityIfNoSniApplicable = false ;
293+ }
294+ }
295+
272296 @ Test
273297 public void serverSecurityHandler_addLast ()
274298 throws InterruptedException , TimeoutException , ExecutionException {
@@ -533,7 +557,7 @@ static FakeGrpcHttp2ConnectionHandler newHandler() {
533557
534558 @ Override
535559 public String getAuthority () {
536- return "authority" ;
560+ return FAKE_AUTHORITY ;
537561 }
538562 }
539563}
0 commit comments