Skip to content
This repository was archived by the owner on Apr 7, 2026. It is now read-only.

Commit 44c628e

Browse files
committed
fix: Migrate away from GoogleCredentials.fromStream() usages
1 parent 44ae653 commit 44c628e

2 files changed

Lines changed: 6 additions & 7 deletions

File tree

google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/CredentialsServiceTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@
2525
import com.google.auth.oauth2.ServiceAccountCredentials;
2626
import com.google.cloud.spanner.ErrorCode;
2727
import com.google.cloud.spanner.SpannerException;
28-
import java.io.FileInputStream;
2928
import java.io.IOException;
29+
import java.nio.file.Files;
30+
import java.nio.file.Paths;
3031
import org.junit.Test;
3132
import org.junit.runner.RunWith;
3233
import org.junit.runners.JUnit4;
@@ -36,7 +37,7 @@
3637
public class CredentialsServiceTest {
3738
private static final String FILE_TEST_PATH =
3839
CredentialsServiceTest.class.getResource("test-key.json").getFile();
39-
private static final String APP_DEFAULT_FILE_TEST_PATH =
40+
private static final String SA_APP_DEFAULT_FILE_TEST_PATH =
4041
CredentialsServiceTest.class.getResource("test-key-app-default.json").getFile();
4142

4243
private static final String TEST_PROJECT_ID = "test-project";
@@ -49,7 +50,8 @@ public class CredentialsServiceTest {
4950
GoogleCredentials internalGetApplicationDefault() throws IOException {
5051
// Read application default credentials directly from a specific file instead of actually
5152
// fetching the default from the environment.
52-
return GoogleCredentials.fromStream(new FileInputStream(APP_DEFAULT_FILE_TEST_PATH));
53+
return ServiceAccountCredentials.fromStream(
54+
Files.newInputStream(Paths.get(SA_APP_DEFAULT_FILE_TEST_PATH)));
5355
}
5456
};
5557

google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITVPCNegativeTest.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
import com.google.common.base.Strings;
4949
import com.google.longrunning.OperationsClient;
5050
import com.google.longrunning.OperationsSettings;
51-
import java.io.FileInputStream;
5251
import java.io.IOException;
5352
import java.util.ArrayList;
5453
import java.util.Collections;
@@ -352,9 +351,7 @@ public void deniedListBackupOperations() throws IOException {
352351
.setTransportChannelProvider(InstantiatingGrpcChannelProvider.newBuilder().build())
353352
.setEndpoint("spanner.googleapis.com:443")
354353
.setCredentialsProvider(
355-
FixedCredentialsProvider.create(
356-
GoogleCredentials.fromStream(
357-
new FileInputStream(System.getenv("GOOGLE_APPLICATION_CREDENTIALS")))))
354+
FixedCredentialsProvider.create(GoogleCredentials.getApplicationDefault()))
358355
.build())) {
359356
client.listOperations(backupId.getName() + "/operations", "");
360357
fail("Expected PermissionDeniedException");

0 commit comments

Comments
 (0)