public async Task CanRegisterAUserWithRequiredConfirmation() { // Arrange void ConfigureTestServices(IServiceCollection services) { services.Configure <IdentityOptions>(o => o.SignIn.RequireConfirmedAccount = true); }; var server = ServerFactory .WithWebHostBuilder(whb => whb.ConfigureServices(ConfigureTestServices)); var client = server.CreateClient(); var client2 = server.CreateClient(); var userName = $"{Guid.NewGuid()}@example.com"; var password = $"!Test.Password1$"; // Act & Assert var register = await UserStories.RegisterNewUserAsyncWithConfirmation(client, userName, password); // Since we aren't confirmed yet, login should fail until we confirm await UserStories.LoginFailsWithWrongPasswordAsync(client, userName, password); await register.ClickConfirmLinkAsync(); await UserStories.LoginExistingUserAsync(client, userName, password); }
public async Task CanChangeEmail() { // Arrange var emails = new ContosoEmailSender(); void ConfigureTestServices(IServiceCollection services) => services.SetupTestEmailSender(emails); var server = ServerFactory .WithWebHostBuilder(whb => whb.ConfigureServices(ConfigureTestServices)); var client = server.CreateClient(); var newClient = server.CreateClient(); var failedClient = server.CreateClient(); var userName = $"{Guid.NewGuid()}@example.com"; var password = $"[PLACEHOLDER]-1a"; var newEmail = "*****@*****.**"; var index = await UserStories.RegisterNewUserAsync(client, userName, password); var email = await UserStories.SendUpdateEmailAsync(index, newEmail); // Act & Assert Assert.Equal(2, emails.SentEmails.Count); await UserStories.ConfirmEmailAsync(emails.SentEmails[1], client); // Verify can login with new email, fails with old await UserStories.LoginExistingUserAsync(newClient, newEmail, password); await UserStories.LoginFailsWithWrongPasswordAsync(failedClient, userName, password); }
public async Task UserNotLockedOut_AfterMaxFailedAccessAttempts_WithGlobalAuthorizeFilter() { // Arrange var emailSender = new ContosoEmailSender(); void ConfigureTestServices(IServiceCollection services) => services.SetupGlobalAuthorizeFilter().SetupMaxFailedAccessAttempts().SetupTestEmailSender(emailSender); var server = ServerFactory.WithWebHostBuilder(whb => whb.ConfigureServices(ConfigureTestServices)); var client = server.CreateClient(); var newClient = server.CreateClient(); var userName = $"{Guid.NewGuid()}@example.com"; var password = $"[PLACEHOLDER]-1a"; var wrongPassword = $"[PLACEHOLDER]-1a-wrong"; await UserStories.RegisterNewUserAsync(client, userName, password); var registrationEmail = Assert.Single(emailSender.SentEmails); await UserStories.ConfirmEmailAsync(registrationEmail, client); // Act & Assert await UserStories.LoginFailsWithWrongPasswordAsync(newClient, userName, wrongPassword); }
public async Task RegisterWithRealConfirmationDoesNotShowLink() { // Arrange void ConfigureTestServices(IServiceCollection services) { services.Configure <IdentityOptions>(o => o.SignIn.RequireConfirmedAccount = true); services.AddSingleton <IEmailSender, FakeEmailSender>(); }; var server = ServerFactory .WithWebHostBuilder(whb => whb.ConfigureServices(ConfigureTestServices)); var client = server.CreateClient(); var client2 = server.CreateClient(); ServerFactory.EnsureDatabaseCreated(); var userName = $"{Guid.NewGuid()}@example.com"; var password = $"!Test.Password1$"; // Act & Assert var register = await UserStories.RegisterNewUserAsyncWithConfirmation(client, userName, password, hasRealEmailSender : true); // Since we aren't confirmed yet, login should fail until we confirm await UserStories.LoginFailsWithWrongPasswordAsync(client, userName, password); }