From ce2b4fadb07b3a5a60528790c7f1abe3aa714d43 Mon Sep 17 00:00:00 2001 From: Wes Tarle Date: Mon, 15 Jun 2026 12:26:29 +0000 Subject: [PATCH 1/2] test(auth): verify GoogleCredentials.fromStream throws IOException on invalid JSON Other client libraries (such as Python, Go, and Rust) strictly validate JSON syntax and reject malformed payload structures immediately. This test ensures Java maintains parity by asserting that an IOException is explicitly thrown when ADC JSON parsing fails, preventing silent fallbacks. This fills an untested gap in the Java ADC resolution suite. --- .../google/auth/oauth2/GoogleCredentialsTest.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/google-auth-library-java/oauth2_http/javatests/com/google/auth/oauth2/GoogleCredentialsTest.java b/google-auth-library-java/oauth2_http/javatests/com/google/auth/oauth2/GoogleCredentialsTest.java index 74aa9fae9ccd..a52c4c35778d 100644 --- a/google-auth-library-java/oauth2_http/javatests/com/google/auth/oauth2/GoogleCredentialsTest.java +++ b/google-auth-library-java/oauth2_http/javatests/com/google/auth/oauth2/GoogleCredentialsTest.java @@ -122,6 +122,18 @@ void fromStream_unknownType_throws() throws IOException { } } + @Test + void fromStream_invalidJson_throws() throws IOException { + // Other client libraries (like Python, Go, and Rust) strictly validate JSON syntax and reject + // malformed payload structures immediately. This test ensures Java maintains parity by + // successfully throwing an IOException when ADC JSON parsing fails, preventing silent fallbacks. + MockHttpTransportFactory transportFactory = new MockHttpTransportFactory(); + try (InputStream stream = new ByteArrayInputStream("invalid-json{".getBytes())) { + assertThrows( + IOException.class, () -> GoogleCredentials.fromStream(stream, transportFactory)); + } + } + @Test void fromStream_nullTransport_throws() { InputStream stream = new ByteArrayInputStream("foo".getBytes()); From dc4317676bc4f1918340766c4fc607ef271c6391 Mon Sep 17 00:00:00 2001 From: Wes Tarle Date: Mon, 15 Jun 2026 11:31:08 -0400 Subject: [PATCH 2/2] Update google-auth-library-java/oauth2_http/javatests/com/google/auth/oauth2/GoogleCredentialsTest.java Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- .../javatests/com/google/auth/oauth2/GoogleCredentialsTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-auth-library-java/oauth2_http/javatests/com/google/auth/oauth2/GoogleCredentialsTest.java b/google-auth-library-java/oauth2_http/javatests/com/google/auth/oauth2/GoogleCredentialsTest.java index a52c4c35778d..b97f3c05c0fa 100644 --- a/google-auth-library-java/oauth2_http/javatests/com/google/auth/oauth2/GoogleCredentialsTest.java +++ b/google-auth-library-java/oauth2_http/javatests/com/google/auth/oauth2/GoogleCredentialsTest.java @@ -128,7 +128,7 @@ void fromStream_invalidJson_throws() throws IOException { // malformed payload structures immediately. This test ensures Java maintains parity by // successfully throwing an IOException when ADC JSON parsing fails, preventing silent fallbacks. MockHttpTransportFactory transportFactory = new MockHttpTransportFactory(); - try (InputStream stream = new ByteArrayInputStream("invalid-json{".getBytes())) { + try (InputStream stream = new ByteArrayInputStream("invalid-json{".getBytes(java.nio.charset.StandardCharsets.UTF_8))) { assertThrows( IOException.class, () -> GoogleCredentials.fromStream(stream, transportFactory)); }