@@ -17,14 +17,8 @@ import (
17
17
"github.com/google/go-cmp/cmp"
18
18
)
19
19
20
- var testAppCheckConfig = & internal.AppCheckConfig {
21
- ProjectID : "project_id" ,
22
- Version : "test-version" ,
23
- }
24
-
25
20
func TestVerifyTokenHasValidClaims (t * testing.T ) {
26
- var tr http.Request
27
- ts , err := setupFakeJWKS (& tr )
21
+ ts , err := setupFakeJWKS ()
28
22
if err != nil {
29
23
t .Fatalf ("Error setting up fake JWKS server: %v" , err )
30
24
}
@@ -36,17 +30,15 @@ func TestVerifyTokenHasValidClaims(t *testing.T) {
36
30
}
37
31
38
32
JWKSUrl = ts .URL
33
+ conf := & internal.AppCheckConfig {
34
+ ProjectID : "project_id" ,
35
+ }
39
36
40
- client , err := NewClient (context .Background (), testAppCheckConfig )
37
+ client , err := NewClient (context .Background (), conf )
41
38
if err != nil {
42
39
t .Errorf ("Error creating NewClient: %v" , err )
43
40
}
44
41
45
- xGoogAPIClientHeader := internal .GetMetricsHeader (testAppCheckConfig .Version )
46
- if h := tr .Header .Get ("x-goog-api-client" ); h != xGoogAPIClientHeader {
47
- t .Errorf ("x-goog-api-client header = %q; want = %q" , h , xGoogAPIClientHeader )
48
- }
49
-
50
42
type appCheckClaims struct {
51
43
Aud []string `json:"aud"`
52
44
jwt.RegisteredClaims
@@ -177,16 +169,18 @@ func TestVerifyTokenHasValidClaims(t *testing.T) {
177
169
}
178
170
179
171
func TestVerifyTokenMustExist (t * testing.T ) {
180
- var tr http.Request
181
- ts , err := setupFakeJWKS (& tr )
172
+ ts , err := setupFakeJWKS ()
182
173
if err != nil {
183
174
t .Fatalf ("Error setting up fake JWK server: %v" , err )
184
175
}
185
176
defer ts .Close ()
186
177
187
178
JWKSUrl = ts .URL
179
+ conf := & internal.AppCheckConfig {
180
+ ProjectID : "project_id" ,
181
+ }
188
182
189
- client , err := NewClient (context .Background (), testAppCheckConfig )
183
+ client , err := NewClient (context .Background (), conf )
190
184
if err != nil {
191
185
t .Errorf ("Error creating NewClient: %v" , err )
192
186
}
@@ -203,8 +197,7 @@ func TestVerifyTokenMustExist(t *testing.T) {
203
197
}
204
198
205
199
func TestVerifyTokenNotExpired (t * testing.T ) {
206
- var tr http.Request
207
- ts , err := setupFakeJWKS (& tr )
200
+ ts , err := setupFakeJWKS ()
208
201
if err != nil {
209
202
t .Fatalf ("Error setting up fake JWKS server: %v" , err )
210
203
}
@@ -216,8 +209,11 @@ func TestVerifyTokenNotExpired(t *testing.T) {
216
209
}
217
210
218
211
JWKSUrl = ts .URL
212
+ conf := & internal.AppCheckConfig {
213
+ ProjectID : "project_id" ,
214
+ }
219
215
220
- client , err := NewClient (context .Background (), testAppCheckConfig )
216
+ client , err := NewClient (context .Background (), conf )
221
217
if err != nil {
222
218
t .Errorf ("Error creating NewClient: %v" , err )
223
219
}
@@ -268,13 +264,12 @@ func TestVerifyTokenNotExpired(t *testing.T) {
268
264
}
269
265
}
270
266
271
- func setupFakeJWKS (tr * http. Request ) (* httptest.Server , error ) {
267
+ func setupFakeJWKS () (* httptest.Server , error ) {
272
268
jwks , err := os .ReadFile ("../testdata/mock.jwks.json" )
273
269
if err != nil {
274
270
return nil , err
275
271
}
276
272
ts := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
277
- * tr = * r
278
273
w .Write (jwks )
279
274
}))
280
275
return ts , nil
0 commit comments