forked from remote/oauth2
Fixed Tyler's nits
Change-Id: I2dc28d4f427509b3e62eeb9f14b1583178812038
This commit is contained in:
@@ -9,13 +9,13 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"golang.org/x/oauth2/google/internal/externalaccount"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"cloud.google.com/go/compute/metadata"
|
"cloud.google.com/go/compute/metadata"
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
|
"golang.org/x/oauth2/google/internal/externalaccount"
|
||||||
"golang.org/x/oauth2/jwt"
|
"golang.org/x/oauth2/jwt"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ var (
|
|||||||
testNow = func() time.Time { return time.Unix(expiry, 0) }
|
testNow = func() time.Time { return time.Unix(expiry, 0) }
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestToken_Func(t *testing.T) {
|
func TestToken(t *testing.T) {
|
||||||
|
|
||||||
targetServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
targetServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
if got, want := r.URL.String(), "/"; got != want {
|
if got, want := r.URL.String(), "/"; got != want {
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ func (cs fileCredentialSource) subjectToken() (string, error) {
|
|||||||
return "", fmt.Errorf("oauth2/google: failed to read credential file: %v", err)
|
return "", fmt.Errorf("oauth2/google: failed to read credential file: %v", err)
|
||||||
}
|
}
|
||||||
tokenBytes = bytes.TrimSpace(tokenBytes)
|
tokenBytes = bytes.TrimSpace(tokenBytes)
|
||||||
var output string
|
|
||||||
switch cs.Format.Type {
|
switch cs.Format.Type {
|
||||||
case "json":
|
case "json":
|
||||||
jsonData := make(map[string]interface{})
|
jsonData := make(map[string]interface{})
|
||||||
@@ -46,15 +45,13 @@ func (cs fileCredentialSource) subjectToken() (string, error) {
|
|||||||
if !ok {
|
if !ok {
|
||||||
return "", errors.New("oauth2/google: improperly formatted subject token")
|
return "", errors.New("oauth2/google: improperly formatted subject token")
|
||||||
}
|
}
|
||||||
output = token
|
return token, nil
|
||||||
case "text":
|
case "text":
|
||||||
output = string(tokenBytes)
|
return string(tokenBytes), nil
|
||||||
case "":
|
case "":
|
||||||
output = string(tokenBytes)
|
return string(tokenBytes), nil
|
||||||
default:
|
default:
|
||||||
return "", errors.New("oauth2/google: invalid credential_source file format type")
|
return "", errors.New("oauth2/google: invalid credential_source file format type")
|
||||||
}
|
}
|
||||||
|
|
||||||
return output, nil
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user