Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion credentials/google/google.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func NewDefaultCredentialsWithOptions(opts DefaultCredentialsOptions) credential
ctx, cancel := context.WithTimeout(context.Background(), tokenRequestTimeout)
defer cancel()
var err error
opts.PerRPCCreds, err = oauth.NewApplicationDefault(ctx)
opts.PerRPCCreds, err = newADC(ctx)
if err != nil {
logger.Warningf("NewDefaultCredentialsWithOptions: failed to create application oauth: %v", err)
}
Expand Down Expand Up @@ -112,6 +112,9 @@ var (
newALTS = func() credentials.TransportCredentials {
return alts.NewClientCreds(alts.DefaultClientOptions())
}
newADC = func(ctx context.Context) (credentials.PerRPCCredentials, error) {
return oauth.NewApplicationDefault(ctx)
}
)

// NewWithMode should make a copy of Bundle, and switch mode. Modifying the
Expand Down
15 changes: 11 additions & 4 deletions credentials/google/google_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,24 @@ var (
)

func overrideNewCredsFuncs() func() {
oldNewTLS := newTLS
origNewTLS := newTLS
newTLS = func() credentials.TransportCredentials {
return testTLS
}
oldNewALTS := newALTS
origNewALTS := newALTS
newALTS = func() credentials.TransportCredentials {
return testALTS
}
origNewADC := newADC
newADC = func(context.Context) (credentials.PerRPCCredentials, error) {
// We do not use perRPC creds in this test. It is safe to return nil here.
return nil, nil
}

return func() {
newTLS = oldNewTLS
newALTS = oldNewALTS
newTLS = origNewTLS
newALTS = origNewALTS
newADC = origNewADC
}
}

Expand Down