@@ -6,6 +6,7 @@ package externalaccount
6
6
7
7
import (
8
8
"context"
9
+ "fmt"
9
10
"io/ioutil"
10
11
"net/http"
11
12
"net/http/httptest"
@@ -51,6 +52,7 @@ type testExchangeTokenServer struct {
51
52
url string
52
53
authorization string
53
54
contentType string
55
+ metricsHeader string
54
56
body string
55
57
response string
56
58
}
@@ -68,6 +70,10 @@ func run(t *testing.T, config *Config, tets *testExchangeTokenServer) (*oauth2.T
68
70
if got , want := headerContentType , tets .contentType ; got != want {
69
71
t .Errorf ("got %v but want %v" , got , want )
70
72
}
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
+ }
71
77
body , err := ioutil .ReadAll (r .Body )
72
78
if err != nil {
73
79
t .Fatalf ("Failed reading request body: %s." , err )
@@ -106,6 +112,10 @@ func validateToken(t *testing.T, tok *oauth2.Token) {
106
112
}
107
113
}
108
114
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
+
109
119
func TestToken (t * testing.T ) {
110
120
config := Config {
111
121
Audience : "32555940559.apps.googleusercontent.com" ,
@@ -120,6 +130,7 @@ func TestToken(t *testing.T) {
120
130
url : "/" ,
121
131
authorization : "Basic cmJyZ25vZ25yaG9uZ28zYmk0Z2I5Z2hnOWc6bm90c29zZWNyZXQ=" ,
122
132
contentType : "application/x-www-form-urlencoded" ,
133
+ metricsHeader : getExpectedMetricsHeader ("file" , false , false ),
123
134
body : baseCredsRequestBody ,
124
135
response : baseCredsResponseBody ,
125
136
}
@@ -147,6 +158,7 @@ func TestWorkforcePoolTokenWithClientID(t *testing.T) {
147
158
url : "/" ,
148
159
authorization : "Basic cmJyZ25vZ25yaG9uZ28zYmk0Z2I5Z2hnOWc6bm90c29zZWNyZXQ=" ,
149
160
contentType : "application/x-www-form-urlencoded" ,
161
+ metricsHeader : getExpectedMetricsHeader ("file" , false , false ),
150
162
body : workforcePoolRequestBodyWithClientId ,
151
163
response : baseCredsResponseBody ,
152
164
}
@@ -173,6 +185,7 @@ func TestWorkforcePoolTokenWithoutClientID(t *testing.T) {
173
185
url : "/" ,
174
186
authorization : "" ,
175
187
contentType : "application/x-www-form-urlencoded" ,
188
+ metricsHeader : getExpectedMetricsHeader ("file" , false , false ),
176
189
body : workforcePoolRequestBodyWithoutClientId ,
177
190
response : baseCredsResponseBody ,
178
191
}
0 commit comments