Skip to content

Commit 328c2ef

Browse files
committed
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.
1 parent 051aea7 commit 328c2ef

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

google-auth-library-java/oauth2_http/javatests/com/google/auth/oauth2/GoogleCredentialsTest.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import java.io.IOException;
5454
import java.io.InputStream;
5555
import java.net.URI;
56+
import java.nio.charset.StandardCharsets;
5657
import java.util.Arrays;
5758
import java.util.Collection;
5859
import java.util.Collections;
@@ -122,9 +123,20 @@ void fromStream_unknownType_throws() throws IOException {
122123
}
123124
}
124125

126+
@Test
127+
void fromStream_invalidJson_throws() throws IOException {
128+
// This test ensures Java successfully throws an IOException when ADC JSON parsing
129+
// fails, preventing silent fallbacks.
130+
MockHttpTransportFactory transportFactory = new MockHttpTransportFactory();
131+
try (InputStream stream =
132+
new ByteArrayInputStream("invalid-json{".getBytes(StandardCharsets.UTF_8))) {
133+
assertThrows(IOException.class, () -> GoogleCredentials.fromStream(stream, transportFactory));
134+
}
135+
}
136+
125137
@Test
126138
void fromStream_nullTransport_throws() {
127-
InputStream stream = new ByteArrayInputStream("foo".getBytes());
139+
InputStream stream = new ByteArrayInputStream("foo".getBytes(StandardCharsets.UTF_8));
128140
assertThrows(NullPointerException.class, () -> GoogleCredentials.fromStream(stream, null));
129141
}
130142

0 commit comments

Comments
 (0)