@@ -6,6 +6,7 @@ package externalaccount
66
77import (
88 "context"
9+ "fmt"
910 "io/ioutil"
1011 "net/http"
1112 "net/http/httptest"
@@ -51,6 +52,7 @@ type testExchangeTokenServer struct {
5152 url string
5253 authorization string
5354 contentType string
55+ metricsHeader string
5456 body string
5557 response string
5658}
@@ -68,6 +70,10 @@ func run(t *testing.T, config *Config, tets *testExchangeTokenServer) (*oauth2.T
6870 if got , want := headerContentType , tets .contentType ; got != want {
6971 t .Errorf ("got %v but want %v" , got , want )
7072 }
73+ headerMetrics := r .Header .Get ("x-goog-api-client" )
74+ if got , want := headerMetrics , tets .metricsHeader ; got != want {
75+ t .Errorf ("got %v but want %v" , got , want )
76+ }
7177 body , err := ioutil .ReadAll (r .Body )
7278 if err != nil {
7379 t .Fatalf ("Failed reading request body: %s." , err )
@@ -106,6 +112,10 @@ func validateToken(t *testing.T, tok *oauth2.Token) {
106112 }
107113}
108114
115+ func getExpectedMetricsHeader (source string , saImpersonation bool , configLifetime bool ) string {
116+ return fmt .Sprintf ("gl-go/%s auth/unknown google-byoid-sdk source/%s sa-impersonation/%t config-lifetime/%t" , goVersion (), source , saImpersonation , configLifetime )
117+ }
118+
109119func TestToken (t * testing.T ) {
110120 config := Config {
111121 Audience : "32555940559.apps.googleusercontent.com" ,
@@ -120,6 +130,7 @@ func TestToken(t *testing.T) {
120130 url : "/" ,
121131 authorization : "Basic cmJyZ25vZ25yaG9uZ28zYmk0Z2I5Z2hnOWc6bm90c29zZWNyZXQ=" ,
122132 contentType : "application/x-www-form-urlencoded" ,
133+ metricsHeader : getExpectedMetricsHeader ("file" , false , false ),
123134 body : baseCredsRequestBody ,
124135 response : baseCredsResponseBody ,
125136 }
@@ -147,6 +158,7 @@ func TestWorkforcePoolTokenWithClientID(t *testing.T) {
147158 url : "/" ,
148159 authorization : "Basic cmJyZ25vZ25yaG9uZ28zYmk0Z2I5Z2hnOWc6bm90c29zZWNyZXQ=" ,
149160 contentType : "application/x-www-form-urlencoded" ,
161+ metricsHeader : getExpectedMetricsHeader ("file" , false , false ),
150162 body : workforcePoolRequestBodyWithClientId ,
151163 response : baseCredsResponseBody ,
152164 }
@@ -173,6 +185,7 @@ func TestWorkforcePoolTokenWithoutClientID(t *testing.T) {
173185 url : "/" ,
174186 authorization : "" ,
175187 contentType : "application/x-www-form-urlencoded" ,
188+ metricsHeader : getExpectedMetricsHeader ("file" , false , false ),
176189 body : workforcePoolRequestBodyWithoutClientId ,
177190 response : baseCredsResponseBody ,
178191 }
0 commit comments