Skip to content

Commit

Permalink
Release v2.2.1 (#51)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
avishalom authored and hiranya911 committed Dec 13, 2017
1 parent ad5322b commit 6f93c0d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
4 changes: 4 additions & 0 deletions auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type Client struct {
projectID string
snr signer
url string
version string
}

type signer interface {
Expand Down Expand Up @@ -128,15 +129,18 @@ func NewClient(ctx context.Context, c *internal.AuthConfig) (*Client, error) {
projectID: c.ProjectID,
snr: snr,
url: idToolKitURL,
version: "Go/Admin/" + c.Version,
}, nil
}

// Passes the request struct, returns a byte array of the json
func (c *Client) makeHTTPCall(ctx context.Context, serviceName string, payload interface{}, result interface{}) error {
versionHeader := internal.WithHeader("X-Client-Version", c.version)
request := &internal.Request{
Method: "POST",
URL: c.url + serviceName,
Body: internal.NewJSONEntity(payload),
Opts: []internal.HTTPOption{versionHeader},
}
resp, err := c.hc.Do(ctx, request)
if err != nil {
Expand Down
12 changes: 8 additions & 4 deletions auth/user_mgt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,7 @@ type mockAuthServer struct {
func echoServer(resp interface{}, t *testing.T) *mockAuthServer {
var b []byte
var err error
testVersion := "test.version"
switch v := resp.(type) {
case nil:
b = []byte("")
Expand All @@ -675,17 +676,20 @@ func echoServer(resp interface{}, t *testing.T) *mockAuthServer {
t.Fatal("marshaling error")
}
}

s := mockAuthServer{Resp: b}

handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()

reqBody, err := ioutil.ReadAll(r.Body)
if err != nil {
t.Fatal(err)
}
s.Req = append(s.Req, r)
vh := r.Header.Get("X-Client-Version")
wantvh := "Go/Admin/" + testVersion
if vh != wantvh {
t.Errorf("version header = %s; want: %s", vh, wantvh)
}
s.Rbody = reqBody
for k, v := range s.Header {
w.Header().Set(k, v)
Expand All @@ -698,9 +702,9 @@ func echoServer(resp interface{}, t *testing.T) *mockAuthServer {

})
s.Srv = httptest.NewServer(handler)
authClient, err := NewClient(context.Background(), &internal.AuthConfig{})
authClient, err := NewClient(context.Background(), &internal.AuthConfig{Version: testVersion})
if err != nil {
t.Fatal()
t.Fatal(err)
}
authClient.url = s.Srv.URL + "/"
s.Client = authClient
Expand Down
3 changes: 2 additions & 1 deletion firebase.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ var firebaseScopes = []string{
}

// Version of the Firebase Go Admin SDK.
const Version = "2.2.0"
const Version = "2.2.1"

// An App holds configuration and state common to all Firebase services that are exposed from the SDK.
type App struct {
Expand All @@ -66,6 +66,7 @@ func (a *App) Auth(ctx context.Context) (*auth.Client, error) {
Creds: a.creds,
ProjectID: a.projectID,
Opts: a.opts,
Version: Version,
}
return auth.NewClient(ctx, conf)
}
Expand Down
3 changes: 3 additions & 0 deletions integration/auth/user_mgt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ func TestUserManagement(t *testing.T) {
t.Run("Delete test users", testDeleteUsers)
}

// N.B if the tests are failing due to inability to create existing users, manual
// cleanup of the previus test run might be required, delete the unwanted users via:
// https://console.firebase.google.com/u/0/project/<project-id>/authentication/users
func testCreateUsers(t *testing.T) {
// Create users with uid
for i := 0; i < 3; i++ {
Expand Down
1 change: 1 addition & 0 deletions internal/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type AuthConfig struct {
Opts []option.ClientOption
Creds *google.DefaultCredentials
ProjectID string
Version string
}

// StorageConfig represents the configuration of Google Cloud Storage service.
Expand Down

0 comments on commit 6f93c0d

Please sign in to comment.