-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added RetryCustomConfirmationAsync (#3468)
- Loading branch information
Showing
7 changed files
with
108 additions
and
3 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
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
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 |
---|---|---|
|
@@ -399,6 +399,42 @@ public void User_LinkCredentials_WhenInUse_Throws() | |
}); | ||
} | ||
|
||
[Test] | ||
public void User_RetryCustomConfirmationAsync_WorksInAllScenarios() | ||
{ | ||
SyncTestHelpers.RunBaasTestAsync(async () => | ||
{ | ||
// Standard case | ||
var unconfirmedMail = SyncTestHelpers.GetUnconfirmedUsername(); | ||
var credentials = Credentials.EmailPassword(unconfirmedMail, SyncTestHelpers.DefaultPassword); | ||
|
||
// The first time the confirmation function is called we return "pending", so the user needs to be confirmed. | ||
// At the same time we save the user email in a collection. | ||
await DefaultApp.EmailPasswordAuth.RegisterUserAsync(unconfirmedMail, SyncTestHelpers.DefaultPassword).Timeout(10_000, detail: "Failed to register user"); | ||
|
||
var ex3 = await TestHelpers.AssertThrows<AppException>(() => DefaultApp.LogInAsync(credentials)); | ||
Assert.That(ex3.Message, Does.Contain("confirmation required")); | ||
|
||
// The second time we call the confirmation function we find the email we saved in the collection and return "success", so the user | ||
// gets confirmed and can log in. | ||
await DefaultApp.EmailPasswordAuth.RetryCustomConfirmationAsync(unconfirmedMail); | ||
var user = await DefaultApp.LogInAsync(credentials); | ||
Assert.That(user.State, Is.EqualTo(UserState.LoggedIn)); | ||
|
||
// Logged in user case | ||
var loggedInUser = await GetUserAsync(); | ||
var ex = await TestHelpers.AssertThrows<AppException>(() => DefaultApp.EmailPasswordAuth.RetryCustomConfirmationAsync(loggedInUser.Profile.Email!)); | ||
Assert.That(ex.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest)); | ||
Assert.That(ex.Message, Does.Contain("already confirmed")); | ||
|
||
// Unknown user case | ||
var invalidEmail = "[email protected]"; | ||
var ex2 = await TestHelpers.AssertThrows<AppException>(() => DefaultApp.EmailPasswordAuth.RetryCustomConfirmationAsync(invalidEmail)); | ||
Assert.That(ex2.StatusCode, Is.EqualTo(HttpStatusCode.NotFound)); | ||
Assert.That(ex2.Message, Does.Contain("user not found")); | ||
}); | ||
} | ||
|
||
[Test] | ||
public void User_JWT_LogsInAndReadsDataFromToken() | ||
{ | ||
|
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