Skip to content

Commit

Permalink
fix: address incorrect universe domain validation when quota project …
Browse files Browse the repository at this point in the history
…id is set (#3257)

Fixes #3256
  • Loading branch information
mpeddada1 authored Oct 2, 2024
1 parent 85401d4 commit 6e70c37
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,9 @@ public boolean hasRequestMetadataOnly() {
public void refresh() throws IOException {
this.wrappedCredentials.refresh();
}

@Override
public String getUniverseDomain() throws IOException {
return this.wrappedCredentials.getUniverseDomain();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,15 @@ void quotaProjectIdHidingCredentials_getAuthenticationType() throws IOException

Mockito.verify(credentials, Mockito.atLeastOnce()).refresh();
}

@Test
void quotaProjectIdHidingCredentials_getUniverseDomain() throws IOException {
Credentials credentials = Mockito.mock(GoogleCredentials.class);
Mockito.when(credentials.getUniverseDomain()).thenReturn("example.com");

QuotaProjectIdHidingCredentials quotaProjectIdHidingCredentials =
new QuotaProjectIdHidingCredentials(credentials);

assertEquals(quotaProjectIdHidingCredentials.getUniverseDomain(), "example.com");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -444,4 +444,23 @@ void endpointResolution_builderBuilderBackToBuilder() throws IOException {
echoStubSettingsBuilder = echoStubSettings.toBuilder();
Truth.assertThat(echoStubSettingsBuilder.getEndpoint()).isEqualTo(customEndpoint);
}

@Test
void universeDomainValidation_quotaProjectId_credentialsNonGDUMatchesUserConfiguration()
throws IOException {
String universeDomain = "random.com";
EchoSettings echoSettings =
ExtendedEchoSettings.newBuilder()
.setQuotaProjectId("exampleProject")
.setCredentialsProvider(UniverseDomainCredentialsProvider.create(universeDomain))
.setEndpoint(TestClientInitializer.DEFAULT_GRPC_ENDPOINT)
.setUniverseDomain(universeDomain)
.setTransportChannelProvider(
EchoSettings.defaultGrpcTransportProviderBuilder()
.setChannelConfigurator(ManagedChannelBuilder::usePlaintext)
.build())
.build();
echoClient = EchoClient.create(echoSettings);
Truth.assertThat(echoClient.echo(DEFAULT_REQUEST).getContent()).isEqualTo("echo");
}
}

0 comments on commit 6e70c37

Please sign in to comment.