-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(option): add internaloption to force use of certain credential (#…
…1162) A new internaloption added that forces the client to use a certain credential. This ensures that if a user directly passes in their own credentials, we can capture and use these credentials. This is part of the effort to improve Signed URLs in the Go Storage Client.
- Loading branch information
Showing
5 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright 2021 Google LLC. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package internaloption | ||
|
||
import ( | ||
"testing" | ||
|
||
"golang.org/x/oauth2" | ||
"golang.org/x/oauth2/google" | ||
"google.golang.org/api/internal" | ||
) | ||
|
||
func TestWithCredentials(t *testing.T) { | ||
want := "fakeToken" | ||
fakeCreds := &google.Credentials{ | ||
TokenSource: oauth2.StaticTokenSource(&oauth2.Token{AccessToken: want}), | ||
} | ||
opt := WithCredentials(fakeCreds) | ||
ds := &internal.DialSettings{} | ||
opt.Apply(ds) | ||
if ds.InternalCredentials == nil || ds.InternalCredentials.TokenSource == nil { | ||
t.Errorf("ds.InternalCredentials should be initialized") | ||
} | ||
if tok, err := ds.InternalCredentials.TokenSource.Token(); err != nil || tok.AccessToken != "fakeToken" { | ||
t.Errorf("ts.Token() = %q, want %q", tok.AccessToken, "") | ||
} | ||
} |