-
Notifications
You must be signed in to change notification settings - Fork 264
feat(auth): GetUserByProviderID() #339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
a62a8e8
Add bulk get method
rsgowman 7f11d80
Add LastRefreshTimestamp field to users returned via GetAccountInfo rpc
rsgowman 2a212b3
Add DeleteUsers() bulk deletion method
rsgowman d82578b
golint
rsgowman 44dae7a
%w -> %v. (Old versions don't support it?)
rsgowman 2c9da85
go vet
rsgowman 43c7e77
chore: Removed Travis CI integration (#326)
hiranya911 48b371f
review feedback
rsgowman ae498f7
Remove matchesUserRecord interface method
rsgowman f665813
Revert "Remove matchesUserRecord interface method"
rsgowman 7937fff
review feedback 2
rsgowman 14c7264
review feedback 3
rsgowman 454e81c
review feedback 4
rsgowman aa4e7a4
chore: Added Actions-based release workflow (#331)
hiranya911 87fd378
doc review feedback
rsgowman 4fa1fba
go fmt
rsgowman 2f3994a
Merge remote-tracking branch 'origin/dev' into rsgowman/bulk_get
rsgowman bad5bf8
GetUserByProviderID()
rsgowman 9293323
review feedback
rsgowman 7c8ad40
review feedback
rsgowman b41cbcb
Merge remote-tracking branch 'origin/dev' into rsgowman/getAccountByP…
rsgowman ac4e25e
review feedback
rsgowman defe6d1
minor style fixups
rsgowman a70f899
Merge remote-tracking branch 'origin/dev' into rsgowman/getAccountByP…
rsgowman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,22 +141,96 @@ func TestGetUserByPhoneNumber(t *testing.T) { | |
} | ||
} | ||
|
||
func TestGetUserByProviderIDNotFound(t *testing.T) { | ||
mockUsers := []byte(`{ "users": [] }`) | ||
s := echoServer(mockUsers, t) | ||
defer s.Close() | ||
|
||
userRecord, err := s.Client.GetUserByProviderID(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) | ||
} | ||
} | ||
|
||
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]"]}`, | ||
}, | ||
} | ||
|
||
// 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) { | ||
|
||
_, err := s.Client.GetUserByProviderID(context.Background(), tc.providerID, tc.providerUID) | ||
if err != nil { | ||
t.Fatalf("GetUserByProviderID() = %q", err) | ||
} | ||
|
||
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) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestInvalidGetUser(t *testing.T) { | ||
client := &Client{ | ||
baseClient: &baseClient{}, | ||
} | ||
|
||
user, err := client.GetUser(context.Background(), "") | ||
if user != nil || err == nil { | ||
t.Errorf("GetUser('') = (%v, %v); want = (nil, error)", user, err) | ||
} | ||
|
||
user, err = client.GetUserByEmail(context.Background(), "") | ||
if user != nil || err == nil { | ||
t.Errorf("GetUserByEmail('') = (%v, %v); want = (nil, error)", user, err) | ||
} | ||
|
||
user, err = client.GetUserByPhoneNumber(context.Background(), "") | ||
if user != nil || err == nil { | ||
t.Errorf("GetUserPhoneNumber('') = (%v, %v); want = (nil, error)", user, err) | ||
} | ||
|
||
userRecord, err := client.GetUserByProviderID(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) | ||
} | ||
|
||
userRecord, err = client.GetUserByProviderID(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) | ||
} | ||
} | ||
|
||
// Checks to see if the users list contain the given uids. Order is ignored. | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.