Skip to content

Commit 6f93c0d

Browse files
avishalomhiranya911
authored andcommitted
Release v2.2.1 (#51)
* Adding version, stat counter header and test (#50) * Adding version to the header for the stat counter + tests * bump version to 2.2.1 * Adding comment for manual cleanup
1 parent ad5322b commit 6f93c0d

File tree

5 files changed

+18
-5
lines changed

5 files changed

+18
-5
lines changed

auth/auth.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ type Client struct {
6868
projectID string
6969
snr signer
7070
url string
71+
version string
7172
}
7273

7374
type signer interface {
@@ -128,15 +129,18 @@ func NewClient(ctx context.Context, c *internal.AuthConfig) (*Client, error) {
128129
projectID: c.ProjectID,
129130
snr: snr,
130131
url: idToolKitURL,
132+
version: "Go/Admin/" + c.Version,
131133
}, nil
132134
}
133135

134136
// Passes the request struct, returns a byte array of the json
135137
func (c *Client) makeHTTPCall(ctx context.Context, serviceName string, payload interface{}, result interface{}) error {
138+
versionHeader := internal.WithHeader("X-Client-Version", c.version)
136139
request := &internal.Request{
137140
Method: "POST",
138141
URL: c.url + serviceName,
139142
Body: internal.NewJSONEntity(payload),
143+
Opts: []internal.HTTPOption{versionHeader},
140144
}
141145
resp, err := c.hc.Do(ctx, request)
142146
if err != nil {

auth/user_mgt_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,7 @@ type mockAuthServer struct {
664664
func echoServer(resp interface{}, t *testing.T) *mockAuthServer {
665665
var b []byte
666666
var err error
667+
testVersion := "test.version"
667668
switch v := resp.(type) {
668669
case nil:
669670
b = []byte("")
@@ -675,17 +676,20 @@ func echoServer(resp interface{}, t *testing.T) *mockAuthServer {
675676
t.Fatal("marshaling error")
676677
}
677678
}
678-
679679
s := mockAuthServer{Resp: b}
680680

681681
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
682682
defer r.Body.Close()
683-
684683
reqBody, err := ioutil.ReadAll(r.Body)
685684
if err != nil {
686685
t.Fatal(err)
687686
}
688687
s.Req = append(s.Req, r)
688+
vh := r.Header.Get("X-Client-Version")
689+
wantvh := "Go/Admin/" + testVersion
690+
if vh != wantvh {
691+
t.Errorf("version header = %s; want: %s", vh, wantvh)
692+
}
689693
s.Rbody = reqBody
690694
for k, v := range s.Header {
691695
w.Header().Set(k, v)
@@ -698,9 +702,9 @@ func echoServer(resp interface{}, t *testing.T) *mockAuthServer {
698702

699703
})
700704
s.Srv = httptest.NewServer(handler)
701-
authClient, err := NewClient(context.Background(), &internal.AuthConfig{})
705+
authClient, err := NewClient(context.Background(), &internal.AuthConfig{Version: testVersion})
702706
if err != nil {
703-
t.Fatal()
707+
t.Fatal(err)
704708
}
705709
authClient.url = s.Srv.URL + "/"
706710
s.Client = authClient

firebase.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ var firebaseScopes = []string{
4444
}
4545

4646
// Version of the Firebase Go Admin SDK.
47-
const Version = "2.2.0"
47+
const Version = "2.2.1"
4848

4949
// An App holds configuration and state common to all Firebase services that are exposed from the SDK.
5050
type App struct {
@@ -66,6 +66,7 @@ func (a *App) Auth(ctx context.Context) (*auth.Client, error) {
6666
Creds: a.creds,
6767
ProjectID: a.projectID,
6868
Opts: a.opts,
69+
Version: Version,
6970
}
7071
return auth.NewClient(ctx, conf)
7172
}

integration/auth/user_mgt_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ func TestUserManagement(t *testing.T) {
4646
t.Run("Delete test users", testDeleteUsers)
4747
}
4848

49+
// N.B if the tests are failing due to inability to create existing users, manual
50+
// cleanup of the previus test run might be required, delete the unwanted users via:
51+
// https://console.firebase.google.com/u/0/project/<project-id>/authentication/users
4952
func testCreateUsers(t *testing.T) {
5053
// Create users with uid
5154
for i := 0; i < 3; i++ {

internal/internal.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type AuthConfig struct {
2525
Opts []option.ClientOption
2626
Creds *google.DefaultCredentials
2727
ProjectID string
28+
Version string
2829
}
2930

3031
// StorageConfig represents the configuration of Google Cloud Storage service.

0 commit comments

Comments
 (0)