Skip to content

Commit a5ed240

Browse files
committed
address review feedback: extend APPDATA check to reject empty/blank strings, add tests
Signed-off-by: anish k <ak8686@princeton.edu>
1 parent cc39e0b commit a5ed240

2 files changed

Lines changed: 35 additions & 2 deletions

File tree

google-auth-library-java/oauth2_http/java/com/google/auth/oauth2/GoogleAuthUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ static final File getWellKnownCredentialsFile(DefaultCredentialsProvider provide
7373
cloudConfigPath = new File(envPath);
7474
} else if (provider.getOsName().indexOf("windows") >= 0) {
7575
String appDataEnv = provider.getEnv("APPDATA");
76-
if (appDataEnv == null) {
76+
if (appDataEnv == null || appDataEnv.trim().isEmpty()) {
7777
throw new UncheckedIOException(
7878
new FileNotFoundException(
79-
"APPDATA environment variable is not set; cannot locate the well-known"
79+
"APPDATA environment variable is not set or empty; cannot locate the well-known"
8080
+ " credentials file on Windows."));
8181
}
8282
File appDataPath = new File(appDataEnv);

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,39 @@ void getWellKnownCredentialsFile_windows_nullAppData_throwsUncheckedIOException(
5656
() -> GoogleAuthUtils.getWellKnownCredentialsFile(provider));
5757
assertTrue(thrown.getCause() instanceof FileNotFoundException);
5858
assertTrue(thrown.getCause().getMessage().contains("APPDATA"));
59+
assertTrue(thrown.getCause().getMessage().contains("not set or empty"));
60+
}
61+
62+
@Test
63+
void getWellKnownCredentialsFile_windows_emptyAppData_throwsUncheckedIOException() {
64+
DefaultCredentialsProviderTest.TestDefaultCredentialsProvider provider =
65+
new DefaultCredentialsProviderTest.TestDefaultCredentialsProvider();
66+
provider.setProperty("os.name", "windows");
67+
provider.setEnv("APPDATA", "");
68+
69+
UncheckedIOException thrown =
70+
assertThrows(
71+
UncheckedIOException.class,
72+
() -> GoogleAuthUtils.getWellKnownCredentialsFile(provider));
73+
assertTrue(thrown.getCause() instanceof FileNotFoundException);
74+
assertTrue(thrown.getCause().getMessage().contains("APPDATA"));
75+
assertTrue(thrown.getCause().getMessage().contains("not set or empty"));
76+
}
77+
78+
@Test
79+
void getWellKnownCredentialsFile_windows_blankAppData_throwsUncheckedIOException() {
80+
DefaultCredentialsProviderTest.TestDefaultCredentialsProvider provider =
81+
new DefaultCredentialsProviderTest.TestDefaultCredentialsProvider();
82+
provider.setProperty("os.name", "windows");
83+
provider.setEnv("APPDATA", " ");
84+
85+
UncheckedIOException thrown =
86+
assertThrows(
87+
UncheckedIOException.class,
88+
() -> GoogleAuthUtils.getWellKnownCredentialsFile(provider));
89+
assertTrue(thrown.getCause() instanceof FileNotFoundException);
90+
assertTrue(thrown.getCause().getMessage().contains("APPDATA"));
91+
assertTrue(thrown.getCause().getMessage().contains("not set or empty"));
5992
}
6093

6194
@Test

0 commit comments

Comments
 (0)