Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(auth/credentials): error on bad file name if explicitly set #10018

Merged
merged 3 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion auth/credentials/detect.go
Original file line number Diff line number Diff line change
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 != "" {
quartzmo marked this conversation as resolved.
Show resolved Hide resolved
if creds, err := readCredentialsFile(filename, opts); err == nil {
return creds, err
}
Expand Down
9 changes: 9 additions & 0 deletions auth/credentials/detect_test.go
Original file line number Diff line number Diff line change
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