@@ -11,7 +11,6 @@ import (
11
11
"strings"
12
12
"testing"
13
13
14
- "golang.org/x/oauth2"
15
14
"golang.org/x/oauth2/google"
16
15
"google.golang.org/api/idtoken"
17
16
"google.golang.org/api/option"
@@ -49,28 +48,7 @@ func TestNewTokenSource(t *testing.T) {
49
48
}
50
49
}
51
50
52
- func TestNewClient_WithCredentialFile (t * testing.T ) {
53
- if testing .Short () {
54
- t .Skip ("skipping integration test" )
55
- }
56
- client , err := idtoken .NewClient (context .Background (), aud , option .WithCredentialsFile (os .Getenv (envCredentialFile )))
57
- if err != nil {
58
- t .Fatalf ("unable to create Client: %v" , err )
59
- }
60
- tok , err := client .Transport .(* oauth2.Transport ).Source .Token ()
61
- if err != nil {
62
- t .Fatalf ("unable to retrieve Token: %v" , err )
63
- }
64
- validTok , err := idtoken .Validate (context .Background (), tok .AccessToken , aud )
65
- if err != nil {
66
- t .Fatalf ("token validation failed: %v" , err )
67
- }
68
- if validTok .Audience != aud {
69
- t .Fatalf ("got %q, want %q" , validTok .Audience , aud )
70
- }
71
- }
72
-
73
- func TestNewClient_WithCredentialJSON (t * testing.T ) {
51
+ func TestNewTokenSource_WithCredentialJSON (t * testing.T ) {
74
52
if testing .Short () {
75
53
t .Skip ("skipping integration test" )
76
54
}
@@ -79,14 +57,19 @@ func TestNewClient_WithCredentialJSON(t *testing.T) {
79
57
if err != nil {
80
58
t .Fatalf ("unable to find default creds: %v" , err )
81
59
}
82
- client , err := idtoken .NewClient (ctx , aud , option .WithCredentialsJSON (creds .JSON ))
60
+ ts , err := idtoken .NewTokenSource (ctx , aud , option .WithCredentialsJSON (creds .JSON ))
83
61
if err != nil {
84
62
t .Fatalf ("unable to create Client: %v" , err )
85
63
}
86
- tok , err := client . Transport .( * oauth2. Transport ). Source .Token ()
64
+ tok , err := ts .Token ()
87
65
if err != nil {
88
66
t .Fatalf ("unable to retrieve Token: %v" , err )
89
67
}
68
+ req := & http.Request {Header : make (http.Header )}
69
+ tok .SetAuthHeader (req )
70
+ if ! strings .HasPrefix (req .Header .Get ("Authorization" ), "Bearer " ) {
71
+ t .Fatalf ("token should sign requests with Bearer Authorization header" )
72
+ }
90
73
validTok , err := idtoken .Validate (context .Background (), tok .AccessToken , aud )
91
74
if err != nil {
92
75
t .Fatalf ("token validation failed: %v" , err )
0 commit comments