Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion auth/user_mgt.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ func (c *baseClient) GetUserByPhoneNumber(ctx context.Context, phone string) (*U
})
}

// GetUserByProviderUid gets the user data for the user corresponding to a given provider id.
// GetUserByProviderID gets the user data for the user corresponding to a given provider id.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless this is a literal, capped "ID" would probably be preferred.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

//
// See
// [Retrieve user data](https://firebase.google.com/docs/auth/admin/manage-users#retrieve_user_data)
Expand Down
99 changes: 38 additions & 61 deletions auth/user_mgt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,72 +152,49 @@ func TestGetUserByProviderIDNotFound(t *testing.T) {
}
}

func TestGetUserByProviderID(t *testing.T) {
// The resulting user isn't parsed, so it just needs to exist (even if it's empty).
mockUsers := []byte(`{ "users": [{}] }`)
s := echoServer(mockUsers, t)
defer s.Close()

_, err := s.Client.GetUserByProviderID(context.Background(), "google.com", "google_uid1")
if err != nil {
t.Fatalf("GetUserByProviderID() = %q", err)
}

want := `{"federatedUserId":[{"providerId":"google.com","rawId":"google_uid1"}]}`
got := string(s.Rbody)
if got != want {
t.Errorf("GetUserByProviderID() Req = %v; want = %v", got, 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)
}
}

func TestGetPhoneUserByProviderID(t *testing.T) {
// The resulting user isn't parsed, so it just needs to exist (even if it's empty).
mockUsers := []byte(`{ "users": [{}] }`)
s := echoServer(mockUsers, t)
defer s.Close()

_, err := s.Client.GetUserByProviderID(context.Background(), "phone", "+15555550001")
if err != nil {
t.Fatalf("GetUserByProviderID() = %q", err)
}

want := `{"phoneNumber":["+15555550001"]}`
got := string(s.Rbody)
if got != want {
t.Errorf("GetUserByProviderID() Req = %v; want = %v", got, 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)
func TestGetUserByProviderId(t *testing.T) {
cases := []struct {
providerID string
providerUID string
want string
}{
{
"google.com",
"google_uid1",
`{"federatedUserId":[{"providerId":"google.com","rawId":"google_uid1"}]}`,
}, {
"phone",
"+15555550001",
`{"phoneNumber":["+15555550001"]}`,
}, {
"email",
"[email protected]",
`{"email":["[email protected]"]}`,
},
}
}

func TestGetEmailUserByProviderID(t *testing.T) {
// The resulting user isn't parsed, so it just needs to exist (even if it's empty).
mockUsers := []byte(`{ "users": [{}] }`)
s := echoServer(mockUsers, t)
defer s.Close()
for _, tc := range cases {
t.Run(tc.providerID+":"+tc.providerUID, func(t *testing.T) {
// The resulting user isn't parsed, so it just needs to exist (even if it's empty).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move server initialization and defer close out of the main loop.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

mockUsers := []byte(`{ "users": [{}] }`)
s := echoServer(mockUsers, t)
defer s.Close()

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

want := `{"email":["[email protected]"]}`
got := string(s.Rbody)
if got != want {
t.Errorf("GetUserByProviderID() Req = %v; want = %v", got, want)
}
got := string(s.Rbody)
if got != tc.want {
t.Errorf("GetUserByProviderID() 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)
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)
}
})
}
}

Expand Down