Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ static final File getWellKnownCredentialsFile(DefaultCredentialsProvider provide
if (envPath != null) {
cloudConfigPath = new File(envPath);
} else if (provider.getOsName().indexOf("windows") >= 0) {
File appDataPath = new File(provider.getEnv("APPDATA"));
String appData = provider.getEnv("APPDATA");
if (appData == null) {
return null;
}
File appDataPath = new File(appData);
cloudConfigPath = new File(appDataPath, provider.CLOUDSDK_CONFIG_DIRECTORY);
Comment thread
westarle marked this conversation as resolved.
} else {
File configPath = new File(provider.getProperty("user.home", ""), ".config");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,21 @@ void getDefaultCredentials_noCredentials_throws() {
assertEquals(DefaultCredentialsProvider.CLOUDSDK_MISSING_CREDENTIALS, message);
}

@Test
void getDefaultCredentials_windowsMissingAppData_throwsOrFallback() {
// When APPDATA is unset on Windows, the ADC resolution should fail gracefully
// with a structured missing credentials exception, rather than crashing with an NPE.
// This matches the expected behavior seen in Node.js and Python implementations.
MockHttpTransportFactory transportFactory = new MockHttpTransportFactory();
TestDefaultCredentialsProvider testProvider = new TestDefaultCredentialsProvider();
testProvider.setProperty("os.name", "windows");
testProvider.setEnv("APPDATA", null);

IOException e =
assertThrows(IOException.class, () -> testProvider.getDefaultCredentials(transportFactory));
assertEquals(DefaultCredentialsProvider.CLOUDSDK_MISSING_CREDENTIALS, e.getMessage());
}

@Test
void getDefaultCredentials_noCredentialsSandbox_throwsNonSecurity() {
MockHttpTransportFactory transportFactory = new MockHttpTransportFactory();
Expand Down
Loading