From dae89794b393bc88f7c5517836df1760bd2bbea3 Mon Sep 17 00:00:00 2001 From: Joe Wang Date: Fri, 23 Jan 2026 12:20:03 -0500 Subject: [PATCH 01/11] deps: update auth library to 1.42.0 --- gapic-generator-java-pom-parent/pom.xml | 2 +- gax-java/dependencies.properties | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gapic-generator-java-pom-parent/pom.xml b/gapic-generator-java-pom-parent/pom.xml index e4ffc27e58..4e3c7102b9 100644 --- a/gapic-generator-java-pom-parent/pom.xml +++ b/gapic-generator-java-pom-parent/pom.xml @@ -28,7 +28,7 @@ consistent across modules in this repository --> 1.3.2 1.76.2 - 1.41.0 + 1.42.0 2.0.3 2.12.1 33.5.0-jre diff --git a/gax-java/dependencies.properties b/gax-java/dependencies.properties index 949aabd71f..47dc4f51e9 100644 --- a/gax-java/dependencies.properties +++ b/gax-java/dependencies.properties @@ -37,8 +37,8 @@ version.io_grpc=1.76.2 # 2) Replace all characters which are neither alphabetic nor digits with the underscore ('_') character maven.com_google_api_grpc_proto_google_common_protos=com.google.api.grpc:proto-google-common-protos:2.63.2 maven.com_google_api_grpc_grpc_google_common_protos=com.google.api.grpc:grpc-google-common-protos:2.63.2 -maven.com_google_auth_google_auth_library_oauth2_http=com.google.auth:google-auth-library-oauth2-http:1.41.0 -maven.com_google_auth_google_auth_library_credentials=com.google.auth:google-auth-library-credentials:1.41.0 +maven.com_google_auth_google_auth_library_oauth2_http=com.google.auth:google-auth-library-oauth2-http:1.42.0 +maven.com_google_auth_google_auth_library_credentials=com.google.auth:google-auth-library-credentials:1.42.0 maven.io_opentelemetry_opentelemetry_api=io.opentelemetry:opentelemetry-api:1.47.0 maven.io_opencensus_opencensus_api=io.opencensus:opencensus-api:0.31.1 maven.io_opencensus_opencensus_contrib_grpc_metrics=io.opencensus:opencensus-contrib-grpc-metrics:0.31.1 From 913ce71bc25bc9209250d65585cd7508d0b9d7ec Mon Sep 17 00:00:00 2001 From: Joe Wang Date: Fri, 23 Jan 2026 13:25:18 -0500 Subject: [PATCH 02/11] disable failed tests --- .../src/test/java/com/google/showcase/v1beta1/it/ITGdch.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/java-showcase-3.21.0/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITGdch.java b/java-showcase-3.21.0/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITGdch.java index f043d45cfc..6b783215db 100644 --- a/java-showcase-3.21.0/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITGdch.java +++ b/java-showcase-3.21.0/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITGdch.java @@ -47,6 +47,7 @@ import java.util.concurrent.TimeUnit; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; @@ -130,6 +131,7 @@ private void prepareCredentials(Path tempDir) throws IOException { * @throws IOException */ @Test + @Disabled void testCreateClient_withGdchCredentialAndNoAudience_defaultsToEndpointBasedAudience() throws IOException { @@ -175,6 +177,7 @@ void testCreateClient_withGdchCredentialAndNoAudience_defaultsToEndpointBasedAud * @throws IOException */ @Test + @Disabled void testCreateClient_withGdchCredentialWithValidAudience_usesCredentialWithPassedAudience() throws IOException { From 679bfc5568354ff8d7c9b088426fe2818787da39 Mon Sep 17 00:00:00 2001 From: Joe Wang Date: Fri, 23 Jan 2026 13:31:05 -0500 Subject: [PATCH 03/11] disable test class --- .../src/test/java/com/google/showcase/v1beta1/it/ITGdch.java | 1 + 1 file changed, 1 insertion(+) diff --git a/java-showcase-3.21.0/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITGdch.java b/java-showcase-3.21.0/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITGdch.java index 6b783215db..55f442e7ef 100644 --- a/java-showcase-3.21.0/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITGdch.java +++ b/java-showcase-3.21.0/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITGdch.java @@ -55,6 +55,7 @@ * Test suite to confirm a client can be instantiated with GDCH credentials. No calls are made since * it is not feasible to test against real GDCH servers (or replicate an environment) */ +@Disabled class ITGdch { private static final String CA_CERT_FILENAME = "fake_cert.pem"; From f35e893066bb4c7973c2affa52379d6f0a911948 Mon Sep 17 00:00:00 2001 From: Joe Wang Date: Fri, 23 Jan 2026 13:54:22 -0500 Subject: [PATCH 04/11] comment out test class --- .../google/showcase/v1beta1/it/ITGdch.java | 453 +++++++++--------- 1 file changed, 225 insertions(+), 228 deletions(-) diff --git a/java-showcase-3.21.0/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITGdch.java b/java-showcase-3.21.0/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITGdch.java index 55f442e7ef..cf0e5427c0 100644 --- a/java-showcase-3.21.0/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITGdch.java +++ b/java-showcase-3.21.0/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITGdch.java @@ -1,228 +1,225 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.showcase.v1beta1.it; - -import static com.google.common.truth.Truth.assertThat; -import static com.google.common.truth.Truth.assertWithMessage; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotSame; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import com.google.api.client.json.GenericJson; -import com.google.api.client.json.JsonFactory; -import com.google.api.client.json.gson.GsonFactory; -import com.google.api.gax.core.FixedCredentialsProvider; -import com.google.api.gax.rpc.ClientContext; -import com.google.auth.Credentials; -import com.google.auth.oauth2.GdchCredentials; -import com.google.auth.oauth2.GdchCredentialsTestUtil; -import com.google.showcase.v1beta1.EchoClient; -import com.google.showcase.v1beta1.EchoSettings; -import com.google.showcase.v1beta1.it.util.InterceptingMockTokenServerTransportFactory; -import com.google.showcase.v1beta1.it.util.TestClientInitializer; -import com.google.showcase.v1beta1.stub.EchoStubSettings; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.StandardCopyOption; -import java.util.concurrent.TimeUnit; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.io.TempDir; - -/** - * Test suite to confirm a client can be instantiated with GDCH credentials. No calls are made since - * it is not feasible to test against real GDCH servers (or replicate an environment) - */ -@Disabled -class ITGdch { - - private static final String CA_CERT_FILENAME = "fake_cert.pem"; - private static final String CA_CERT_RESOURCE_PATH = "/" + CA_CERT_FILENAME; - private static final String CA_CERT_JSON_KEY = "ca_cert_path"; - private static final String GDCH_CREDENTIAL_FILENAME = "test_gdch_credential.json"; - private static final String GDCH_CREDENTIAL_RESOURCE_PATH = "/" + GDCH_CREDENTIAL_FILENAME; - private static final String GDCH_TOKEN_STRING = "1/MkSJoj1xsli0AccessToken_NKPY2"; - private static final String SID_NAME = "service-identity-name"; - - private EchoClient client; - private EchoSettings settings; - private EchoStubSettings stubSettings; - private Credentials initialCredentials; - private ClientContext context; - private InterceptingMockTokenServerTransportFactory transportFactory; - private String projectId; - private URI tokenUri; - - @BeforeEach - void setup(@TempDir Path tempDir) throws IOException { - transportFactory = new InterceptingMockTokenServerTransportFactory(); - prepareCredentials(tempDir); - settings = - EchoSettings.newBuilder() - .setCredentialsProvider(FixedCredentialsProvider.create(initialCredentials)) - .build(); - } - - @AfterEach - void tearDown() throws InterruptedException { - if (client != null) { - client.close(); - client.awaitTermination(TestClientInitializer.AWAIT_TERMINATION_SECONDS, TimeUnit.SECONDS); - } - } - - private void prepareCredentials(Path tempDir) throws IOException { - // Copy file so it can be referenced by Path even in native-image builds - File caCertFile = new File(tempDir.toFile(), CA_CERT_FILENAME); - try (InputStream inputStream = getClass().getResourceAsStream(CA_CERT_RESOURCE_PATH)) { - assertThat(inputStream).isNotNull(); - Files.copy(inputStream, caCertFile.toPath(), StandardCopyOption.REPLACE_EXISTING); - } - assertWithMessage(caCertFile.toPath() + " should exist").that(caCertFile.exists()).isTrue(); - - // open gdch credential json (still needs its "ca_cert_path" to point to the CA certificate - // obtained from above) - JsonFactory factory = new GsonFactory(); - GenericJson converted = - factory.fromInputStream( - getClass().getResourceAsStream(GDCH_CREDENTIAL_RESOURCE_PATH), GenericJson.class); - - // modify and save to a temporary folder - converted.set(CA_CERT_JSON_KEY, caCertFile.toPath().toAbsolutePath().toString()); - projectId = converted.get("project").toString(); - tokenUri = URI.create(converted.get("token_uri").toString()); - - File tempGdchCredentialFile = new File(tempDir.toFile(), GDCH_CREDENTIAL_FILENAME); - try (FileWriter fileWriter = new FileWriter(tempGdchCredentialFile)) { - String preparedJson = converted.toPrettyString(); - fileWriter.write(preparedJson); - } - - // use temp location to instantiate credentials - initialCredentials = GdchCredentialsTestUtil.fromJson(converted, transportFactory); - } - - /** - * {@link com.google.api.gax.rpc.ClientContext} will create a new {@link GdchCredentials} with an - * audience defaulted to the endpoint if the audience is not manually passed. This test confirms - * that a new credential is created from the context and can be refreshed - * - * @throws IOException - */ - @Test - @Disabled - void testCreateClient_withGdchCredentialAndNoAudience_defaultsToEndpointBasedAudience() - throws IOException { - - // we create the client as usual - no audience passed - String testEndpoint = "custom-endpoint:123"; - settings = settings.toBuilder().setEndpoint(testEndpoint).build(); - context = ClientContext.create(settings); - stubSettings = EchoStubSettings.newBuilder(context).build(); - client = EchoClient.create(stubSettings.createStub()); - - // We retrieve from context and from client - // the client has only access to creds provider, which may differ from the actual credentials - // used in the Context - Credentials fromContext = context.getCredentials(); - Credentials fromClient = initialCredentials; - - // Since ClientContext.create() uses a modified version of GdchCredentials - // via GdchCredentials.createWithGdchAudience(), they should be different objects - assertNotSame(fromContext, fromClient); - - // When credentials don't have an audience (such as the ones we passed to client creation and - // now stored in the - // provider) they will throw if we try to refresh them - NullPointerException expectedEx = - assertThrows(NullPointerException.class, () -> initialCredentials.refresh()); - assertTrue( - expectedEx.getMessage().contains("Audience are not configured for GDCH service account")); - - // However, the credentials prepared in ClientContext should be able to refresh since the - // audience would be - // internally defaulted the endpoint of the StubSettings - registerCredential(fromContext); - ((GdchCredentials) fromContext).refreshAccessToken(); - String usedAudience = transportFactory.transport.getLastAudienceSent(); - assertEquals(testEndpoint, usedAudience); - } - - /** - * Confirms creating a client with a valid audience is successful. We cannot confirm which - * audience is chosen (our passed audience or the endpoint) but this is confirmed in the unit - * tests. - * - * @throws IOException - */ - @Test - @Disabled - void testCreateClient_withGdchCredentialWithValidAudience_usesCredentialWithPassedAudience() - throws IOException { - - // Similar to the previous test, create a client as usual but this time we pass a explicit - // audience. It should - // be created without issues - String testAudience = "valid-audience"; - settings = - settings.toBuilder().setGdchApiAudience(testAudience).setEndpoint("localhost:7469").build(); - context = ClientContext.create(settings); - stubSettings = EchoStubSettings.newBuilder(context).build(); - client = EchoClient.create(stubSettings.createStub()); - - // We retrieve both creds from the creds provider and the ones prepared in the context (which - // should have been - // re-created using GdchCredentials.createWithAudience("valid-audience")) - Credentials fromContext = context.getCredentials(); - assertNotSame(fromContext, initialCredentials); - - // Again, since the initial credentials don't have an audience, we should not be able to refresh - // them - NullPointerException thrownByClientCreds = - assertThrows(NullPointerException.class, () -> initialCredentials.refresh()); - assertTrue( - thrownByClientCreds - .getMessage() - .contains("Audience are not configured for GDCH service account")); - - // But the credentials prepared in ClientContext should be able to refresh since the audience - // would be internally - // set to the one passed in stub settings - registerCredential(fromContext); - ((GdchCredentials) fromContext).refreshAccessToken(); - String usedAudience = transportFactory.transport.getLastAudienceSent(); - assertEquals(testAudience, usedAudience); - } - - private void registerCredential(Credentials fromContext) { - GdchCredentialsTestUtil.registerGdchCredentialWithMockTransport( - (GdchCredentials) fromContext, - transportFactory.transport, - projectId, - SID_NAME, - GDCH_TOKEN_STRING, - tokenUri); - } -} +///* +// * Copyright 2023 Google LLC +// * +// * Licensed under the Apache License, Version 2.0 (the "License"); +// * you may not use this file except in compliance with the License. +// * You may obtain a copy of the License at +// * +// * https://www.apache.org/licenses/LICENSE-2.0 +// * +// * Unless required by applicable law or agreed to in writing, software +// * distributed under the License is distributed on an "AS IS" BASIS, +// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// * See the License for the specific language governing permissions and +// * limitations under the License. +// */ +// +//package com.google.showcase.v1beta1.it; +// +//import static com.google.common.truth.Truth.assertThat; +//import static com.google.common.truth.Truth.assertWithMessage; +//import static org.junit.jupiter.api.Assertions.assertEquals; +//import static org.junit.jupiter.api.Assertions.assertNotSame; +//import static org.junit.jupiter.api.Assertions.assertThrows; +//import static org.junit.jupiter.api.Assertions.assertTrue; +// +//import com.google.api.client.json.GenericJson; +//import com.google.api.client.json.JsonFactory; +//import com.google.api.client.json.gson.GsonFactory; +//import com.google.api.gax.core.FixedCredentialsProvider; +//import com.google.api.gax.rpc.ClientContext; +//import com.google.auth.Credentials; +//import com.google.auth.oauth2.GdchCredentials; +//import com.google.auth.oauth2.GdchCredentialsTestUtil; +//import com.google.showcase.v1beta1.EchoClient; +//import com.google.showcase.v1beta1.EchoSettings; +//import com.google.showcase.v1beta1.it.util.InterceptingMockTokenServerTransportFactory; +//import com.google.showcase.v1beta1.it.util.TestClientInitializer; +//import com.google.showcase.v1beta1.stub.EchoStubSettings; +//import java.io.File; +//import java.io.FileWriter; +//import java.io.IOException; +//import java.io.InputStream; +//import java.net.URI; +//import java.nio.file.Files; +//import java.nio.file.Path; +//import java.nio.file.StandardCopyOption; +//import java.util.concurrent.TimeUnit; +//import org.junit.jupiter.api.AfterEach; +//import org.junit.jupiter.api.BeforeEach; +//import org.junit.jupiter.api.Disabled; +//import org.junit.jupiter.api.Test; +//import org.junit.jupiter.api.io.TempDir; +// +///** +// * Test suite to confirm a client can be instantiated with GDCH credentials. No calls are made since +// * it is not feasible to test against real GDCH servers (or replicate an environment) +// */ +//class ITGdch { +// +// private static final String CA_CERT_FILENAME = "fake_cert.pem"; +// private static final String CA_CERT_RESOURCE_PATH = "/" + CA_CERT_FILENAME; +// private static final String CA_CERT_JSON_KEY = "ca_cert_path"; +// private static final String GDCH_CREDENTIAL_FILENAME = "test_gdch_credential.json"; +// private static final String GDCH_CREDENTIAL_RESOURCE_PATH = "/" + GDCH_CREDENTIAL_FILENAME; +// private static final String GDCH_TOKEN_STRING = "1/MkSJoj1xsli0AccessToken_NKPY2"; +// private static final String SID_NAME = "service-identity-name"; +// +// private EchoClient client; +// private EchoSettings settings; +// private EchoStubSettings stubSettings; +// private Credentials initialCredentials; +// private ClientContext context; +// private InterceptingMockTokenServerTransportFactory transportFactory; +// private String projectId; +// private URI tokenUri; +// +// @BeforeEach +// void setup(@TempDir Path tempDir) throws IOException { +// transportFactory = new InterceptingMockTokenServerTransportFactory(); +// prepareCredentials(tempDir); +// settings = +// EchoSettings.newBuilder() +// .setCredentialsProvider(FixedCredentialsProvider.create(initialCredentials)) +// .build(); +// } +// +// @AfterEach +// void tearDown() throws InterruptedException { +// if (client != null) { +// client.close(); +// client.awaitTermination(TestClientInitializer.AWAIT_TERMINATION_SECONDS, TimeUnit.SECONDS); +// } +// } +// +// private void prepareCredentials(Path tempDir) throws IOException { +// // Copy file so it can be referenced by Path even in native-image builds +// File caCertFile = new File(tempDir.toFile(), CA_CERT_FILENAME); +// try (InputStream inputStream = getClass().getResourceAsStream(CA_CERT_RESOURCE_PATH)) { +// assertThat(inputStream).isNotNull(); +// Files.copy(inputStream, caCertFile.toPath(), StandardCopyOption.REPLACE_EXISTING); +// } +// assertWithMessage(caCertFile.toPath() + " should exist").that(caCertFile.exists()).isTrue(); +// +// // open gdch credential json (still needs its "ca_cert_path" to point to the CA certificate +// // obtained from above) +// JsonFactory factory = new GsonFactory(); +// GenericJson converted = +// factory.fromInputStream( +// getClass().getResourceAsStream(GDCH_CREDENTIAL_RESOURCE_PATH), GenericJson.class); +// +// // modify and save to a temporary folder +// converted.set(CA_CERT_JSON_KEY, caCertFile.toPath().toAbsolutePath().toString()); +// projectId = converted.get("project").toString(); +// tokenUri = URI.create(converted.get("token_uri").toString()); +// +// File tempGdchCredentialFile = new File(tempDir.toFile(), GDCH_CREDENTIAL_FILENAME); +// try (FileWriter fileWriter = new FileWriter(tempGdchCredentialFile)) { +// String preparedJson = converted.toPrettyString(); +// fileWriter.write(preparedJson); +// } +// +// // use temp location to instantiate credentials +// initialCredentials = GdchCredentialsTestUtil.fromJson(converted, transportFactory); +// } +// +// /** +// * {@link com.google.api.gax.rpc.ClientContext} will create a new {@link GdchCredentials} with an +// * audience defaulted to the endpoint if the audience is not manually passed. This test confirms +// * that a new credential is created from the context and can be refreshed +// * +// * @throws IOException +// */ +// @Test +// void testCreateClient_withGdchCredentialAndNoAudience_defaultsToEndpointBasedAudience() +// throws IOException { +// +// // we create the client as usual - no audience passed +// String testEndpoint = "custom-endpoint:123"; +// settings = settings.toBuilder().setEndpoint(testEndpoint).build(); +// context = ClientContext.create(settings); +// stubSettings = EchoStubSettings.newBuilder(context).build(); +// client = EchoClient.create(stubSettings.createStub()); +// +// // We retrieve from context and from client +// // the client has only access to creds provider, which may differ from the actual credentials +// // used in the Context +// Credentials fromContext = context.getCredentials(); +// Credentials fromClient = initialCredentials; +// +// // Since ClientContext.create() uses a modified version of GdchCredentials +// // via GdchCredentials.createWithGdchAudience(), they should be different objects +// assertNotSame(fromContext, fromClient); +// +// // When credentials don't have an audience (such as the ones we passed to client creation and +// // now stored in the +// // provider) they will throw if we try to refresh them +// NullPointerException expectedEx = +// assertThrows(NullPointerException.class, () -> initialCredentials.refresh()); +// assertTrue( +// expectedEx.getMessage().contains("Audience are not configured for GDCH service account")); +// +// // However, the credentials prepared in ClientContext should be able to refresh since the +// // audience would be +// // internally defaulted the endpoint of the StubSettings +// registerCredential(fromContext); +// ((GdchCredentials) fromContext).refreshAccessToken(); +// String usedAudience = transportFactory.transport.getLastAudienceSent(); +// assertEquals(testEndpoint, usedAudience); +// } +// +// /** +// * Confirms creating a client with a valid audience is successful. We cannot confirm which +// * audience is chosen (our passed audience or the endpoint) but this is confirmed in the unit +// * tests. +// * +// * @throws IOException +// */ +// @Test +// void testCreateClient_withGdchCredentialWithValidAudience_usesCredentialWithPassedAudience() +// throws IOException { +// +// // Similar to the previous test, create a client as usual but this time we pass a explicit +// // audience. It should +// // be created without issues +// String testAudience = "valid-audience"; +// settings = +// settings.toBuilder().setGdchApiAudience(testAudience).setEndpoint("localhost:7469").build(); +// context = ClientContext.create(settings); +// stubSettings = EchoStubSettings.newBuilder(context).build(); +// client = EchoClient.create(stubSettings.createStub()); +// +// // We retrieve both creds from the creds provider and the ones prepared in the context (which +// // should have been +// // re-created using GdchCredentials.createWithAudience("valid-audience")) +// Credentials fromContext = context.getCredentials(); +// assertNotSame(fromContext, initialCredentials); +// +// // Again, since the initial credentials don't have an audience, we should not be able to refresh +// // them +// NullPointerException thrownByClientCreds = +// assertThrows(NullPointerException.class, () -> initialCredentials.refresh()); +// assertTrue( +// thrownByClientCreds +// .getMessage() +// .contains("Audience are not configured for GDCH service account")); +// +// // But the credentials prepared in ClientContext should be able to refresh since the audience +// // would be internally +// // set to the one passed in stub settings +// registerCredential(fromContext); +// ((GdchCredentials) fromContext).refreshAccessToken(); +// String usedAudience = transportFactory.transport.getLastAudienceSent(); +// assertEquals(testAudience, usedAudience); +// } +// +// private void registerCredential(Credentials fromContext) { +// GdchCredentialsTestUtil.registerGdchCredentialWithMockTransport( +// (GdchCredentials) fromContext, +// transportFactory.transport, +// projectId, +// SID_NAME, +// GDCH_TOKEN_STRING, +// tokenUri); +// } +//} From 8af127c7ed6375e4bbe824c075502ea05fc0ab67 Mon Sep 17 00:00:00 2001 From: Joe Wang Date: Fri, 23 Jan 2026 13:59:48 -0500 Subject: [PATCH 05/11] comment out test class --- .../google/showcase/v1beta1/it/ITGdch.java | 448 +++++++++--------- 1 file changed, 224 insertions(+), 224 deletions(-) diff --git a/java-showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITGdch.java b/java-showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITGdch.java index f043d45cfc..2c722212b7 100644 --- a/java-showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITGdch.java +++ b/java-showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITGdch.java @@ -1,224 +1,224 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.showcase.v1beta1.it; - -import static com.google.common.truth.Truth.assertThat; -import static com.google.common.truth.Truth.assertWithMessage; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotSame; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import com.google.api.client.json.GenericJson; -import com.google.api.client.json.JsonFactory; -import com.google.api.client.json.gson.GsonFactory; -import com.google.api.gax.core.FixedCredentialsProvider; -import com.google.api.gax.rpc.ClientContext; -import com.google.auth.Credentials; -import com.google.auth.oauth2.GdchCredentials; -import com.google.auth.oauth2.GdchCredentialsTestUtil; -import com.google.showcase.v1beta1.EchoClient; -import com.google.showcase.v1beta1.EchoSettings; -import com.google.showcase.v1beta1.it.util.InterceptingMockTokenServerTransportFactory; -import com.google.showcase.v1beta1.it.util.TestClientInitializer; -import com.google.showcase.v1beta1.stub.EchoStubSettings; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.StandardCopyOption; -import java.util.concurrent.TimeUnit; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.io.TempDir; - -/** - * Test suite to confirm a client can be instantiated with GDCH credentials. No calls are made since - * it is not feasible to test against real GDCH servers (or replicate an environment) - */ -class ITGdch { - - private static final String CA_CERT_FILENAME = "fake_cert.pem"; - private static final String CA_CERT_RESOURCE_PATH = "/" + CA_CERT_FILENAME; - private static final String CA_CERT_JSON_KEY = "ca_cert_path"; - private static final String GDCH_CREDENTIAL_FILENAME = "test_gdch_credential.json"; - private static final String GDCH_CREDENTIAL_RESOURCE_PATH = "/" + GDCH_CREDENTIAL_FILENAME; - private static final String GDCH_TOKEN_STRING = "1/MkSJoj1xsli0AccessToken_NKPY2"; - private static final String SID_NAME = "service-identity-name"; - - private EchoClient client; - private EchoSettings settings; - private EchoStubSettings stubSettings; - private Credentials initialCredentials; - private ClientContext context; - private InterceptingMockTokenServerTransportFactory transportFactory; - private String projectId; - private URI tokenUri; - - @BeforeEach - void setup(@TempDir Path tempDir) throws IOException { - transportFactory = new InterceptingMockTokenServerTransportFactory(); - prepareCredentials(tempDir); - settings = - EchoSettings.newBuilder() - .setCredentialsProvider(FixedCredentialsProvider.create(initialCredentials)) - .build(); - } - - @AfterEach - void tearDown() throws InterruptedException { - if (client != null) { - client.close(); - client.awaitTermination(TestClientInitializer.AWAIT_TERMINATION_SECONDS, TimeUnit.SECONDS); - } - } - - private void prepareCredentials(Path tempDir) throws IOException { - // Copy file so it can be referenced by Path even in native-image builds - File caCertFile = new File(tempDir.toFile(), CA_CERT_FILENAME); - try (InputStream inputStream = getClass().getResourceAsStream(CA_CERT_RESOURCE_PATH)) { - assertThat(inputStream).isNotNull(); - Files.copy(inputStream, caCertFile.toPath(), StandardCopyOption.REPLACE_EXISTING); - } - assertWithMessage(caCertFile.toPath() + " should exist").that(caCertFile.exists()).isTrue(); - - // open gdch credential json (still needs its "ca_cert_path" to point to the CA certificate - // obtained from above) - JsonFactory factory = new GsonFactory(); - GenericJson converted = - factory.fromInputStream( - getClass().getResourceAsStream(GDCH_CREDENTIAL_RESOURCE_PATH), GenericJson.class); - - // modify and save to a temporary folder - converted.set(CA_CERT_JSON_KEY, caCertFile.toPath().toAbsolutePath().toString()); - projectId = converted.get("project").toString(); - tokenUri = URI.create(converted.get("token_uri").toString()); - - File tempGdchCredentialFile = new File(tempDir.toFile(), GDCH_CREDENTIAL_FILENAME); - try (FileWriter fileWriter = new FileWriter(tempGdchCredentialFile)) { - String preparedJson = converted.toPrettyString(); - fileWriter.write(preparedJson); - } - - // use temp location to instantiate credentials - initialCredentials = GdchCredentialsTestUtil.fromJson(converted, transportFactory); - } - - /** - * {@link com.google.api.gax.rpc.ClientContext} will create a new {@link GdchCredentials} with an - * audience defaulted to the endpoint if the audience is not manually passed. This test confirms - * that a new credential is created from the context and can be refreshed - * - * @throws IOException - */ - @Test - void testCreateClient_withGdchCredentialAndNoAudience_defaultsToEndpointBasedAudience() - throws IOException { - - // we create the client as usual - no audience passed - String testEndpoint = "custom-endpoint:123"; - settings = settings.toBuilder().setEndpoint(testEndpoint).build(); - context = ClientContext.create(settings); - stubSettings = EchoStubSettings.newBuilder(context).build(); - client = EchoClient.create(stubSettings.createStub()); - - // We retrieve from context and from client - // the client has only access to creds provider, which may differ from the actual credentials - // used in the Context - Credentials fromContext = context.getCredentials(); - Credentials fromClient = initialCredentials; - - // Since ClientContext.create() uses a modified version of GdchCredentials - // via GdchCredentials.createWithGdchAudience(), they should be different objects - assertNotSame(fromContext, fromClient); - - // When credentials don't have an audience (such as the ones we passed to client creation and - // now stored in the - // provider) they will throw if we try to refresh them - NullPointerException expectedEx = - assertThrows(NullPointerException.class, () -> initialCredentials.refresh()); - assertTrue( - expectedEx.getMessage().contains("Audience are not configured for GDCH service account")); - - // However, the credentials prepared in ClientContext should be able to refresh since the - // audience would be - // internally defaulted the endpoint of the StubSettings - registerCredential(fromContext); - ((GdchCredentials) fromContext).refreshAccessToken(); - String usedAudience = transportFactory.transport.getLastAudienceSent(); - assertEquals(testEndpoint, usedAudience); - } - - /** - * Confirms creating a client with a valid audience is successful. We cannot confirm which - * audience is chosen (our passed audience or the endpoint) but this is confirmed in the unit - * tests. - * - * @throws IOException - */ - @Test - void testCreateClient_withGdchCredentialWithValidAudience_usesCredentialWithPassedAudience() - throws IOException { - - // Similar to the previous test, create a client as usual but this time we pass a explicit - // audience. It should - // be created without issues - String testAudience = "valid-audience"; - settings = - settings.toBuilder().setGdchApiAudience(testAudience).setEndpoint("localhost:7469").build(); - context = ClientContext.create(settings); - stubSettings = EchoStubSettings.newBuilder(context).build(); - client = EchoClient.create(stubSettings.createStub()); - - // We retrieve both creds from the creds provider and the ones prepared in the context (which - // should have been - // re-created using GdchCredentials.createWithAudience("valid-audience")) - Credentials fromContext = context.getCredentials(); - assertNotSame(fromContext, initialCredentials); - - // Again, since the initial credentials don't have an audience, we should not be able to refresh - // them - NullPointerException thrownByClientCreds = - assertThrows(NullPointerException.class, () -> initialCredentials.refresh()); - assertTrue( - thrownByClientCreds - .getMessage() - .contains("Audience are not configured for GDCH service account")); - - // But the credentials prepared in ClientContext should be able to refresh since the audience - // would be internally - // set to the one passed in stub settings - registerCredential(fromContext); - ((GdchCredentials) fromContext).refreshAccessToken(); - String usedAudience = transportFactory.transport.getLastAudienceSent(); - assertEquals(testAudience, usedAudience); - } - - private void registerCredential(Credentials fromContext) { - GdchCredentialsTestUtil.registerGdchCredentialWithMockTransport( - (GdchCredentials) fromContext, - transportFactory.transport, - projectId, - SID_NAME, - GDCH_TOKEN_STRING, - tokenUri); - } -} +///* +// * Copyright 2023 Google LLC +// * +// * Licensed under the Apache License, Version 2.0 (the "License"); +// * you may not use this file except in compliance with the License. +// * You may obtain a copy of the License at +// * +// * https://www.apache.org/licenses/LICENSE-2.0 +// * +// * Unless required by applicable law or agreed to in writing, software +// * distributed under the License is distributed on an "AS IS" BASIS, +// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// * See the License for the specific language governing permissions and +// * limitations under the License. +// */ +// +//package com.google.showcase.v1beta1.it; +// +//import static com.google.common.truth.Truth.assertThat; +//import static com.google.common.truth.Truth.assertWithMessage; +//import static org.junit.jupiter.api.Assertions.assertEquals; +//import static org.junit.jupiter.api.Assertions.assertNotSame; +//import static org.junit.jupiter.api.Assertions.assertThrows; +//import static org.junit.jupiter.api.Assertions.assertTrue; +// +//import com.google.api.client.json.GenericJson; +//import com.google.api.client.json.JsonFactory; +//import com.google.api.client.json.gson.GsonFactory; +//import com.google.api.gax.core.FixedCredentialsProvider; +//import com.google.api.gax.rpc.ClientContext; +//import com.google.auth.Credentials; +//import com.google.auth.oauth2.GdchCredentials; +//import com.google.auth.oauth2.GdchCredentialsTestUtil; +//import com.google.showcase.v1beta1.EchoClient; +//import com.google.showcase.v1beta1.EchoSettings; +//import com.google.showcase.v1beta1.it.util.InterceptingMockTokenServerTransportFactory; +//import com.google.showcase.v1beta1.it.util.TestClientInitializer; +//import com.google.showcase.v1beta1.stub.EchoStubSettings; +//import java.io.File; +//import java.io.FileWriter; +//import java.io.IOException; +//import java.io.InputStream; +//import java.net.URI; +//import java.nio.file.Files; +//import java.nio.file.Path; +//import java.nio.file.StandardCopyOption; +//import java.util.concurrent.TimeUnit; +//import org.junit.jupiter.api.AfterEach; +//import org.junit.jupiter.api.BeforeEach; +//import org.junit.jupiter.api.Test; +//import org.junit.jupiter.api.io.TempDir; +// +///** +// * Test suite to confirm a client can be instantiated with GDCH credentials. No calls are made since +// * it is not feasible to test against real GDCH servers (or replicate an environment) +// */ +//class ITGdch { +// +// private static final String CA_CERT_FILENAME = "fake_cert.pem"; +// private static final String CA_CERT_RESOURCE_PATH = "/" + CA_CERT_FILENAME; +// private static final String CA_CERT_JSON_KEY = "ca_cert_path"; +// private static final String GDCH_CREDENTIAL_FILENAME = "test_gdch_credential.json"; +// private static final String GDCH_CREDENTIAL_RESOURCE_PATH = "/" + GDCH_CREDENTIAL_FILENAME; +// private static final String GDCH_TOKEN_STRING = "1/MkSJoj1xsli0AccessToken_NKPY2"; +// private static final String SID_NAME = "service-identity-name"; +// +// private EchoClient client; +// private EchoSettings settings; +// private EchoStubSettings stubSettings; +// private Credentials initialCredentials; +// private ClientContext context; +// private InterceptingMockTokenServerTransportFactory transportFactory; +// private String projectId; +// private URI tokenUri; +// +// @BeforeEach +// void setup(@TempDir Path tempDir) throws IOException { +// transportFactory = new InterceptingMockTokenServerTransportFactory(); +// prepareCredentials(tempDir); +// settings = +// EchoSettings.newBuilder() +// .setCredentialsProvider(FixedCredentialsProvider.create(initialCredentials)) +// .build(); +// } +// +// @AfterEach +// void tearDown() throws InterruptedException { +// if (client != null) { +// client.close(); +// client.awaitTermination(TestClientInitializer.AWAIT_TERMINATION_SECONDS, TimeUnit.SECONDS); +// } +// } +// +// private void prepareCredentials(Path tempDir) throws IOException { +// // Copy file so it can be referenced by Path even in native-image builds +// File caCertFile = new File(tempDir.toFile(), CA_CERT_FILENAME); +// try (InputStream inputStream = getClass().getResourceAsStream(CA_CERT_RESOURCE_PATH)) { +// assertThat(inputStream).isNotNull(); +// Files.copy(inputStream, caCertFile.toPath(), StandardCopyOption.REPLACE_EXISTING); +// } +// assertWithMessage(caCertFile.toPath() + " should exist").that(caCertFile.exists()).isTrue(); +// +// // open gdch credential json (still needs its "ca_cert_path" to point to the CA certificate +// // obtained from above) +// JsonFactory factory = new GsonFactory(); +// GenericJson converted = +// factory.fromInputStream( +// getClass().getResourceAsStream(GDCH_CREDENTIAL_RESOURCE_PATH), GenericJson.class); +// +// // modify and save to a temporary folder +// converted.set(CA_CERT_JSON_KEY, caCertFile.toPath().toAbsolutePath().toString()); +// projectId = converted.get("project").toString(); +// tokenUri = URI.create(converted.get("token_uri").toString()); +// +// File tempGdchCredentialFile = new File(tempDir.toFile(), GDCH_CREDENTIAL_FILENAME); +// try (FileWriter fileWriter = new FileWriter(tempGdchCredentialFile)) { +// String preparedJson = converted.toPrettyString(); +// fileWriter.write(preparedJson); +// } +// +// // use temp location to instantiate credentials +// initialCredentials = GdchCredentialsTestUtil.fromJson(converted, transportFactory); +// } +// +// /** +// * {@link com.google.api.gax.rpc.ClientContext} will create a new {@link GdchCredentials} with an +// * audience defaulted to the endpoint if the audience is not manually passed. This test confirms +// * that a new credential is created from the context and can be refreshed +// * +// * @throws IOException +// */ +// @Test +// void testCreateClient_withGdchCredentialAndNoAudience_defaultsToEndpointBasedAudience() +// throws IOException { +// +// // we create the client as usual - no audience passed +// String testEndpoint = "custom-endpoint:123"; +// settings = settings.toBuilder().setEndpoint(testEndpoint).build(); +// context = ClientContext.create(settings); +// stubSettings = EchoStubSettings.newBuilder(context).build(); +// client = EchoClient.create(stubSettings.createStub()); +// +// // We retrieve from context and from client +// // the client has only access to creds provider, which may differ from the actual credentials +// // used in the Context +// Credentials fromContext = context.getCredentials(); +// Credentials fromClient = initialCredentials; +// +// // Since ClientContext.create() uses a modified version of GdchCredentials +// // via GdchCredentials.createWithGdchAudience(), they should be different objects +// assertNotSame(fromContext, fromClient); +// +// // When credentials don't have an audience (such as the ones we passed to client creation and +// // now stored in the +// // provider) they will throw if we try to refresh them +// NullPointerException expectedEx = +// assertThrows(NullPointerException.class, () -> initialCredentials.refresh()); +// assertTrue( +// expectedEx.getMessage().contains("Audience are not configured for GDCH service account")); +// +// // However, the credentials prepared in ClientContext should be able to refresh since the +// // audience would be +// // internally defaulted the endpoint of the StubSettings +// registerCredential(fromContext); +// ((GdchCredentials) fromContext).refreshAccessToken(); +// String usedAudience = transportFactory.transport.getLastAudienceSent(); +// assertEquals(testEndpoint, usedAudience); +// } +// +// /** +// * Confirms creating a client with a valid audience is successful. We cannot confirm which +// * audience is chosen (our passed audience or the endpoint) but this is confirmed in the unit +// * tests. +// * +// * @throws IOException +// */ +// @Test +// void testCreateClient_withGdchCredentialWithValidAudience_usesCredentialWithPassedAudience() +// throws IOException { +// +// // Similar to the previous test, create a client as usual but this time we pass a explicit +// // audience. It should +// // be created without issues +// String testAudience = "valid-audience"; +// settings = +// settings.toBuilder().setGdchApiAudience(testAudience).setEndpoint("localhost:7469").build(); +// context = ClientContext.create(settings); +// stubSettings = EchoStubSettings.newBuilder(context).build(); +// client = EchoClient.create(stubSettings.createStub()); +// +// // We retrieve both creds from the creds provider and the ones prepared in the context (which +// // should have been +// // re-created using GdchCredentials.createWithAudience("valid-audience")) +// Credentials fromContext = context.getCredentials(); +// assertNotSame(fromContext, initialCredentials); +// +// // Again, since the initial credentials don't have an audience, we should not be able to refresh +// // them +// NullPointerException thrownByClientCreds = +// assertThrows(NullPointerException.class, () -> initialCredentials.refresh()); +// assertTrue( +// thrownByClientCreds +// .getMessage() +// .contains("Audience are not configured for GDCH service account")); +// +// // But the credentials prepared in ClientContext should be able to refresh since the audience +// // would be internally +// // set to the one passed in stub settings +// registerCredential(fromContext); +// ((GdchCredentials) fromContext).refreshAccessToken(); +// String usedAudience = transportFactory.transport.getLastAudienceSent(); +// assertEquals(testAudience, usedAudience); +// } +// +// private void registerCredential(Credentials fromContext) { +// GdchCredentialsTestUtil.registerGdchCredentialWithMockTransport( +// (GdchCredentials) fromContext, +// transportFactory.transport, +// projectId, +// SID_NAME, +// GDCH_TOKEN_STRING, +// tokenUri); +// } +//} From 3d623c54b532ea3f9cb900473f00db551cfbb0f0 Mon Sep 17 00:00:00 2001 From: cloud-java-bot Date: Fri, 23 Jan 2026 19:07:21 +0000 Subject: [PATCH 06/11] chore: generate libraries at Fri Jan 23 19:05:17 UTC 2026 --- .../google/showcase/v1beta1/it/ITGdch.java | 92 ++++++++++--------- 1 file changed, 48 insertions(+), 44 deletions(-) diff --git a/java-showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITGdch.java b/java-showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITGdch.java index 2c722212b7..544a0d123f 100644 --- a/java-showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITGdch.java +++ b/java-showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITGdch.java @@ -1,4 +1,4 @@ -///* +/// * // * Copyright 2023 Google LLC // * // * Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,47 +14,48 @@ // * limitations under the License. // */ // -//package com.google.showcase.v1beta1.it; -// -//import static com.google.common.truth.Truth.assertThat; -//import static com.google.common.truth.Truth.assertWithMessage; -//import static org.junit.jupiter.api.Assertions.assertEquals; -//import static org.junit.jupiter.api.Assertions.assertNotSame; -//import static org.junit.jupiter.api.Assertions.assertThrows; -//import static org.junit.jupiter.api.Assertions.assertTrue; -// -//import com.google.api.client.json.GenericJson; -//import com.google.api.client.json.JsonFactory; -//import com.google.api.client.json.gson.GsonFactory; -//import com.google.api.gax.core.FixedCredentialsProvider; -//import com.google.api.gax.rpc.ClientContext; -//import com.google.auth.Credentials; -//import com.google.auth.oauth2.GdchCredentials; -//import com.google.auth.oauth2.GdchCredentialsTestUtil; -//import com.google.showcase.v1beta1.EchoClient; -//import com.google.showcase.v1beta1.EchoSettings; -//import com.google.showcase.v1beta1.it.util.InterceptingMockTokenServerTransportFactory; -//import com.google.showcase.v1beta1.it.util.TestClientInitializer; -//import com.google.showcase.v1beta1.stub.EchoStubSettings; -//import java.io.File; -//import java.io.FileWriter; -//import java.io.IOException; -//import java.io.InputStream; -//import java.net.URI; -//import java.nio.file.Files; -//import java.nio.file.Path; -//import java.nio.file.StandardCopyOption; -//import java.util.concurrent.TimeUnit; -//import org.junit.jupiter.api.AfterEach; -//import org.junit.jupiter.api.BeforeEach; -//import org.junit.jupiter.api.Test; -//import org.junit.jupiter.api.io.TempDir; -// -///** -// * Test suite to confirm a client can be instantiated with GDCH credentials. No calls are made since +// package com.google.showcase.v1beta1.it; +// +// import static com.google.common.truth.Truth.assertThat; +// import static com.google.common.truth.Truth.assertWithMessage; +// import static org.junit.jupiter.api.Assertions.assertEquals; +// import static org.junit.jupiter.api.Assertions.assertNotSame; +// import static org.junit.jupiter.api.Assertions.assertThrows; +// import static org.junit.jupiter.api.Assertions.assertTrue; +// +// import com.google.api.client.json.GenericJson; +// import com.google.api.client.json.JsonFactory; +// import com.google.api.client.json.gson.GsonFactory; +// import com.google.api.gax.core.FixedCredentialsProvider; +// import com.google.api.gax.rpc.ClientContext; +// import com.google.auth.Credentials; +// import com.google.auth.oauth2.GdchCredentials; +// import com.google.auth.oauth2.GdchCredentialsTestUtil; +// import com.google.showcase.v1beta1.EchoClient; +// import com.google.showcase.v1beta1.EchoSettings; +// import com.google.showcase.v1beta1.it.util.InterceptingMockTokenServerTransportFactory; +// import com.google.showcase.v1beta1.it.util.TestClientInitializer; +// import com.google.showcase.v1beta1.stub.EchoStubSettings; +// import java.io.File; +// import java.io.FileWriter; +// import java.io.IOException; +// import java.io.InputStream; +// import java.net.URI; +// import java.nio.file.Files; +// import java.nio.file.Path; +// import java.nio.file.StandardCopyOption; +// import java.util.concurrent.TimeUnit; +// import org.junit.jupiter.api.AfterEach; +// import org.junit.jupiter.api.BeforeEach; +// import org.junit.jupiter.api.Test; +// import org.junit.jupiter.api.io.TempDir; +// +/// ** +// * Test suite to confirm a client can be instantiated with GDCH credentials. No calls are made +// since // * it is not feasible to test against real GDCH servers (or replicate an environment) // */ -//class ITGdch { +// class ITGdch { // // private static final String CA_CERT_FILENAME = "fake_cert.pem"; // private static final String CA_CERT_RESOURCE_PATH = "/" + CA_CERT_FILENAME; @@ -123,7 +124,8 @@ // } // // /** -// * {@link com.google.api.gax.rpc.ClientContext} will create a new {@link GdchCredentials} with an +// * {@link com.google.api.gax.rpc.ClientContext} will create a new {@link GdchCredentials} with +// an // * audience defaulted to the endpoint if the audience is not manually passed. This test confirms // * that a new credential is created from the context and can be refreshed // * @@ -183,7 +185,8 @@ // // be created without issues // String testAudience = "valid-audience"; // settings = -// settings.toBuilder().setGdchApiAudience(testAudience).setEndpoint("localhost:7469").build(); +// +// settings.toBuilder().setGdchApiAudience(testAudience).setEndpoint("localhost:7469").build(); // context = ClientContext.create(settings); // stubSettings = EchoStubSettings.newBuilder(context).build(); // client = EchoClient.create(stubSettings.createStub()); @@ -194,7 +197,8 @@ // Credentials fromContext = context.getCredentials(); // assertNotSame(fromContext, initialCredentials); // -// // Again, since the initial credentials don't have an audience, we should not be able to refresh +// // Again, since the initial credentials don't have an audience, we should not be able to +// refresh // // them // NullPointerException thrownByClientCreds = // assertThrows(NullPointerException.class, () -> initialCredentials.refresh()); @@ -221,4 +225,4 @@ // GDCH_TOKEN_STRING, // tokenUri); // } -//} +// } From 1184d1c83248fb99d895edf4aea98bf54fc02c2d Mon Sep 17 00:00:00 2001 From: Joe Wang Date: Fri, 23 Jan 2026 14:26:09 -0500 Subject: [PATCH 07/11] update auth --- dependencies.txt | 2 +- gapic-generator-java-pom-parent/pom.xml | 2 +- gax-java/dependencies.properties | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dependencies.txt b/dependencies.txt index a95dd0501c..8b503ce286 100644 --- a/dependencies.txt +++ b/dependencies.txt @@ -10,7 +10,7 @@ # These dependencies are declared: https://github.com/googleapis/sdk-platform-java/blob/main/gapic-generator-java-pom-parent/pom.xml javax.annotation:javax.annotation-api,javax.annotation-api=1.3.2 io.grpc:grpc-bom,grpc=1.78.0 -com.google.auth:google-auth-library-bom,google.auth=1.42.0 +com.google.auth:google-auth-library-bom,google.auth=1.42.1 com.google.http-client:google-http-client,google.http-client=2.1.0 com.google.code.gson:gson,gson=2.13.2 com.google.guava:guava,guava=33.5.0-jre diff --git a/gapic-generator-java-pom-parent/pom.xml b/gapic-generator-java-pom-parent/pom.xml index 3aba881f91..4d05a95687 100644 --- a/gapic-generator-java-pom-parent/pom.xml +++ b/gapic-generator-java-pom-parent/pom.xml @@ -28,7 +28,7 @@ consistent across modules in this repository --> 1.3.2 1.76.2 - 1.42.0 + 1.42.1 2.1.0 2.12.1 33.5.0-jre diff --git a/gax-java/dependencies.properties b/gax-java/dependencies.properties index 47dc4f51e9..d29f9c34a7 100644 --- a/gax-java/dependencies.properties +++ b/gax-java/dependencies.properties @@ -37,8 +37,8 @@ version.io_grpc=1.76.2 # 2) Replace all characters which are neither alphabetic nor digits with the underscore ('_') character maven.com_google_api_grpc_proto_google_common_protos=com.google.api.grpc:proto-google-common-protos:2.63.2 maven.com_google_api_grpc_grpc_google_common_protos=com.google.api.grpc:grpc-google-common-protos:2.63.2 -maven.com_google_auth_google_auth_library_oauth2_http=com.google.auth:google-auth-library-oauth2-http:1.42.0 -maven.com_google_auth_google_auth_library_credentials=com.google.auth:google-auth-library-credentials:1.42.0 +maven.com_google_auth_google_auth_library_oauth2_http=com.google.auth:google-auth-library-oauth2-http:1.42.1 +maven.com_google_auth_google_auth_library_credentials=com.google.auth:google-auth-library-credentials:1.42.1 maven.io_opentelemetry_opentelemetry_api=io.opentelemetry:opentelemetry-api:1.47.0 maven.io_opencensus_opencensus_api=io.opencensus:opencensus-api:0.31.1 maven.io_opencensus_opencensus_contrib_grpc_metrics=io.opencensus:opencensus-contrib-grpc-metrics:0.31.1 From ae3260cec61a8b620fbea17f2deaee01cdbcf0b2 Mon Sep 17 00:00:00 2001 From: Joe Wang Date: Fri, 23 Jan 2026 14:26:26 -0500 Subject: [PATCH 08/11] restore --- .../google/showcase/v1beta1/it/ITGdch.java | 450 ++++++++--------- .../google/showcase/v1beta1/it/ITGdch.java | 456 +++++++++--------- 2 files changed, 453 insertions(+), 453 deletions(-) diff --git a/java-showcase-3.21.0/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITGdch.java b/java-showcase-3.21.0/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITGdch.java index cf0e5427c0..2f9693f8e4 100644 --- a/java-showcase-3.21.0/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITGdch.java +++ b/java-showcase-3.21.0/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITGdch.java @@ -1,225 +1,225 @@ -///* -// * Copyright 2023 Google LLC -// * -// * Licensed under the Apache License, Version 2.0 (the "License"); -// * you may not use this file except in compliance with the License. -// * You may obtain a copy of the License at -// * -// * https://www.apache.org/licenses/LICENSE-2.0 -// * -// * Unless required by applicable law or agreed to in writing, software -// * distributed under the License is distributed on an "AS IS" BASIS, -// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// * See the License for the specific language governing permissions and -// * limitations under the License. -// */ -// -//package com.google.showcase.v1beta1.it; -// -//import static com.google.common.truth.Truth.assertThat; -//import static com.google.common.truth.Truth.assertWithMessage; -//import static org.junit.jupiter.api.Assertions.assertEquals; -//import static org.junit.jupiter.api.Assertions.assertNotSame; -//import static org.junit.jupiter.api.Assertions.assertThrows; -//import static org.junit.jupiter.api.Assertions.assertTrue; -// -//import com.google.api.client.json.GenericJson; -//import com.google.api.client.json.JsonFactory; -//import com.google.api.client.json.gson.GsonFactory; -//import com.google.api.gax.core.FixedCredentialsProvider; -//import com.google.api.gax.rpc.ClientContext; -//import com.google.auth.Credentials; -//import com.google.auth.oauth2.GdchCredentials; -//import com.google.auth.oauth2.GdchCredentialsTestUtil; -//import com.google.showcase.v1beta1.EchoClient; -//import com.google.showcase.v1beta1.EchoSettings; -//import com.google.showcase.v1beta1.it.util.InterceptingMockTokenServerTransportFactory; -//import com.google.showcase.v1beta1.it.util.TestClientInitializer; -//import com.google.showcase.v1beta1.stub.EchoStubSettings; -//import java.io.File; -//import java.io.FileWriter; -//import java.io.IOException; -//import java.io.InputStream; -//import java.net.URI; -//import java.nio.file.Files; -//import java.nio.file.Path; -//import java.nio.file.StandardCopyOption; -//import java.util.concurrent.TimeUnit; -//import org.junit.jupiter.api.AfterEach; -//import org.junit.jupiter.api.BeforeEach; -//import org.junit.jupiter.api.Disabled; -//import org.junit.jupiter.api.Test; -//import org.junit.jupiter.api.io.TempDir; -// -///** -// * Test suite to confirm a client can be instantiated with GDCH credentials. No calls are made since -// * it is not feasible to test against real GDCH servers (or replicate an environment) -// */ -//class ITGdch { -// -// private static final String CA_CERT_FILENAME = "fake_cert.pem"; -// private static final String CA_CERT_RESOURCE_PATH = "/" + CA_CERT_FILENAME; -// private static final String CA_CERT_JSON_KEY = "ca_cert_path"; -// private static final String GDCH_CREDENTIAL_FILENAME = "test_gdch_credential.json"; -// private static final String GDCH_CREDENTIAL_RESOURCE_PATH = "/" + GDCH_CREDENTIAL_FILENAME; -// private static final String GDCH_TOKEN_STRING = "1/MkSJoj1xsli0AccessToken_NKPY2"; -// private static final String SID_NAME = "service-identity-name"; -// -// private EchoClient client; -// private EchoSettings settings; -// private EchoStubSettings stubSettings; -// private Credentials initialCredentials; -// private ClientContext context; -// private InterceptingMockTokenServerTransportFactory transportFactory; -// private String projectId; -// private URI tokenUri; -// -// @BeforeEach -// void setup(@TempDir Path tempDir) throws IOException { -// transportFactory = new InterceptingMockTokenServerTransportFactory(); -// prepareCredentials(tempDir); -// settings = -// EchoSettings.newBuilder() -// .setCredentialsProvider(FixedCredentialsProvider.create(initialCredentials)) -// .build(); -// } -// -// @AfterEach -// void tearDown() throws InterruptedException { -// if (client != null) { -// client.close(); -// client.awaitTermination(TestClientInitializer.AWAIT_TERMINATION_SECONDS, TimeUnit.SECONDS); -// } -// } -// -// private void prepareCredentials(Path tempDir) throws IOException { -// // Copy file so it can be referenced by Path even in native-image builds -// File caCertFile = new File(tempDir.toFile(), CA_CERT_FILENAME); -// try (InputStream inputStream = getClass().getResourceAsStream(CA_CERT_RESOURCE_PATH)) { -// assertThat(inputStream).isNotNull(); -// Files.copy(inputStream, caCertFile.toPath(), StandardCopyOption.REPLACE_EXISTING); -// } -// assertWithMessage(caCertFile.toPath() + " should exist").that(caCertFile.exists()).isTrue(); -// -// // open gdch credential json (still needs its "ca_cert_path" to point to the CA certificate -// // obtained from above) -// JsonFactory factory = new GsonFactory(); -// GenericJson converted = -// factory.fromInputStream( -// getClass().getResourceAsStream(GDCH_CREDENTIAL_RESOURCE_PATH), GenericJson.class); -// -// // modify and save to a temporary folder -// converted.set(CA_CERT_JSON_KEY, caCertFile.toPath().toAbsolutePath().toString()); -// projectId = converted.get("project").toString(); -// tokenUri = URI.create(converted.get("token_uri").toString()); -// -// File tempGdchCredentialFile = new File(tempDir.toFile(), GDCH_CREDENTIAL_FILENAME); -// try (FileWriter fileWriter = new FileWriter(tempGdchCredentialFile)) { -// String preparedJson = converted.toPrettyString(); -// fileWriter.write(preparedJson); -// } -// -// // use temp location to instantiate credentials -// initialCredentials = GdchCredentialsTestUtil.fromJson(converted, transportFactory); -// } -// -// /** -// * {@link com.google.api.gax.rpc.ClientContext} will create a new {@link GdchCredentials} with an -// * audience defaulted to the endpoint if the audience is not manually passed. This test confirms -// * that a new credential is created from the context and can be refreshed -// * -// * @throws IOException -// */ -// @Test -// void testCreateClient_withGdchCredentialAndNoAudience_defaultsToEndpointBasedAudience() -// throws IOException { -// -// // we create the client as usual - no audience passed -// String testEndpoint = "custom-endpoint:123"; -// settings = settings.toBuilder().setEndpoint(testEndpoint).build(); -// context = ClientContext.create(settings); -// stubSettings = EchoStubSettings.newBuilder(context).build(); -// client = EchoClient.create(stubSettings.createStub()); -// -// // We retrieve from context and from client -// // the client has only access to creds provider, which may differ from the actual credentials -// // used in the Context -// Credentials fromContext = context.getCredentials(); -// Credentials fromClient = initialCredentials; -// -// // Since ClientContext.create() uses a modified version of GdchCredentials -// // via GdchCredentials.createWithGdchAudience(), they should be different objects -// assertNotSame(fromContext, fromClient); -// -// // When credentials don't have an audience (such as the ones we passed to client creation and -// // now stored in the -// // provider) they will throw if we try to refresh them -// NullPointerException expectedEx = -// assertThrows(NullPointerException.class, () -> initialCredentials.refresh()); -// assertTrue( -// expectedEx.getMessage().contains("Audience are not configured for GDCH service account")); -// -// // However, the credentials prepared in ClientContext should be able to refresh since the -// // audience would be -// // internally defaulted the endpoint of the StubSettings -// registerCredential(fromContext); -// ((GdchCredentials) fromContext).refreshAccessToken(); -// String usedAudience = transportFactory.transport.getLastAudienceSent(); -// assertEquals(testEndpoint, usedAudience); -// } -// -// /** -// * Confirms creating a client with a valid audience is successful. We cannot confirm which -// * audience is chosen (our passed audience or the endpoint) but this is confirmed in the unit -// * tests. -// * -// * @throws IOException -// */ -// @Test -// void testCreateClient_withGdchCredentialWithValidAudience_usesCredentialWithPassedAudience() -// throws IOException { -// -// // Similar to the previous test, create a client as usual but this time we pass a explicit -// // audience. It should -// // be created without issues -// String testAudience = "valid-audience"; -// settings = -// settings.toBuilder().setGdchApiAudience(testAudience).setEndpoint("localhost:7469").build(); -// context = ClientContext.create(settings); -// stubSettings = EchoStubSettings.newBuilder(context).build(); -// client = EchoClient.create(stubSettings.createStub()); -// -// // We retrieve both creds from the creds provider and the ones prepared in the context (which -// // should have been -// // re-created using GdchCredentials.createWithAudience("valid-audience")) -// Credentials fromContext = context.getCredentials(); -// assertNotSame(fromContext, initialCredentials); -// -// // Again, since the initial credentials don't have an audience, we should not be able to refresh -// // them -// NullPointerException thrownByClientCreds = -// assertThrows(NullPointerException.class, () -> initialCredentials.refresh()); -// assertTrue( -// thrownByClientCreds -// .getMessage() -// .contains("Audience are not configured for GDCH service account")); -// -// // But the credentials prepared in ClientContext should be able to refresh since the audience -// // would be internally -// // set to the one passed in stub settings -// registerCredential(fromContext); -// ((GdchCredentials) fromContext).refreshAccessToken(); -// String usedAudience = transportFactory.transport.getLastAudienceSent(); -// assertEquals(testAudience, usedAudience); -// } -// -// private void registerCredential(Credentials fromContext) { -// GdchCredentialsTestUtil.registerGdchCredentialWithMockTransport( -// (GdchCredentials) fromContext, -// transportFactory.transport, -// projectId, -// SID_NAME, -// GDCH_TOKEN_STRING, -// tokenUri); -// } -//} +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.showcase.v1beta1.it; + +import static com.google.common.truth.Truth.assertThat; +import static com.google.common.truth.Truth.assertWithMessage; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import com.google.api.client.json.GenericJson; +import com.google.api.client.json.JsonFactory; +import com.google.api.client.json.gson.GsonFactory; +import com.google.api.gax.core.FixedCredentialsProvider; +import com.google.api.gax.rpc.ClientContext; +import com.google.auth.Credentials; +import com.google.auth.oauth2.GdchCredentials; +import com.google.auth.oauth2.GdchCredentialsTestUtil; +import com.google.showcase.v1beta1.EchoClient; +import com.google.showcase.v1beta1.EchoSettings; +import com.google.showcase.v1beta1.it.util.InterceptingMockTokenServerTransportFactory; +import com.google.showcase.v1beta1.it.util.TestClientInitializer; +import com.google.showcase.v1beta1.stub.EchoStubSettings; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardCopyOption; +import java.util.concurrent.TimeUnit; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +/** + * Test suite to confirm a client can be instantiated with GDCH credentials. No calls are made since + * it is not feasible to test against real GDCH servers (or replicate an environment) + */ +class ITGdch { + + private static final String CA_CERT_FILENAME = "fake_cert.pem"; + private static final String CA_CERT_RESOURCE_PATH = "/" + CA_CERT_FILENAME; + private static final String CA_CERT_JSON_KEY = "ca_cert_path"; + private static final String GDCH_CREDENTIAL_FILENAME = "test_gdch_credential.json"; + private static final String GDCH_CREDENTIAL_RESOURCE_PATH = "/" + GDCH_CREDENTIAL_FILENAME; + private static final String GDCH_TOKEN_STRING = "1/MkSJoj1xsli0AccessToken_NKPY2"; + private static final String SID_NAME = "service-identity-name"; + + private EchoClient client; + private EchoSettings settings; + private EchoStubSettings stubSettings; + private Credentials initialCredentials; + private ClientContext context; + private InterceptingMockTokenServerTransportFactory transportFactory; + private String projectId; + private URI tokenUri; + + @BeforeEach + void setup(@TempDir Path tempDir) throws IOException { + transportFactory = new InterceptingMockTokenServerTransportFactory(); + prepareCredentials(tempDir); + settings = + EchoSettings.newBuilder() + .setCredentialsProvider(FixedCredentialsProvider.create(initialCredentials)) + .build(); + } + + @AfterEach + void tearDown() throws InterruptedException { + if (client != null) { + client.close(); + client.awaitTermination(TestClientInitializer.AWAIT_TERMINATION_SECONDS, TimeUnit.SECONDS); + } + } + + private void prepareCredentials(Path tempDir) throws IOException { + // Copy file so it can be referenced by Path even in native-image builds + File caCertFile = new File(tempDir.toFile(), CA_CERT_FILENAME); + try (InputStream inputStream = getClass().getResourceAsStream(CA_CERT_RESOURCE_PATH)) { + assertThat(inputStream).isNotNull(); + Files.copy(inputStream, caCertFile.toPath(), StandardCopyOption.REPLACE_EXISTING); + } + assertWithMessage(caCertFile.toPath() + " should exist").that(caCertFile.exists()).isTrue(); + + // open gdch credential json (still needs its "ca_cert_path" to point to the CA certificate + // obtained from above) + JsonFactory factory = new GsonFactory(); + GenericJson converted = + factory.fromInputStream( + getClass().getResourceAsStream(GDCH_CREDENTIAL_RESOURCE_PATH), GenericJson.class); + + // modify and save to a temporary folder + converted.set(CA_CERT_JSON_KEY, caCertFile.toPath().toAbsolutePath().toString()); + projectId = converted.get("project").toString(); + tokenUri = URI.create(converted.get("token_uri").toString()); + + File tempGdchCredentialFile = new File(tempDir.toFile(), GDCH_CREDENTIAL_FILENAME); + try (FileWriter fileWriter = new FileWriter(tempGdchCredentialFile)) { + String preparedJson = converted.toPrettyString(); + fileWriter.write(preparedJson); + } + + // use temp location to instantiate credentials + initialCredentials = GdchCredentialsTestUtil.fromJson(converted, transportFactory); + } + + /** + * {@link com.google.api.gax.rpc.ClientContext} will create a new {@link GdchCredentials} with an + * audience defaulted to the endpoint if the audience is not manually passed. This test confirms + * that a new credential is created from the context and can be refreshed + * + * @throws IOException + */ + @Test + void testCreateClient_withGdchCredentialAndNoAudience_defaultsToEndpointBasedAudience() + throws IOException { + + // we create the client as usual - no audience passed + String testEndpoint = "custom-endpoint:123"; + settings = settings.toBuilder().setEndpoint(testEndpoint).build(); + context = ClientContext.create(settings); + stubSettings = EchoStubSettings.newBuilder(context).build(); + client = EchoClient.create(stubSettings.createStub()); + + // We retrieve from context and from client + // the client has only access to creds provider, which may differ from the actual credentials + // used in the Context + Credentials fromContext = context.getCredentials(); + Credentials fromClient = initialCredentials; + + // Since ClientContext.create() uses a modified version of GdchCredentials + // via GdchCredentials.createWithGdchAudience(), they should be different objects + assertNotSame(fromContext, fromClient); + + // When credentials don't have an audience (such as the ones we passed to client creation and + // now stored in the + // provider) they will throw if we try to refresh them + NullPointerException expectedEx = + assertThrows(NullPointerException.class, () -> initialCredentials.refresh()); + assertTrue( + expectedEx.getMessage().contains("Audience are not configured for GDCH service account")); + + // However, the credentials prepared in ClientContext should be able to refresh since the + // audience would be + // internally defaulted the endpoint of the StubSettings + registerCredential(fromContext); + ((GdchCredentials) fromContext).refreshAccessToken(); + String usedAudience = transportFactory.transport.getLastAudienceSent(); + assertEquals(testEndpoint, usedAudience); + } + + /** + * Confirms creating a client with a valid audience is successful. We cannot confirm which + * audience is chosen (our passed audience or the endpoint) but this is confirmed in the unit + * tests. + * + * @throws IOException + */ + @Test + void testCreateClient_withGdchCredentialWithValidAudience_usesCredentialWithPassedAudience() + throws IOException { + + // Similar to the previous test, create a client as usual but this time we pass a explicit + // audience. It should + // be created without issues + String testAudience = "valid-audience"; + settings = + settings.toBuilder().setGdchApiAudience(testAudience).setEndpoint("localhost:7469").build(); + context = ClientContext.create(settings); + stubSettings = EchoStubSettings.newBuilder(context).build(); + client = EchoClient.create(stubSettings.createStub()); + + // We retrieve both creds from the creds provider and the ones prepared in the context (which + // should have been + // re-created using GdchCredentials.createWithAudience("valid-audience")) + Credentials fromContext = context.getCredentials(); + assertNotSame(fromContext, initialCredentials); + + // Again, since the initial credentials don't have an audience, we should not be able to refresh + // them + NullPointerException thrownByClientCreds = + assertThrows(NullPointerException.class, () -> initialCredentials.refresh()); + assertTrue( + thrownByClientCreds + .getMessage() + .contains("Audience are not configured for GDCH service account")); + + // But the credentials prepared in ClientContext should be able to refresh since the audience + // would be internally + // set to the one passed in stub settings + registerCredential(fromContext); + ((GdchCredentials) fromContext).refreshAccessToken(); + String usedAudience = transportFactory.transport.getLastAudienceSent(); + assertEquals(testAudience, usedAudience); + } + + private void registerCredential(Credentials fromContext) { + GdchCredentialsTestUtil.registerGdchCredentialWithMockTransport( + (GdchCredentials) fromContext, + transportFactory.transport, + projectId, + SID_NAME, + GDCH_TOKEN_STRING, + tokenUri); + } +} diff --git a/java-showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITGdch.java b/java-showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITGdch.java index 544a0d123f..3169c5f946 100644 --- a/java-showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITGdch.java +++ b/java-showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITGdch.java @@ -1,228 +1,228 @@ -/// * -// * Copyright 2023 Google LLC -// * -// * Licensed under the Apache License, Version 2.0 (the "License"); -// * you may not use this file except in compliance with the License. -// * You may obtain a copy of the License at -// * -// * https://www.apache.org/licenses/LICENSE-2.0 -// * -// * Unless required by applicable law or agreed to in writing, software -// * distributed under the License is distributed on an "AS IS" BASIS, -// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// * See the License for the specific language governing permissions and -// * limitations under the License. -// */ -// -// package com.google.showcase.v1beta1.it; -// -// import static com.google.common.truth.Truth.assertThat; -// import static com.google.common.truth.Truth.assertWithMessage; -// import static org.junit.jupiter.api.Assertions.assertEquals; -// import static org.junit.jupiter.api.Assertions.assertNotSame; -// import static org.junit.jupiter.api.Assertions.assertThrows; -// import static org.junit.jupiter.api.Assertions.assertTrue; -// -// import com.google.api.client.json.GenericJson; -// import com.google.api.client.json.JsonFactory; -// import com.google.api.client.json.gson.GsonFactory; -// import com.google.api.gax.core.FixedCredentialsProvider; -// import com.google.api.gax.rpc.ClientContext; -// import com.google.auth.Credentials; -// import com.google.auth.oauth2.GdchCredentials; -// import com.google.auth.oauth2.GdchCredentialsTestUtil; -// import com.google.showcase.v1beta1.EchoClient; -// import com.google.showcase.v1beta1.EchoSettings; -// import com.google.showcase.v1beta1.it.util.InterceptingMockTokenServerTransportFactory; -// import com.google.showcase.v1beta1.it.util.TestClientInitializer; -// import com.google.showcase.v1beta1.stub.EchoStubSettings; -// import java.io.File; -// import java.io.FileWriter; -// import java.io.IOException; -// import java.io.InputStream; -// import java.net.URI; -// import java.nio.file.Files; -// import java.nio.file.Path; -// import java.nio.file.StandardCopyOption; -// import java.util.concurrent.TimeUnit; -// import org.junit.jupiter.api.AfterEach; -// import org.junit.jupiter.api.BeforeEach; -// import org.junit.jupiter.api.Test; -// import org.junit.jupiter.api.io.TempDir; -// -/// ** -// * Test suite to confirm a client can be instantiated with GDCH credentials. No calls are made -// since -// * it is not feasible to test against real GDCH servers (or replicate an environment) -// */ -// class ITGdch { -// -// private static final String CA_CERT_FILENAME = "fake_cert.pem"; -// private static final String CA_CERT_RESOURCE_PATH = "/" + CA_CERT_FILENAME; -// private static final String CA_CERT_JSON_KEY = "ca_cert_path"; -// private static final String GDCH_CREDENTIAL_FILENAME = "test_gdch_credential.json"; -// private static final String GDCH_CREDENTIAL_RESOURCE_PATH = "/" + GDCH_CREDENTIAL_FILENAME; -// private static final String GDCH_TOKEN_STRING = "1/MkSJoj1xsli0AccessToken_NKPY2"; -// private static final String SID_NAME = "service-identity-name"; -// -// private EchoClient client; -// private EchoSettings settings; -// private EchoStubSettings stubSettings; -// private Credentials initialCredentials; -// private ClientContext context; -// private InterceptingMockTokenServerTransportFactory transportFactory; -// private String projectId; -// private URI tokenUri; -// -// @BeforeEach -// void setup(@TempDir Path tempDir) throws IOException { -// transportFactory = new InterceptingMockTokenServerTransportFactory(); -// prepareCredentials(tempDir); -// settings = -// EchoSettings.newBuilder() -// .setCredentialsProvider(FixedCredentialsProvider.create(initialCredentials)) -// .build(); -// } -// -// @AfterEach -// void tearDown() throws InterruptedException { -// if (client != null) { -// client.close(); -// client.awaitTermination(TestClientInitializer.AWAIT_TERMINATION_SECONDS, TimeUnit.SECONDS); -// } -// } -// -// private void prepareCredentials(Path tempDir) throws IOException { -// // Copy file so it can be referenced by Path even in native-image builds -// File caCertFile = new File(tempDir.toFile(), CA_CERT_FILENAME); -// try (InputStream inputStream = getClass().getResourceAsStream(CA_CERT_RESOURCE_PATH)) { -// assertThat(inputStream).isNotNull(); -// Files.copy(inputStream, caCertFile.toPath(), StandardCopyOption.REPLACE_EXISTING); -// } -// assertWithMessage(caCertFile.toPath() + " should exist").that(caCertFile.exists()).isTrue(); -// -// // open gdch credential json (still needs its "ca_cert_path" to point to the CA certificate -// // obtained from above) -// JsonFactory factory = new GsonFactory(); -// GenericJson converted = -// factory.fromInputStream( -// getClass().getResourceAsStream(GDCH_CREDENTIAL_RESOURCE_PATH), GenericJson.class); -// -// // modify and save to a temporary folder -// converted.set(CA_CERT_JSON_KEY, caCertFile.toPath().toAbsolutePath().toString()); -// projectId = converted.get("project").toString(); -// tokenUri = URI.create(converted.get("token_uri").toString()); -// -// File tempGdchCredentialFile = new File(tempDir.toFile(), GDCH_CREDENTIAL_FILENAME); -// try (FileWriter fileWriter = new FileWriter(tempGdchCredentialFile)) { -// String preparedJson = converted.toPrettyString(); -// fileWriter.write(preparedJson); -// } -// -// // use temp location to instantiate credentials -// initialCredentials = GdchCredentialsTestUtil.fromJson(converted, transportFactory); -// } -// -// /** -// * {@link com.google.api.gax.rpc.ClientContext} will create a new {@link GdchCredentials} with -// an -// * audience defaulted to the endpoint if the audience is not manually passed. This test confirms -// * that a new credential is created from the context and can be refreshed -// * -// * @throws IOException -// */ -// @Test -// void testCreateClient_withGdchCredentialAndNoAudience_defaultsToEndpointBasedAudience() -// throws IOException { -// -// // we create the client as usual - no audience passed -// String testEndpoint = "custom-endpoint:123"; -// settings = settings.toBuilder().setEndpoint(testEndpoint).build(); -// context = ClientContext.create(settings); -// stubSettings = EchoStubSettings.newBuilder(context).build(); -// client = EchoClient.create(stubSettings.createStub()); -// -// // We retrieve from context and from client -// // the client has only access to creds provider, which may differ from the actual credentials -// // used in the Context -// Credentials fromContext = context.getCredentials(); -// Credentials fromClient = initialCredentials; -// -// // Since ClientContext.create() uses a modified version of GdchCredentials -// // via GdchCredentials.createWithGdchAudience(), they should be different objects -// assertNotSame(fromContext, fromClient); -// -// // When credentials don't have an audience (such as the ones we passed to client creation and -// // now stored in the -// // provider) they will throw if we try to refresh them -// NullPointerException expectedEx = -// assertThrows(NullPointerException.class, () -> initialCredentials.refresh()); -// assertTrue( -// expectedEx.getMessage().contains("Audience are not configured for GDCH service account")); -// -// // However, the credentials prepared in ClientContext should be able to refresh since the -// // audience would be -// // internally defaulted the endpoint of the StubSettings -// registerCredential(fromContext); -// ((GdchCredentials) fromContext).refreshAccessToken(); -// String usedAudience = transportFactory.transport.getLastAudienceSent(); -// assertEquals(testEndpoint, usedAudience); -// } -// -// /** -// * Confirms creating a client with a valid audience is successful. We cannot confirm which -// * audience is chosen (our passed audience or the endpoint) but this is confirmed in the unit -// * tests. -// * -// * @throws IOException -// */ -// @Test -// void testCreateClient_withGdchCredentialWithValidAudience_usesCredentialWithPassedAudience() -// throws IOException { -// -// // Similar to the previous test, create a client as usual but this time we pass a explicit -// // audience. It should -// // be created without issues -// String testAudience = "valid-audience"; -// settings = -// -// settings.toBuilder().setGdchApiAudience(testAudience).setEndpoint("localhost:7469").build(); -// context = ClientContext.create(settings); -// stubSettings = EchoStubSettings.newBuilder(context).build(); -// client = EchoClient.create(stubSettings.createStub()); -// -// // We retrieve both creds from the creds provider and the ones prepared in the context (which -// // should have been -// // re-created using GdchCredentials.createWithAudience("valid-audience")) -// Credentials fromContext = context.getCredentials(); -// assertNotSame(fromContext, initialCredentials); -// -// // Again, since the initial credentials don't have an audience, we should not be able to -// refresh -// // them -// NullPointerException thrownByClientCreds = -// assertThrows(NullPointerException.class, () -> initialCredentials.refresh()); -// assertTrue( -// thrownByClientCreds -// .getMessage() -// .contains("Audience are not configured for GDCH service account")); -// -// // But the credentials prepared in ClientContext should be able to refresh since the audience -// // would be internally -// // set to the one passed in stub settings -// registerCredential(fromContext); -// ((GdchCredentials) fromContext).refreshAccessToken(); -// String usedAudience = transportFactory.transport.getLastAudienceSent(); -// assertEquals(testAudience, usedAudience); -// } -// -// private void registerCredential(Credentials fromContext) { -// GdchCredentialsTestUtil.registerGdchCredentialWithMockTransport( -// (GdchCredentials) fromContext, -// transportFactory.transport, -// projectId, -// SID_NAME, -// GDCH_TOKEN_STRING, -// tokenUri); -// } -// } +/ * + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + package com.google.showcase.v1beta1.it; + + import static com.google.common.truth.Truth.assertThat; + import static com.google.common.truth.Truth.assertWithMessage; + import static org.junit.jupiter.api.Assertions.assertEquals; + import static org.junit.jupiter.api.Assertions.assertNotSame; + import static org.junit.jupiter.api.Assertions.assertThrows; + import static org.junit.jupiter.api.Assertions.assertTrue; + + import com.google.api.client.json.GenericJson; + import com.google.api.client.json.JsonFactory; + import com.google.api.client.json.gson.GsonFactory; + import com.google.api.gax.core.FixedCredentialsProvider; + import com.google.api.gax.rpc.ClientContext; + import com.google.auth.Credentials; + import com.google.auth.oauth2.GdchCredentials; + import com.google.auth.oauth2.GdchCredentialsTestUtil; + import com.google.showcase.v1beta1.EchoClient; + import com.google.showcase.v1beta1.EchoSettings; + import com.google.showcase.v1beta1.it.util.InterceptingMockTokenServerTransportFactory; + import com.google.showcase.v1beta1.it.util.TestClientInitializer; + import com.google.showcase.v1beta1.stub.EchoStubSettings; + import java.io.File; + import java.io.FileWriter; + import java.io.IOException; + import java.io.InputStream; + import java.net.URI; + import java.nio.file.Files; + import java.nio.file.Path; + import java.nio.file.StandardCopyOption; + import java.util.concurrent.TimeUnit; + import org.junit.jupiter.api.AfterEach; + import org.junit.jupiter.api.BeforeEach; + import org.junit.jupiter.api.Test; + import org.junit.jupiter.api.io.TempDir; + +/ ** + * Test suite to confirm a client can be instantiated with GDCH credentials. No calls are made + since + * it is not feasible to test against real GDCH servers (or replicate an environment) + */ + class ITGdch { + + private static final String CA_CERT_FILENAME = "fake_cert.pem"; + private static final String CA_CERT_RESOURCE_PATH = "/" + CA_CERT_FILENAME; + private static final String CA_CERT_JSON_KEY = "ca_cert_path"; + private static final String GDCH_CREDENTIAL_FILENAME = "test_gdch_credential.json"; + private static final String GDCH_CREDENTIAL_RESOURCE_PATH = "/" + GDCH_CREDENTIAL_FILENAME; + private static final String GDCH_TOKEN_STRING = "1/MkSJoj1xsli0AccessToken_NKPY2"; + private static final String SID_NAME = "service-identity-name"; + + private EchoClient client; + private EchoSettings settings; + private EchoStubSettings stubSettings; + private Credentials initialCredentials; + private ClientContext context; + private InterceptingMockTokenServerTransportFactory transportFactory; + private String projectId; + private URI tokenUri; + + @BeforeEach + void setup(@TempDir Path tempDir) throws IOException { + transportFactory = new InterceptingMockTokenServerTransportFactory(); + prepareCredentials(tempDir); + settings = + EchoSettings.newBuilder() + .setCredentialsProvider(FixedCredentialsProvider.create(initialCredentials)) + .build(); + } + + @AfterEach + void tearDown() throws InterruptedException { + if (client != null) { + client.close(); + client.awaitTermination(TestClientInitializer.AWAIT_TERMINATION_SECONDS, TimeUnit.SECONDS); + } + } + + private void prepareCredentials(Path tempDir) throws IOException { + // Copy file so it can be referenced by Path even in native-image builds + File caCertFile = new File(tempDir.toFile(), CA_CERT_FILENAME); + try (InputStream inputStream = getClass().getResourceAsStream(CA_CERT_RESOURCE_PATH)) { + assertThat(inputStream).isNotNull(); + Files.copy(inputStream, caCertFile.toPath(), StandardCopyOption.REPLACE_EXISTING); + } + assertWithMessage(caCertFile.toPath() + " should exist").that(caCertFile.exists()).isTrue(); + + // open gdch credential json (still needs its "ca_cert_path" to point to the CA certificate + // obtained from above) + JsonFactory factory = new GsonFactory(); + GenericJson converted = + factory.fromInputStream( + getClass().getResourceAsStream(GDCH_CREDENTIAL_RESOURCE_PATH), GenericJson.class); + + // modify and save to a temporary folder + converted.set(CA_CERT_JSON_KEY, caCertFile.toPath().toAbsolutePath().toString()); + projectId = converted.get("project").toString(); + tokenUri = URI.create(converted.get("token_uri").toString()); + + File tempGdchCredentialFile = new File(tempDir.toFile(), GDCH_CREDENTIAL_FILENAME); + try (FileWriter fileWriter = new FileWriter(tempGdchCredentialFile)) { + String preparedJson = converted.toPrettyString(); + fileWriter.write(preparedJson); + } + + // use temp location to instantiate credentials + initialCredentials = GdchCredentialsTestUtil.fromJson(converted, transportFactory); + } + + /** + * {@link com.google.api.gax.rpc.ClientContext} will create a new {@link GdchCredentials} with + an + * audience defaulted to the endpoint if the audience is not manually passed. This test confirms + * that a new credential is created from the context and can be refreshed + * + * @throws IOException + */ + @Test + void testCreateClient_withGdchCredentialAndNoAudience_defaultsToEndpointBasedAudience() + throws IOException { + + // we create the client as usual - no audience passed + String testEndpoint = "custom-endpoint:123"; + settings = settings.toBuilder().setEndpoint(testEndpoint).build(); + context = ClientContext.create(settings); + stubSettings = EchoStubSettings.newBuilder(context).build(); + client = EchoClient.create(stubSettings.createStub()); + + // We retrieve from context and from client + // the client has only access to creds provider, which may differ from the actual credentials + // used in the Context + Credentials fromContext = context.getCredentials(); + Credentials fromClient = initialCredentials; + + // Since ClientContext.create() uses a modified version of GdchCredentials + // via GdchCredentials.createWithGdchAudience(), they should be different objects + assertNotSame(fromContext, fromClient); + + // When credentials don't have an audience (such as the ones we passed to client creation and + // now stored in the + // provider) they will throw if we try to refresh them + NullPointerException expectedEx = + assertThrows(NullPointerException.class, () -> initialCredentials.refresh()); + assertTrue( + expectedEx.getMessage().contains("Audience are not configured for GDCH service account")); + + // However, the credentials prepared in ClientContext should be able to refresh since the + // audience would be + // internally defaulted the endpoint of the StubSettings + registerCredential(fromContext); + ((GdchCredentials) fromContext).refreshAccessToken(); + String usedAudience = transportFactory.transport.getLastAudienceSent(); + assertEquals(testEndpoint, usedAudience); + } + + /** + * Confirms creating a client with a valid audience is successful. We cannot confirm which + * audience is chosen (our passed audience or the endpoint) but this is confirmed in the unit + * tests. + * + * @throws IOException + */ + @Test + void testCreateClient_withGdchCredentialWithValidAudience_usesCredentialWithPassedAudience() + throws IOException { + + // Similar to the previous test, create a client as usual but this time we pass a explicit + // audience. It should + // be created without issues + String testAudience = "valid-audience"; + settings = + + settings.toBuilder().setGdchApiAudience(testAudience).setEndpoint("localhost:7469").build(); + context = ClientContext.create(settings); + stubSettings = EchoStubSettings.newBuilder(context).build(); + client = EchoClient.create(stubSettings.createStub()); + + // We retrieve both creds from the creds provider and the ones prepared in the context (which + // should have been + // re-created using GdchCredentials.createWithAudience("valid-audience")) + Credentials fromContext = context.getCredentials(); + assertNotSame(fromContext, initialCredentials); + + // Again, since the initial credentials don't have an audience, we should not be able to + refresh + // them + NullPointerException thrownByClientCreds = + assertThrows(NullPointerException.class, () -> initialCredentials.refresh()); + assertTrue( + thrownByClientCreds + .getMessage() + .contains("Audience are not configured for GDCH service account")); + + // But the credentials prepared in ClientContext should be able to refresh since the audience + // would be internally + // set to the one passed in stub settings + registerCredential(fromContext); + ((GdchCredentials) fromContext).refreshAccessToken(); + String usedAudience = transportFactory.transport.getLastAudienceSent(); + assertEquals(testAudience, usedAudience); + } + + private void registerCredential(Credentials fromContext) { + GdchCredentialsTestUtil.registerGdchCredentialWithMockTransport( + (GdchCredentials) fromContext, + transportFactory.transport, + projectId, + SID_NAME, + GDCH_TOKEN_STRING, + tokenUri); + } + } From 8f060badfcd0d0521d36d1881eeed9ab1e1e36ca Mon Sep 17 00:00:00 2001 From: Joe Wang Date: Fri, 23 Jan 2026 14:29:58 -0500 Subject: [PATCH 09/11] restore --- .../src/test/java/com/google/showcase/v1beta1/it/ITGdch.java | 1 - .../src/test/java/com/google/showcase/v1beta1/it/ITGdch.java | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/java-showcase-3.21.0/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITGdch.java b/java-showcase-3.21.0/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITGdch.java index 2f9693f8e4..f043d45cfc 100644 --- a/java-showcase-3.21.0/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITGdch.java +++ b/java-showcase-3.21.0/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITGdch.java @@ -47,7 +47,6 @@ import java.util.concurrent.TimeUnit; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; diff --git a/java-showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITGdch.java b/java-showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITGdch.java index 3169c5f946..127504e188 100644 --- a/java-showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITGdch.java +++ b/java-showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITGdch.java @@ -50,7 +50,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; -/ ** +/** * Test suite to confirm a client can be instantiated with GDCH credentials. No calls are made since * it is not feasible to test against real GDCH servers (or replicate an environment) From 4f67fe08669aff5bee7eff92edcd50f441cec4de Mon Sep 17 00:00:00 2001 From: Joe Wang Date: Fri, 23 Jan 2026 14:31:31 -0500 Subject: [PATCH 10/11] format --- .../src/test/java/com/google/showcase/v1beta1/it/ITGdch.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java-showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITGdch.java b/java-showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITGdch.java index 127504e188..3b39c434d9 100644 --- a/java-showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITGdch.java +++ b/java-showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITGdch.java @@ -1,4 +1,4 @@ -/ * +/* * Copyright 2023 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); From 13bd3d6445ca924fb8aab19af6d2ccd4b394dd89 Mon Sep 17 00:00:00 2001 From: Joe Wang Date: Fri, 23 Jan 2026 14:33:00 -0500 Subject: [PATCH 11/11] restore --- .../google/showcase/v1beta1/it/ITGdch.java | 86 +++++++++---------- 1 file changed, 41 insertions(+), 45 deletions(-) diff --git a/java-showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITGdch.java b/java-showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITGdch.java index 3b39c434d9..f043d45cfc 100644 --- a/java-showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITGdch.java +++ b/java-showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITGdch.java @@ -14,48 +14,47 @@ * limitations under the License. */ - package com.google.showcase.v1beta1.it; - - import static com.google.common.truth.Truth.assertThat; - import static com.google.common.truth.Truth.assertWithMessage; - import static org.junit.jupiter.api.Assertions.assertEquals; - import static org.junit.jupiter.api.Assertions.assertNotSame; - import static org.junit.jupiter.api.Assertions.assertThrows; - import static org.junit.jupiter.api.Assertions.assertTrue; - - import com.google.api.client.json.GenericJson; - import com.google.api.client.json.JsonFactory; - import com.google.api.client.json.gson.GsonFactory; - import com.google.api.gax.core.FixedCredentialsProvider; - import com.google.api.gax.rpc.ClientContext; - import com.google.auth.Credentials; - import com.google.auth.oauth2.GdchCredentials; - import com.google.auth.oauth2.GdchCredentialsTestUtil; - import com.google.showcase.v1beta1.EchoClient; - import com.google.showcase.v1beta1.EchoSettings; - import com.google.showcase.v1beta1.it.util.InterceptingMockTokenServerTransportFactory; - import com.google.showcase.v1beta1.it.util.TestClientInitializer; - import com.google.showcase.v1beta1.stub.EchoStubSettings; - import java.io.File; - import java.io.FileWriter; - import java.io.IOException; - import java.io.InputStream; - import java.net.URI; - import java.nio.file.Files; - import java.nio.file.Path; - import java.nio.file.StandardCopyOption; - import java.util.concurrent.TimeUnit; - import org.junit.jupiter.api.AfterEach; - import org.junit.jupiter.api.BeforeEach; - import org.junit.jupiter.api.Test; - import org.junit.jupiter.api.io.TempDir; +package com.google.showcase.v1beta1.it; + +import static com.google.common.truth.Truth.assertThat; +import static com.google.common.truth.Truth.assertWithMessage; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import com.google.api.client.json.GenericJson; +import com.google.api.client.json.JsonFactory; +import com.google.api.client.json.gson.GsonFactory; +import com.google.api.gax.core.FixedCredentialsProvider; +import com.google.api.gax.rpc.ClientContext; +import com.google.auth.Credentials; +import com.google.auth.oauth2.GdchCredentials; +import com.google.auth.oauth2.GdchCredentialsTestUtil; +import com.google.showcase.v1beta1.EchoClient; +import com.google.showcase.v1beta1.EchoSettings; +import com.google.showcase.v1beta1.it.util.InterceptingMockTokenServerTransportFactory; +import com.google.showcase.v1beta1.it.util.TestClientInitializer; +import com.google.showcase.v1beta1.stub.EchoStubSettings; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardCopyOption; +import java.util.concurrent.TimeUnit; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; /** - * Test suite to confirm a client can be instantiated with GDCH credentials. No calls are made - since + * Test suite to confirm a client can be instantiated with GDCH credentials. No calls are made since * it is not feasible to test against real GDCH servers (or replicate an environment) */ - class ITGdch { +class ITGdch { private static final String CA_CERT_FILENAME = "fake_cert.pem"; private static final String CA_CERT_RESOURCE_PATH = "/" + CA_CERT_FILENAME; @@ -124,8 +123,7 @@ private void prepareCredentials(Path tempDir) throws IOException { } /** - * {@link com.google.api.gax.rpc.ClientContext} will create a new {@link GdchCredentials} with - an + * {@link com.google.api.gax.rpc.ClientContext} will create a new {@link GdchCredentials} with an * audience defaulted to the endpoint if the audience is not manually passed. This test confirms * that a new credential is created from the context and can be refreshed * @@ -185,8 +183,7 @@ void testCreateClient_withGdchCredentialWithValidAudience_usesCredentialWithPass // be created without issues String testAudience = "valid-audience"; settings = - - settings.toBuilder().setGdchApiAudience(testAudience).setEndpoint("localhost:7469").build(); + settings.toBuilder().setGdchApiAudience(testAudience).setEndpoint("localhost:7469").build(); context = ClientContext.create(settings); stubSettings = EchoStubSettings.newBuilder(context).build(); client = EchoClient.create(stubSettings.createStub()); @@ -197,8 +194,7 @@ void testCreateClient_withGdchCredentialWithValidAudience_usesCredentialWithPass Credentials fromContext = context.getCredentials(); assertNotSame(fromContext, initialCredentials); - // Again, since the initial credentials don't have an audience, we should not be able to - refresh + // Again, since the initial credentials don't have an audience, we should not be able to refresh // them NullPointerException thrownByClientCreds = assertThrows(NullPointerException.class, () -> initialCredentials.refresh()); @@ -225,4 +221,4 @@ private void registerCredential(Credentials fromContext) { GDCH_TOKEN_STRING, tokenUri); } - } +}