Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
rmehta19 committed Jan 7, 2025
1 parent 3d99673 commit 39380c5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,6 @@ private String determineUniverseDomain() {

/** Determines the fully resolved endpoint and universe domain values */
private String determineEndpoint() throws IOException {
if (shouldUseS2A()) {
return mtlsEndpoint();
}
MtlsProvider mtlsProvider = mtlsProvider() == null ? new MtlsProvider() : mtlsProvider();
// TransportChannelProvider's endpoint will override the ClientSettings' endpoint
String customEndpoint =
Expand Down Expand Up @@ -312,6 +309,11 @@ private String determineEndpoint() throws IOException {
/** Determine if S2A can be used */
@VisibleForTesting
boolean shouldUseS2A() {
// If mTLS endpoint is not available, skip S2A
if (Strings.isNullOrEmpty(mtlsEndpoint())) {
return false;
}

// If EXPERIMENTAL_GOOGLE_API_USE_S2A is not set to true, skip S2A.
String s2AEnv;
s2AEnv = envProvider().getenv(S2A_ENV_ENABLE_USE_S2A);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,20 @@ void shouldUseS2A_customEndpointSetViaTransportChannelProvider_returnsFalse() th
Truth.assertThat(defaultEndpointContextBuilder.shouldUseS2A()).isFalse();
}

@Test
void shouldUseS2A_mtlsEndpointNull_returnsFalse() throws IOException {
EnvironmentProvider envProvider = Mockito.mock(EnvironmentProvider.class);
Mockito.when(envProvider.getenv(EndpointContext.S2A_ENV_ENABLE_USE_S2A)).thenReturn("false");
defaultEndpointContextBuilder =
defaultEndpointContextBuilder
.setEnvProvider(envProvider)
.setClientSettingsEndpoint("")
.setTransportChannelProviderEndpoint("")
.setUsingGDCH(false)
.setMtlsEndpoint(null);
Truth.assertThat(defaultEndpointContextBuilder.shouldUseS2A()).isFalse();
}

@Test
void shouldUseS2A_mtlsEndpointEmpty_returnsFalse() throws IOException {
EnvironmentProvider envProvider = Mockito.mock(EnvironmentProvider.class);
Expand Down

0 comments on commit 39380c5

Please sign in to comment.