File tree Expand file tree Collapse file tree
main/java/com/google/api/gax/rpc
test/java/com/google/api/gax/rpc Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -272,9 +272,6 @@ private String determineUniverseDomain() {
272272
273273 /** Determines the fully resolved endpoint and universe domain values */
274274 private String determineEndpoint () throws IOException {
275- if (shouldUseS2A ()) {
276- return mtlsEndpoint ();
277- }
278275 MtlsProvider mtlsProvider = mtlsProvider () == null ? new MtlsProvider () : mtlsProvider ();
279276 // TransportChannelProvider's endpoint will override the ClientSettings' endpoint
280277 String customEndpoint =
@@ -312,6 +309,11 @@ private String determineEndpoint() throws IOException {
312309 /** Determine if S2A can be used */
313310 @ VisibleForTesting
314311 boolean shouldUseS2A () {
312+ // If mTLS endpoint is not available, skip S2A
313+ if (Strings .isNullOrEmpty (mtlsEndpoint ())) {
314+ return false ;
315+ }
316+
315317 // If EXPERIMENTAL_GOOGLE_API_USE_S2A is not set to true, skip S2A.
316318 String s2AEnv ;
317319 s2AEnv = envProvider ().getenv (S2A_ENV_ENABLE_USE_S2A );
Original file line number Diff line number Diff line change @@ -508,6 +508,20 @@ void shouldUseS2A_customEndpointSetViaTransportChannelProvider_returnsFalse() th
508508 Truth .assertThat (defaultEndpointContextBuilder .shouldUseS2A ()).isFalse ();
509509 }
510510
511+ @ Test
512+ void shouldUseS2A_mtlsEndpointNull_returnsFalse () throws IOException {
513+ EnvironmentProvider envProvider = Mockito .mock (EnvironmentProvider .class );
514+ Mockito .when (envProvider .getenv (EndpointContext .S2A_ENV_ENABLE_USE_S2A )).thenReturn ("true" );
515+ defaultEndpointContextBuilder =
516+ defaultEndpointContextBuilder
517+ .setEnvProvider (envProvider )
518+ .setClientSettingsEndpoint ("" )
519+ .setTransportChannelProviderEndpoint ("" )
520+ .setUsingGDCH (false )
521+ .setMtlsEndpoint (null );
522+ Truth .assertThat (defaultEndpointContextBuilder .shouldUseS2A ()).isFalse ();
523+ }
524+
511525 @ Test
512526 void shouldUseS2A_mtlsEndpointEmpty_returnsFalse () throws IOException {
513527 EnvironmentProvider envProvider = Mockito .mock (EnvironmentProvider .class );
You can’t perform that action at this time.
0 commit comments