diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/internal/QuotaProjectIdHidingCredentials.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/internal/QuotaProjectIdHidingCredentials.java index 51bbade9a0..8c9d2c5799 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/internal/QuotaProjectIdHidingCredentials.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/internal/QuotaProjectIdHidingCredentials.java @@ -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(); + } } diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/internal/QuotaProjectIdHidingCredentialsTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/internal/QuotaProjectIdHidingCredentialsTest.java index 9a02bd13dd..0d9d357115 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/internal/QuotaProjectIdHidingCredentialsTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/internal/QuotaProjectIdHidingCredentialsTest.java @@ -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"); + } } diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITEndpointContext.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITEndpointContext.java index abf3844a6f..55fdd350b8 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITEndpointContext.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITEndpointContext.java @@ -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"); + } }