-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
216 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
|
@@ -326,6 326,109 @@ public async Task GetUserByPhoneNumberEmpty() | |
await Assert.ThrowsAsync<ArgumentException>(() => auth.GetUserByPhoneNumberAsync(string.Empty)); | ||
} | ||
|
||
[Fact] | ||
public async Task GetUserByProviderUid() | ||
{ | ||
var handler = new MockMessageHandler() | ||
{ | ||
Response = GetUserResponse, | ||
}; | ||
var auth = this.CreateFirebaseAuth(handler); | ||
|
||
var userRecord = await auth.GetUserByProviderUidAsync("google.com", "google_uid"); | ||
|
||
Assert.Equal("user1", userRecord.Uid); | ||
Assert.Null(userRecord.DisplayName); | ||
Assert.Null(userRecord.Email); | ||
Assert.Null(userRecord.PhoneNumber); | ||
Assert.Null(userRecord.PhotoUrl); | ||
Assert.Equal("firebase", userRecord.ProviderId); | ||
Assert.False(userRecord.Disabled); | ||
Assert.False(userRecord.EmailVerified); | ||
Assert.Equal(UserRecord.UnixEpoch, userRecord.TokensValidAfterTimestamp); | ||
Assert.Empty(userRecord.CustomClaims); | ||
Assert.Empty(userRecord.ProviderData); | ||
Assert.Null(userRecord.UserMetaData.CreationTimestamp); | ||
Assert.Null(userRecord.UserMetaData.LastSignInTimestamp); | ||
|
||
var request = NewtonsoftJsonSerializer.Instance.Deserialize<Dictionary<string, object>>(handler.LastRequestBody); | ||
Assert.Equal(new JArray("{providerId: google.com, rawId: google_uid}"), request["federatedUserId"]); | ||
this.AssertClientVersion(handler.LastRequestHeaders); | ||
} | ||
|
||
[Fact] | ||
public async Task GetUserByProviderUidWithPhoneProvider() | ||
{ | ||
var handler = new MockMessageHandler() | ||
{ | ||
Response = GetUserResponse, | ||
}; | ||
var auth = this.CreateFirebaseAuth(handler); | ||
|
||
var userRecord = await auth.GetUserByProviderUidAsync("phone", " 1234567890"); | ||
|
||
Assert.Equal("user1", userRecord.Uid); | ||
|
||
var request = NewtonsoftJsonSerializer.Instance.Deserialize<Dictionary<string, object>>(handler.LastRequestBody); | ||
Assert.Equal(new JArray(" 1234567890"), request["phoneNumber"]); | ||
Assert.False(request.ContainsKey("federatedUserId")); | ||
this.AssertClientVersion(handler.LastRequestHeaders); | ||
} | ||
|
||
[Fact] | ||
public async Task GetUserByProviderUidWithEmailProvider() | ||
{ | ||
var handler = new MockMessageHandler() | ||
{ | ||
Response = GetUserResponse, | ||
}; | ||
var auth = this.CreateFirebaseAuth(handler); | ||
|
||
var userRecord = await auth.GetUserByProviderUidAsync("email", "[email protected]"); | ||
|
||
Assert.Equal("user1", userRecord.Uid); | ||
|
||
var request = NewtonsoftJsonSerializer.Instance.Deserialize<Dictionary<string, object>>(handler.LastRequestBody); | ||
Assert.Equal(new JArray("[email protected]"), request["email"]); | ||
Assert.False(request.ContainsKey("federatedUserId")); | ||
this.AssertClientVersion(handler.LastRequestHeaders); | ||
} | ||
|
||
[Fact] | ||
public async Task GetUserByProviderUidUserNotFound() | ||
{ | ||
var handler = new MockMessageHandler() | ||
{ | ||
Response = @"{""users"": []}", | ||
}; | ||
var auth = this.CreateFirebaseAuth(handler); | ||
|
||
var exception = await Assert.ThrowsAsync<FirebaseAuthException>( | ||
async () => await auth.GetUserByProviderUidAsync("google.com", "google_uid")); | ||
|
||
Assert.Equal(ErrorCode.NotFound, exception.ErrorCode); | ||
Assert.Equal(AuthErrorCode.UserNotFound, exception.AuthErrorCode); | ||
Assert.Equal("Failed to get user with federated user ID: {providerId: google.com, rawId: google_uid}", exception.Message); | ||
Assert.NotNull(exception.HttpResponse); | ||
Assert.Null(exception.InnerException); | ||
} | ||
|
||
[Fact] | ||
public async Task GetUserByProviderUidNull() | ||
{ | ||
var auth = this.CreateFirebaseAuth(new MockMessageHandler()); | ||
await Assert.ThrowsAsync<ArgumentException>(() => auth.GetUserByProviderUidAsync("google.com", null)); | ||
await Assert.ThrowsAsync<ArgumentException>(() => auth.GetUserByProviderUidAsync(null, "google_uid")); | ||
} | ||
|
||
[Fact] | ||
public async Task GetUserByProviderUidEmpty() | ||
{ | ||
var auth = this.CreateFirebaseAuth(new MockMessageHandler()); | ||
await Assert.ThrowsAsync<ArgumentException>(() => auth.GetUserByProviderUidAsync("google.com", string.Empty)); | ||
await Assert.ThrowsAsync<ArgumentException>(() => auth.GetUserByProviderUidAsync(string.Empty, "google_uid")); | ||
} | ||
|
||
[Fact] | ||
public async Task ListUsers() | ||
{ | ||
|
This file contains 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 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