Skip to content

Commit

Permalink
Merge dev into master
Browse files Browse the repository at this point in the history
  • Loading branch information
google-oss-bot authored Mar 29, 2021
2 parents eb0d2a0 + b4f2d40 commit 05378ef
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 19 deletions.
13 changes: 10 additions & 3 deletions auth/user_mgt.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,15 +609,22 @@ func (c *baseClient) GetUserByPhoneNumber(ctx context.Context, phone string) (*U
})
}

// GetUserByProviderID gets the user data for the user corresponding to a given provider ID.
// GetUserByProviderID is an alias for GetUserByProviderUID.
//
// Deprecated. Use GetUserByProviderUID instead.
func (c *baseClient) GetUserByProviderID(ctx context.Context, providerID string, providerUID string) (*UserRecord, error) {
return c.GetUserByProviderUID(ctx, providerID, providerUID)
}

// GetUserByProviderUID gets the user data for the user corresponding to a given provider ID.
//
// See
// [Retrieve user data](https://firebase.google.com/docs/auth/admin/manage-users#retrieve_user_data)
// https://firebase.google.com/docs/auth/admin/manage-users#retrieve_user_data
// for code samples and detailed documentation.
//
// `providerID` indicates the provider, such as 'google.com' for the Google provider.
// `providerUID` is the user identifier for the given provider.
func (c *baseClient) GetUserByProviderID(ctx context.Context, providerID string, providerUID string) (*UserRecord, error) {
func (c *baseClient) GetUserByProviderUID(ctx context.Context, providerID string, providerUID string) (*UserRecord, error) {
// Although we don't really advertise it, we want to also handle non-federated
// IDPs with this call. So if we detect one of them, we'll reroute this
// request appropriately.
Expand Down
20 changes: 10 additions & 10 deletions auth/user_mgt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@ func TestGetUserByProviderIDNotFound(t *testing.T) {
s := echoServer(mockUsers, t)
defer s.Close()

userRecord, err := s.Client.GetUserByProviderID(context.Background(), "google.com", "google_uid1")
userRecord, err := s.Client.GetUserByProviderUID(context.Background(), "google.com", "google_uid1")
want := "cannot find user from providerID: { google.com, google_uid1 }"
if userRecord != nil || err == nil || err.Error() != want || !IsUserNotFound(err) {
t.Errorf("GetUserByProviderID() = (%v, %q); want = (nil, %q)", userRecord, err, want)
t.Errorf("GetUserByProviderUID() = (%v, %q); want = (nil, %q)", userRecord, err, want)
}
}

Expand Down Expand Up @@ -182,19 +182,19 @@ func TestGetUserByProviderId(t *testing.T) {
for _, tc := range cases {
t.Run(tc.providerID+":"+tc.providerUID, func(t *testing.T) {

_, err := s.Client.GetUserByProviderID(context.Background(), tc.providerID, tc.providerUID)
_, err := s.Client.GetUserByProviderUID(context.Background(), tc.providerID, tc.providerUID)
if err != nil {
t.Fatalf("GetUserByProviderID() = %q", err)
t.Fatalf("GetUserByProviderUID() = %q", err)
}

got := string(s.Rbody)
if got != tc.want {
t.Errorf("GetUserByProviderID() Req = %v; want = %v", got, tc.want)
t.Errorf("GetUserByProviderUID() Req = %v; want = %v", got, tc.want)
}

wantPath := "/projects/mock-project-id/accounts:lookup"
if s.Req[0].RequestURI != wantPath {
t.Errorf("GetUserByProviderID() URL = %q; want = %q", s.Req[0].RequestURI, wantPath)
t.Errorf("GetUserByProviderUID() URL = %q; want = %q", s.Req[0].RequestURI, wantPath)
}
})
}
Expand All @@ -220,16 +220,16 @@ func TestInvalidGetUser(t *testing.T) {
t.Errorf("GetUserPhoneNumber('') = (%v, %v); want = (nil, error)", user, err)
}

userRecord, err := client.GetUserByProviderID(context.Background(), "", "google_uid1")
userRecord, err := client.GetUserByProviderUID(context.Background(), "", "google_uid1")
want := "providerID must be a non-empty string"
if userRecord != nil || err == nil || err.Error() != want {
t.Errorf("GetUserByProviderID() = (%v, %q); want = (nil, %q)", userRecord, err, want)
t.Errorf("GetUserByProviderUID() = (%v, %q); want = (nil, %q)", userRecord, err, want)
}

userRecord, err = client.GetUserByProviderID(context.Background(), "google.com", "")
userRecord, err = client.GetUserByProviderUID(context.Background(), "google.com", "")
want = "providerUID must be a non-empty string"
if userRecord != nil || err == nil || err.Error() != want {
t.Errorf("GetUserByProviderID() = (%v, %q); want = (nil, %q)", userRecord, err, want)
t.Errorf("GetUserByProviderUID() = (%v, %q); want = (nil, %q)", userRecord, err, want)
}
}

Expand Down
2 changes: 1 addition & 1 deletion firebase.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import (
var defaultAuthOverrides = make(map[string]interface{})

// Version of the Firebase Go Admin SDK.
const Version = "4.3.0"
const Version = "4.4.0"

// firebaseEnvName is the name of the environment variable with the Config.
const firebaseEnvName = "FIREBASE_CONFIG"
Expand Down
10 changes: 5 additions & 5 deletions integration/auth/user_mgt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func TestGetUser(t *testing.T) {
}
}

func TestGetUserByProviderID(t *testing.T) {
func TestGetUserByProviderUID(t *testing.T) {
// TODO(rsgowman): Once we can link a provider id with a user, just do that
// here instead of importing a new user.
importUserUID := randomUID()
Expand All @@ -98,13 +98,13 @@ func TestGetUserByProviderID(t *testing.T) {
importUser(t, importUserUID, userToImport)
defer deleteUser(importUserUID)

userRecord, err := client.GetUserByProviderID(context.Background(), "google.com", providerUID)
userRecord, err := client.GetUserByProviderUID(context.Background(), "google.com", providerUID)
if err != nil {
t.Fatalf("GetUserByProviderID() = %q", err)
t.Fatalf("GetUserByProviderUID() = %q", err)
}

if userRecord.UID != importUserUID {
t.Errorf("GetUserByProviderID().UID = %v; want = %v", userRecord.UID, importUserUID)
t.Errorf("GetUserByProviderUID().UID = %v; want = %v", userRecord.UID, importUserUID)
}
}

Expand All @@ -124,7 +124,7 @@ func TestGetNonExistingUser(t *testing.T) {
t.Errorf("GetUser(non.existing) = (%v, %v); want = (nil, error)", user, err)
}

user, err = client.GetUserByProviderID(context.Background(), "google.com", "a-uid-that-doesnt-exist")
user, err = client.GetUserByProviderUID(context.Background(), "google.com", "a-uid-that-doesnt-exist")
if user != nil || !auth.IsUserNotFound(err) {
t.Errorf("GetUser(non.existing) = (%v, %v); want = (nil, error)", user, err)
}
Expand Down

0 comments on commit 05378ef

Please sign in to comment.