Skip to content

Commit 55beaa9

Browse files
authored
fix(auth/credentials): error on bad file name if explicitly set (#10018)
Only want our fall-through logic to work for ADC specified behaviour, not explicit credential options. Fixes: #9809
1 parent 34455c1 commit 55beaa9

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

auth/credentials/detect.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ func DetectDefault(opts *DetectOptions) (*auth.Credentials, error) {
7676
if opts.CredentialsJSON != nil {
7777
return readCredentialsFileJSON(opts.CredentialsJSON, opts)
7878
}
79-
if filename := credsfile.GetFileNameFromEnv(opts.CredentialsFile); filename != "" {
79+
if opts.CredentialsFile != "" {
80+
return readCredentialsFile(opts.CredentialsFile, opts)
81+
}
82+
if filename := os.Getenv(credsfile.GoogleAppCredsEnvVar); filename != "" {
8083
if creds, err := readCredentialsFile(filename, opts); err == nil {
8184
return creds, err
8285
}

auth/credentials/detect_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,15 @@ func TestDefaultCredentials_BadFiletype(t *testing.T) {
688688
}
689689
}
690690

691+
func TestDefaultCredentials_BadFileName(t *testing.T) {
692+
if _, err := DetectDefault(&DetectOptions{
693+
CredentialsFile: "a/bad/filepath",
694+
Scopes: []string{"https://www.googleapis.com/auth/cloud-platform"},
695+
}); err == nil {
696+
t.Fatal("got nil, want non-nil err")
697+
}
698+
}
699+
691700
func TestDefaultCredentials_Validate(t *testing.T) {
692701
tests := []struct {
693702
name string

0 commit comments

Comments
 (0)