backend + web: Improve validation and email retry handling
This commit is contained in:
1 parent
e9782a1413
commit
722d318898
13 files changed
+195
-44
No files matched your search
@@ -19,6 +19,32 @@ public sealed class EmailConfirmationTests(BackendFixture fixture) : IClassFixtu
|
||||
private const string Confirm = "/api/v1/auth/confirm-email";
|
||||
private const string Login = "/api/v1/auth/login";
|
||||
|
||||
[Fact]
|
||||
public async Task FailedRegistrationEmailCanBeRetriedForTheSameAccount()
|
||||
{
|
||||
using var anonymous = fixture.CreateClient();
|
||||
const string address = "[email protected]";
|
||||
var request = new RegisterRequest(address, "Jan", "Novák");
|
||||
fixture.FailNextEmail(address, "SMTP_UNAVAILABLE", retryable: true);
|
||||
|
||||
var failure = await ReadAsync<ProblemDetails>(anonymous.PostAsJsonAsync(Register, request, Cancellation),
|
||||
HttpStatusCode.ServiceUnavailable);
|
||||
Assert.Equal("urn:ntbug:email-delivery-failed", failure.Type);
|
||||
|
||||
await using var scope = fixture.Services.CreateAsyncScope();
|
||||
var db = scope.ServiceProvider.GetRequiredService<HelpdeskDbContext>();
|
||||
var pending = await db.Users.AsNoTracking().SingleAsync(user => user.Email == address, Cancellation);
|
||||
Assert.False(pending.EmailConfirmed);
|
||||
Assert.Empty(pending.PasswordHash);
|
||||
|
||||
var retried = await ReadAsync<UserDto>(anonymous.PostAsJsonAsync(Register, request, Cancellation), HttpStatusCode.Created);
|
||||
Assert.Equal(pending.Id, retried.Id);
|
||||
var token = await fixture.TakeConfirmationTokenAsync(address);
|
||||
await ExpectAsync(anonymous.PostAsJsonAsync(Confirm, new ConfirmEmailRequest(token, Password), Cancellation),
|
||||
HttpStatusCode.NoContent);
|
||||
Assert.Equal(pending.Id, (await LoginAsync(anonymous, address)).User.Id);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RegistrationHasNoPasswordUntilTheMailboxOwnerSetsIt()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user