Skip to content

Commit 4bd3b45

Browse files
committed
Remove App Check headers
1 parent c04763b commit 4bd3b45

File tree

4 files changed

+16
-42
lines changed

4 files changed

+16
-42
lines changed

appcheck/appcheck.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package appcheck
1818
import (
1919
"context"
2020
"errors"
21-
"net/http"
2221
"strings"
2322
"time"
2423

@@ -78,7 +77,6 @@ func NewClient(ctx context.Context, conf *internal.AppCheckConfig) (*Client, err
7877
jwks, err := keyfunc.Get(JWKSUrl, keyfunc.Options{
7978
Ctx: ctx,
8079
RefreshInterval: 6 * time.Hour,
81-
RequestFactory: makeRequestFactory(conf),
8280
})
8381
if err != nil {
8482
return nil, err
@@ -90,23 +88,6 @@ func NewClient(ctx context.Context, conf *internal.AppCheckConfig) (*Client, err
9088
}, nil
9189
}
9290

93-
func makeRequestFactory(conf *internal.AppCheckConfig) func(ctx context.Context, url string) (*http.Request, error) {
94-
opts := []internal.HTTPOption{
95-
internal.WithHeader("x-goog-api-client", internal.GetMetricsHeader(conf.Version)),
96-
}
97-
98-
return func(ctx context.Context, url string) (*http.Request, error) {
99-
hr, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
100-
if err != nil {
101-
return nil, err
102-
}
103-
for _, o := range opts {
104-
o(hr)
105-
}
106-
return hr, nil
107-
}
108-
}
109-
11091
// VerifyToken verifies the given App Check token.
11192
//
11293
// VerifyToken considers an App Check token string to be valid if all the following conditions are met:

appcheck/appcheck_test.go

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,8 @@ import (
1717
"github.com/google/go-cmp/cmp"
1818
)
1919

20-
var testAppCheckConfig = &internal.AppCheckConfig{
21-
ProjectID: "project_id",
22-
Version: "test-version",
23-
}
24-
2520
func TestVerifyTokenHasValidClaims(t *testing.T) {
26-
var tr http.Request
27-
ts, err := setupFakeJWKS(&tr)
21+
ts, err := setupFakeJWKS()
2822
if err != nil {
2923
t.Fatalf("Error setting up fake JWKS server: %v", err)
3024
}
@@ -36,17 +30,15 @@ func TestVerifyTokenHasValidClaims(t *testing.T) {
3630
}
3731

3832
JWKSUrl = ts.URL
33+
conf := &internal.AppCheckConfig{
34+
ProjectID: "project_id",
35+
}
3936

40-
client, err := NewClient(context.Background(), testAppCheckConfig)
37+
client, err := NewClient(context.Background(), conf)
4138
if err != nil {
4239
t.Errorf("Error creating NewClient: %v", err)
4340
}
4441

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-
5042
type appCheckClaims struct {
5143
Aud []string `json:"aud"`
5244
jwt.RegisteredClaims
@@ -177,16 +169,18 @@ func TestVerifyTokenHasValidClaims(t *testing.T) {
177169
}
178170

179171
func TestVerifyTokenMustExist(t *testing.T) {
180-
var tr http.Request
181-
ts, err := setupFakeJWKS(&tr)
172+
ts, err := setupFakeJWKS()
182173
if err != nil {
183174
t.Fatalf("Error setting up fake JWK server: %v", err)
184175
}
185176
defer ts.Close()
186177

187178
JWKSUrl = ts.URL
179+
conf := &internal.AppCheckConfig{
180+
ProjectID: "project_id",
181+
}
188182

189-
client, err := NewClient(context.Background(), testAppCheckConfig)
183+
client, err := NewClient(context.Background(), conf)
190184
if err != nil {
191185
t.Errorf("Error creating NewClient: %v", err)
192186
}
@@ -203,8 +197,7 @@ func TestVerifyTokenMustExist(t *testing.T) {
203197
}
204198

205199
func TestVerifyTokenNotExpired(t *testing.T) {
206-
var tr http.Request
207-
ts, err := setupFakeJWKS(&tr)
200+
ts, err := setupFakeJWKS()
208201
if err != nil {
209202
t.Fatalf("Error setting up fake JWKS server: %v", err)
210203
}
@@ -216,8 +209,11 @@ func TestVerifyTokenNotExpired(t *testing.T) {
216209
}
217210

218211
JWKSUrl = ts.URL
212+
conf := &internal.AppCheckConfig{
213+
ProjectID: "project_id",
214+
}
219215

220-
client, err := NewClient(context.Background(), testAppCheckConfig)
216+
client, err := NewClient(context.Background(), conf)
221217
if err != nil {
222218
t.Errorf("Error creating NewClient: %v", err)
223219
}
@@ -268,13 +264,12 @@ func TestVerifyTokenNotExpired(t *testing.T) {
268264
}
269265
}
270266

271-
func setupFakeJWKS(tr *http.Request) (*httptest.Server, error) {
267+
func setupFakeJWKS() (*httptest.Server, error) {
272268
jwks, err := os.ReadFile("../testdata/mock.jwks.json")
273269
if err != nil {
274270
return nil, err
275271
}
276272
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
277-
*tr = *r
278273
w.Write(jwks)
279274
}))
280275
return ts, nil

firebase.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ func (a *App) Messaging(ctx context.Context) (*messaging.Client, error) {
134134
func (a *App) AppCheck(ctx context.Context) (*appcheck.Client, error) {
135135
conf := &internal.AppCheckConfig{
136136
ProjectID: a.projectID,
137-
Version: Version,
138137
}
139138
return appcheck.NewClient(ctx, conf)
140139
}

internal/internal.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ type MessagingConfig struct {
7777
// AppCheckConfig represents the configuration of App Check service.
7878
type AppCheckConfig struct {
7979
ProjectID string
80-
Version string
8180
}
8281

8382
// MockTokenSource is a TokenSource implementation that can be used for testing.

0 commit comments

Comments
 (0)