Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
quartzmo committed Aug 1, 2024
1 parent a6f2e9d commit 133df26
Showing 1 changed file with 0 additions and 91 deletions.
91 changes: 0 additions & 91 deletions transport/http/dial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@ package http
import (
"context"
"fmt"
"strings"
"testing"

"golang.org/x/oauth2"
"golang.org/x/oauth2/google"
"google.golang.org/api/option"
)

func TestNewClient(t *testing.T) {
Expand All @@ -31,89 +26,3 @@ func TestNewClient(t *testing.T) {
t.Fatalf("got %s, want: %s", got, want)
}
}

func TestNewClient_MismatchedUniverseChecks(t *testing.T) {
t.Setenv("GOOGLE_API_GO_EXPERIMENTAL_DISABLE_NEW_AUTH_LIB", "true")
rootTokenScope := "https://www.googleapis.com/auth/cloud-platform"
otherUniverse := "example.com"
defaultUniverse := "googleapis.com"
fakeCreds := `
{"type": "service_account",
"project_id": "some-project",
"universe_domain": "UNIVERSE"}`

// utility function to make a fake credential quickly
makeFakeCredF := func(universe string) option.ClientOption {
data := []byte(strings.ReplaceAll(fakeCreds, "UNIVERSE", universe))
creds, _ := google.CredentialsFromJSON(context.Background(), data, rootTokenScope)
return option.WithCredentials(creds)
}

testCases := []struct {
description string
opts []option.ClientOption
wantErr bool
}{
{
description: "default creds and no universe",
opts: []option.ClientOption{
option.WithCredentials(&google.Credentials{}),
},
wantErr: false,
},
{
description: "default creds and default universe",
opts: []option.ClientOption{
option.WithCredentials(&google.Credentials{}),
option.WithUniverseDomain(defaultUniverse),
},
wantErr: false,
},
{
description: "default creds and mismatched universe",
opts: []option.ClientOption{
option.WithCredentials(&google.Credentials{}),
option.WithUniverseDomain(otherUniverse),
},
wantErr: true,
},
{
description: "foreign universe creds and default universe",
opts: []option.ClientOption{
makeFakeCredF(otherUniverse),
option.WithUniverseDomain(defaultUniverse),
},
wantErr: true,
},
{
description: "foreign universe creds and foreign universe",
opts: []option.ClientOption{
makeFakeCredF(otherUniverse),
option.WithUniverseDomain(otherUniverse),
},
wantErr: false,
},
{
description: "tokensource + mismatched universe",
opts: []option.ClientOption{
option.WithTokenSource(oauth2.StaticTokenSource(&oauth2.Token{})),
option.WithUniverseDomain(otherUniverse),
},
wantErr: false,
},
}

for _, tc := range testCases {
opts := []option.ClientOption{
option.WithScopes(rootTokenScope),
}
opts = append(opts, tc.opts...)
_, _, gotErr := NewClient(context.Background(), opts...)
if tc.wantErr && gotErr == nil {
t.Errorf("%q: wanted error, got none", tc.description)
}
if !tc.wantErr && gotErr != nil {
t.Errorf("%q: wanted success, got err: %v", tc.description, gotErr)
}
}
}

0 comments on commit 133df26

Please sign in to comment.