From 95713928e495d51d2209bb81cbf2c16185441145 Mon Sep 17 00:00:00 2001 From: Patrick Jones Date: Wed, 13 Jan 2021 12:36:49 -0800 Subject: [PATCH] Small tweaks. Change-Id: I77b1f7b362c3ed9972e278f06045c603abcdd9d4 --- google/internal/externalaccount/urlcredsource.go | 4 ++++ google/internal/externalaccount/urlcredsource_test.go | 7 ++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/google/internal/externalaccount/urlcredsource.go b/google/internal/externalaccount/urlcredsource.go index d3818be..b0d5d35 100644 --- a/google/internal/externalaccount/urlcredsource.go +++ b/google/internal/externalaccount/urlcredsource.go @@ -25,6 +25,10 @@ type urlCredentialSource struct { func (cs urlCredentialSource) subjectToken() (string, error) { client := oauth2.NewClient(cs.ctx, nil) req, err := http.NewRequest("GET", cs.URL, nil) + if err != nil { + return "", fmt.Errorf("oauth2/google: HTTP request for URL-sourced credential failed: %v", err) + } + req = req.WithContext(cs.ctx) for key, val := range cs.Headers { req.Header.Add(key, val) diff --git a/google/internal/externalaccount/urlcredsource_test.go b/google/internal/externalaccount/urlcredsource_test.go index 1deea05..592610f 100644 --- a/google/internal/externalaccount/urlcredsource_test.go +++ b/google/internal/externalaccount/urlcredsource_test.go @@ -5,6 +5,7 @@ package externalaccount import ( + "context" "encoding/json" "net/http" "net/http/httptest" @@ -27,7 +28,7 @@ func TestRetrieveURLSubjectToken_Text(t *testing.T) { tfc := testFileConfig tfc.CredentialSource = cs - out, err := tfc.parse().subjectToken() + out, err := tfc.parse(context.Background()).subjectToken() if err != nil { t.Fatalf("retrieveSubjectToken() failed: %v", err) } @@ -50,7 +51,7 @@ func TestRetrieveURLSubjectToken_Untyped(t *testing.T) { tfc := testFileConfig tfc.CredentialSource = cs - out, err := tfc.parse().subjectToken() + out, err := tfc.parse(context.Background()).subjectToken() if err != nil { t.Fatalf("Failed to retrieve URL subject token: %v", err) } @@ -81,7 +82,7 @@ func TestRetrieveURLSubjectToken_JSON(t *testing.T) { tfc := testFileConfig tfc.CredentialSource = cs - out, err := tfc.parse().subjectToken() + out, err := tfc.parse(context.Background()).subjectToken() if err != nil { t.Fatalf("%v", err) }