Skip to content

Commit

Permalink
fix(auth/credentials): error on bad file name if explicitly set (#10018)
Browse files Browse the repository at this point in the history
Only want our fall-through logic to work for ADC specified behaviour, not explicit credential options.

Fixes: #9809
  • Loading branch information
codyoss committed Apr 22, 2024
1 parent 34455c1 commit 55beaa9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion auth/credentials/detect.go
Expand Up @@ -76,7 +76,10 @@ func DetectDefault(opts *DetectOptions) (*auth.Credentials, error) {
if opts.CredentialsJSON != nil {
return readCredentialsFileJSON(opts.CredentialsJSON, opts)
}
if filename := credsfile.GetFileNameFromEnv(opts.CredentialsFile); filename != "" {
if opts.CredentialsFile != "" {
return readCredentialsFile(opts.CredentialsFile, opts)
}
if filename := os.Getenv(credsfile.GoogleAppCredsEnvVar); filename != "" {
if creds, err := readCredentialsFile(filename, opts); err == nil {
return creds, err
}
Expand Down
9 changes: 9 additions & 0 deletions auth/credentials/detect_test.go
Expand Up @@ -688,6 +688,15 @@ func TestDefaultCredentials_BadFiletype(t *testing.T) {
}
}

func TestDefaultCredentials_BadFileName(t *testing.T) {
if _, err := DetectDefault(&DetectOptions{
CredentialsFile: "a/bad/filepath",
Scopes: []string{"https://www.googleapis.com/auth/cloud-platform"},
}); err == nil {
t.Fatal("got nil, want non-nil err")
}
}

func TestDefaultCredentials_Validate(t *testing.T) {
tests := []struct {
name string
Expand Down

0 comments on commit 55beaa9

Please sign in to comment.