@@ -11,7 +11,6 @@ import (
1111 "strings"
1212 "testing"
1313
14- "golang.org/x/oauth2"
1514 "golang.org/x/oauth2/google"
1615 "google.golang.org/api/idtoken"
1716 "google.golang.org/api/option"
@@ -49,28 +48,7 @@ func TestNewTokenSource(t *testing.T) {
4948 }
5049}
5150
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 ) {
7452 if testing .Short () {
7553 t .Skip ("skipping integration test" )
7654 }
@@ -79,14 +57,19 @@ func TestNewClient_WithCredentialJSON(t *testing.T) {
7957 if err != nil {
8058 t .Fatalf ("unable to find default creds: %v" , err )
8159 }
82- client , err := idtoken .NewClient (ctx , aud , option .WithCredentialsJSON (creds .JSON ))
60+ ts , err := idtoken .NewTokenSource (ctx , aud , option .WithCredentialsJSON (creds .JSON ))
8361 if err != nil {
8462 t .Fatalf ("unable to create Client: %v" , err )
8563 }
86- tok , err := client . Transport .( * oauth2. Transport ). Source .Token ()
64+ tok , err := ts .Token ()
8765 if err != nil {
8866 t .Fatalf ("unable to retrieve Token: %v" , err )
8967 }
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+ }
9073 validTok , err := idtoken .Validate (context .Background (), tok .AccessToken , aud )
9174 if err != nil {
9275 t .Fatalf ("token validation failed: %v" , err )
0 commit comments