Exemplo n.º 1
0
        public async Task CanLogInAfterConfirmingEmail()
        {
            using (StartLog(out var loggerFactory))
            {
                // Arrange
                var emailSender = new ContosoEmailSender();
                var server      = ServerFactory.CreateServer(loggerFactory, builder =>
                {
                    builder.ConfigureServices(services => services
                                              .SetupTestEmailSender(emailSender)
                                              .SetupEmailRequired());
                });

                var client    = ServerFactory.CreateDefaultClient(server);
                var newClient = ServerFactory.CreateDefaultClient(server);

                var userName = $"{Guid.NewGuid()}@example.com";
                var password = $"!Test.Password1$";

                var loggedIn = await UserStories.RegisterNewUserAsync(client, userName, password);

                // Act & Assert
                // Use a new client to simulate a new browser session.
                var email = Assert.Single(emailSender.SentEmails);
                await UserStories.ConfirmEmailAsync(email, newClient);

                await UserStories.LoginExistingUserAsync(newClient, userName, password);
            }
        }
Exemplo n.º 2
0
        public async Task CanLogInAfterResettingThePassword()
        {
            using (StartLog(out var loggerFactory))
            {
                // Arrange
                var emailSender = new ContosoEmailSender();
                var server      = ServerFactory.CreateServer(loggerFactory, b => b.ConfigureServices(s =>
                                                                                                     s.SetupTestEmailSender(emailSender)));
                var client = ServerFactory.CreateDefaultClient(server);
                var resetPasswordClient = ServerFactory.CreateDefaultClient(server);
                var newClient           = ServerFactory.CreateDefaultClient(server);

                var userName    = $"{Guid.NewGuid()}@example.com";
                var password    = $"!Test.Password1$";
                var newPassword = $"!New.Password1$";

                await UserStories.RegisterNewUserAsync(client, userName, password);

                var registrationEmail = Assert.Single(emailSender.SentEmails);
                await UserStories.ConfirmEmailAsync(registrationEmail, client);

                // Act & Assert
                await UserStories.ForgotPasswordAsync(resetPasswordClient, userName);

                Assert.Equal(2, emailSender.SentEmails.Count);
                var email = emailSender.SentEmails[1];
                await UserStories.ResetPasswordAsync(resetPasswordClient, email, userName, newPassword);

                await UserStories.LoginExistingUserAsync(newClient, userName, newPassword);
            }
        }
Exemplo n.º 3
0
        public async Task CannotLogInWithoutRequiredEmailConfirmation()
        {
            using (StartLog(out var loggerFactory))
            {
                // Arrange
                var emailSender = new ContosoEmailSender();
                var server      = ServerFactory.CreateServer(loggerFactory, builder =>
                {
                    builder.ConfigureServices(services => services
                                              .SetupTestEmailSender(emailSender)
                                              .SetupEmailRequired());
                });

                var client    = ServerFactory.CreateDefaultClient(server);
                var newClient = ServerFactory.CreateDefaultClient(server);

                var userName = $"{Guid.NewGuid()}@example.com";
                var password = $"!Test.Password1$";

                var loggedIn = await UserStories.RegisterNewUserAsync(client, userName, password);

                // Act & Assert
                // Use a new client to simulate a new browser session.
                await Assert.ThrowsAnyAsync <XunitException>(() => UserStories.LoginExistingUserAsync(newClient, userName, password));
            }
        }
Exemplo n.º 4
0
        public async Task CanRegisterWithASocialLoginProviderFromLoginWithConfirmationAndRealEmailSender()
        {
            // Arrange
            var emailSender = new ContosoEmailSender();

            void ConfigureTestServices(IServiceCollection services)
            {
                services.SetupTestEmailSender(emailSender);
                services
                .Configure <IdentityOptions>(o => o.SignIn.RequireConfirmedAccount = true)
                .SetupTestThirdPartyLogin();
            }

            var client = ServerFactory
                         .WithWebHostBuilder(whb => whb.ConfigureServices(ConfigureTestServices))
                         .CreateClient();

            var guid     = Guid.NewGuid();
            var userName = $"{guid}";
            var email    = $"{guid}@example.com";

            // Act & Assert
            await UserStories.RegisterNewUserWithSocialLoginWithConfirmationAsync(client, userName, email, hasRealEmailSender : true);

            Assert.Single(emailSender.SentEmails);
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        public async Task CanLogInWithTwoFactorAuthentication_WithGlobalAuthorizeFilter()
        {
            // Arrange
            void ConfigureTestServices(IServiceCollection services) =>
            services.SetupGlobalAuthorizeFilter();

            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 loggedIn = await UserStories.RegisterNewUserAsync(client, userName, password);

            var showRecoveryCodes = await UserStories.EnableTwoFactorAuthentication(loggedIn);

            var twoFactorKey = showRecoveryCodes.Context.AuthenticatorKey;

            // Act & Assert
            // Use a new client to simulate a new browser session.
            await UserStories.LoginExistingUser2FaAsync(newClient, userName, password, twoFactorKey);
        }
Exemplo n.º 7
0
        public async Task CanResetPassword_WithGlobalAuthorizeFilter()
        {
            // Arrange
            var emailSender = new ContosoEmailSender();

            void ConfigureTestServices(IServiceCollection services) =>
            services.SetupGlobalAuthorizeFilter().SetupTestEmailSender(emailSender);

            var server = ServerFactory.WithWebHostBuilder(whb => whb.ConfigureServices(ConfigureTestServices));

            var client = server.CreateClient();
            var resetPasswordClient = server.CreateClient();
            var newClient           = server.CreateClient();

            var userName    = $"{Guid.NewGuid()}@example.com";
            var password    = $"[PLACEHOLDER]-1a";
            var newPassword = $"[PLACEHOLDER]-1a-updated";

            await UserStories.RegisterNewUserAsync(client, userName, password);

            var registrationEmail = Assert.Single(emailSender.SentEmails);
            await UserStories.ConfirmEmailAsync(registrationEmail, client);

            // Act & Assert
            await UserStories.ForgotPasswordAsync(resetPasswordClient, userName);

            Assert.Equal(2, emailSender.SentEmails.Count);
            var email = emailSender.SentEmails[1];
            await UserStories.ResetPasswordAsync(resetPasswordClient, email, userName, newPassword);

            await UserStories.LoginExistingUserAsync(newClient, userName, newPassword);
        }
Exemplo n.º 8
0
        public async Task CanResendConfirmingEmail()
        {
            // Arrange
            var emailSender = new ContosoEmailSender();

            void ConfigureTestServices(IServiceCollection services) => services
            .SetupTestEmailSender(emailSender)
            .SetupEmailRequired();

            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 loggedIn = await UserStories.RegisterNewUserAsync(client, userName, password);

            // Act & Assert
            // Use a new client to simulate a new browser session.
            await UserStories.ResendConfirmEmailAsync(server.CreateClient(), userName);

            Assert.Equal(2, emailSender.SentEmails.Count);
            var email = emailSender.SentEmails.Last();
            await UserStories.ConfirmEmailAsync(email, newClient);
        }
Exemplo n.º 9
0
        public async Task CanChangePassword()
        {
            // Arrange
            var principals = new List <ClaimsPrincipal>();

            void ConfigureTestServices(IServiceCollection services) =>
            services.SetupGetUserClaimsPrincipal(user => principals.Add(user), IdentityConstants.ApplicationScheme);

            var server = ServerFactory
                         .WithWebHostBuilder(whb => whb.ConfigureTestServices(ConfigureTestServices));

            var client    = server.CreateClient();
            var newClient = server.CreateClient();

            var userName = $"{Guid.NewGuid()}@example.com";
            var password = "******";

            var index = await UserStories.RegisterNewUserAsync(client, userName, password);

            // Act 1
            var changedPassword = await UserStories.ChangePasswordAsync(index, "!Test.Password1", "!Test.Password2");

            // Assert 1
            // RefreshSignIn generates a new security stamp claim
            AssertClaimsNotEqual(principals[0], principals[1], "AspNet.Identity.SecurityStamp");

            // Act 2
            await UserStories.LoginExistingUserAsync(newClient, userName, "!Test.Password2");

            // Assert 2
            // Signing in again with a different client uses the same security stamp claim
            AssertClaimsEqual(principals[1], principals[2], "AspNet.Identity.SecurityStamp");
        }
Exemplo n.º 10
0
        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);
        }
Exemplo n.º 11
0
        public async Task CanLogInAfterResettingThePassword()
        {
            // Arrange
            var emailSender = new ContosoEmailSender();

            void ConfigureTestServices(IServiceCollection services) => services
            .SetupTestEmailSender(emailSender);

            var server = ServerFactory.WithWebHostBuilder(whb => whb.ConfigureServices(ConfigureTestServices));

            ServerFactory.EnsureDatabaseCreated();

            var client = server.CreateClient();
            var resetPasswordClient = server.CreateClient();
            var newClient           = server.CreateClient();

            var userName    = $"{Guid.NewGuid()}@example.com";
            var password    = $"!Test.Password1$";
            var newPassword = $"!New.Password1$";

            await UserStories.RegisterNewUserAsync(client, userName, password);

            var registrationEmail = Assert.Single(emailSender.SentEmails);
            await UserStories.ConfirmEmailAsync(registrationEmail, client);

            // Act & Assert
            await UserStories.ForgotPasswordAsync(resetPasswordClient, userName);

            Assert.Equal(2, emailSender.SentEmails.Count);
            var email = emailSender.SentEmails[1];
            await UserStories.ResetPasswordAsync(resetPasswordClient, email, userName, newPassword);

            await UserStories.LoginExistingUserAsync(newClient, userName, newPassword);
        }
Exemplo n.º 12
0
        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);
        }
Exemplo n.º 13
0
        public async Task CanRemoveExternalLogin()
        {
            // Arrange
            var principals = new List <ClaimsPrincipal>();

            void ConfigureTestServices(IServiceCollection services) =>
            services
            .SetupTestThirdPartyLogin()
            .SetupGetUserClaimsPrincipal(user => principals.Add(user), IdentityConstants.ApplicationScheme);

            var server = ServerFactory
                         .WithWebHostBuilder(whb => whb.ConfigureTestServices(ConfigureTestServices));

            var client = server.CreateClient();

            var guid     = Guid.NewGuid();
            var userName = $"{guid}";
            var email    = $"{guid}@example.com";

            // Act
            var index = await UserStories.RegisterNewUserAsync(client, email, "!TestPassword1");

            var linkLogin = await UserStories.LinkExternalLoginAsync(index, email);

            await UserStories.RemoveExternalLoginAsync(linkLogin, email);

            // RefreshSignIn generates a new security stamp claim
            AssertClaimsNotEqual(principals[0], principals[1], "AspNet.Identity.SecurityStamp");
        }
Exemplo n.º 14
0
        public async Task CanResetAuthenticator()
        {
            using (StartLog(out var loggerFactory))
            {
                // Arrange
                var principals = new List <ClaimsPrincipal>();
                var server     = ServerFactory.CreateServer(loggerFactory, builder =>
                                                            builder.ConfigureTestServices(s => s.SetupTestThirdPartyLogin()
                                                                                          .SetupGetUserClaimsPrincipal(user => principals.Add(user), IdentityConstants.ApplicationScheme)));

                var client    = ServerFactory.CreateDefaultClient(server);
                var newClient = ServerFactory.CreateDefaultClient(server);

                var userName = $"{Guid.NewGuid()}@example.com";
                var password = $"!Test.Password1$";

                // Act
                var loggedIn = await UserStories.RegisterNewUserAsync(client, userName, password);

                var showRecoveryCodes = await UserStories.EnableTwoFactorAuthentication(loggedIn);

                var twoFactorKey = showRecoveryCodes.Context.AuthenticatorKey;

                // Use a new client to simulate a new browser session.
                var index = await UserStories.LoginExistingUser2FaAsync(newClient, userName, password, twoFactorKey);

                await UserStories.ResetAuthenticator(index);

                // RefreshSignIn generates a new security stamp claim
                AssertClaimsNotEqual(principals[1], principals[2], "AspNet.Identity.SecurityStamp");
            }
        }
Exemplo n.º 15
0
        public async Task CanSeeExternalLoginProviderDisplayName()
        {
            // Arrange
            void ConfigureTestServices(IServiceCollection services) => services.SetupTestThirdPartyLogin();

            var server = ServerFactory
                         .WithWebHostBuilder(whb => whb.ConfigureTestServices(ConfigureTestServices));

            var client = server.CreateClient();

            // Act
            var userName = Guid.NewGuid().ToString();
            var email    = $"{userName}@example.com";
            var index    = await UserStories.RegisterNewUserWithSocialLoginAsync(client, userName, email);

            var manage = await index.ClickManageLinkWithExternalLoginAsync();

            var externalLogins = await manage.ClickExternalLoginsAsync();

            // Assert
            var title     = externalLogins.Document.GetElementsByTagName("h4").FirstOrDefault(e => e.TextContent == "Registered Logins");
            var table     = title?.NextElementSibling as IHtmlTableElement;
            var firstCell = table?.Bodies?.FirstOrDefault()?.Rows.FirstOrDefault()?.Cells?.FirstOrDefault();

            Assert.Equal("Contoso auth", firstCell?.TextContent);
        }
Exemplo n.º 16
0
        public async Task CanLogInAfterConfirmingEmail()
        {
            // Arrange
            TestEmailSender testEmailSender = new TestEmailSender();
            var             server          = ServerFactory.CreateServer(builder =>
            {
                builder.ConfigureServices(services => services
                                          .AddSingleton <IEmailSender>(testEmailSender)
                                          .Configure <IdentityOptions>(opt => opt.SignIn.RequireConfirmedEmail = true));
            });

            var client    = ServerFactory.CreateDefaultClient(server);
            var newClient = ServerFactory.CreateDefaultClient(server);

            var userName = $"{Guid.NewGuid()}@example.com";
            var password = $"!Test.Password1$";

            var loggedIn = await UserStories.RegisterNewUserAsync(client, userName, password);

            // Act & Assert
            // Use a new client to simulate a new browser session.
            var emailBody   = HtmlAssert.IsHtmlFragment(testEmailSender.HtmlMessage);
            var linkElement = HtmlAssert.HasElement("a", emailBody);
            var link        = Assert.IsAssignableFrom <IHtmlAnchorElement>(linkElement);
            var response    = await newClient.GetAsync(link.Href);

            await UserStories.LoginExistingUserAsync(newClient, userName, password);
        }
Exemplo n.º 17
0
        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);
        }
Exemplo n.º 18
0
        public async Task CanLogInAfterConfirmingEmail_WithGlobalAuthorizeFilter()
        {
            // Arrange
            var emailSender = new ContosoEmailSender();

            void ConfigureTestServices(IServiceCollection services) => services
            .SetupTestEmailSender(emailSender)
            .SetupEmailRequired()
            .SetupGlobalAuthorizeFilter();

            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 loggedIn = await UserStories.RegisterNewUserAsync(client, userName, password);

            // Act & Assert
            // Use a new client to simulate a new browser session.
            var email = Assert.Single(emailSender.SentEmails);
            await UserStories.ConfirmEmailAsync(email, newClient);

            await UserStories.LoginExistingUserAsync(newClient, userName, password);
        }
Exemplo n.º 19
0
        public async Task CanDownloadPersonalData(bool twoFactor, bool social)
        {
            // Arrange
            void ConfigureTestServices(IServiceCollection services) =>
            services.SetupTestThirdPartyLogin();

            var client = ServerFactory
                         .WithWebHostBuilder(whb => whb.ConfigureTestServices(ConfigureTestServices))
                         .CreateClient();

            var userName = $"{Guid.NewGuid()}@example.com";
            var guid     = Guid.NewGuid();
            var email    = userName;

            var index = social
                ? await UserStories.RegisterNewUserWithSocialLoginAsync(client, userName, email)
                : await UserStories.RegisterNewUserAsync(client, email, "!TestPassword1");

            if (twoFactor)
            {
                await UserStories.EnableTwoFactorAuthentication(index);
            }

            // Act & Assert
            var jsonData = await UserStories.DownloadPersonalData(index, userName);

            Assert.NotNull(jsonData);
            Assert.True(jsonData.ContainsKey("Id"));
            Assert.NotNull(jsonData["Id"]);
            Assert.True(jsonData.ContainsKey("UserName"));
            Assert.Equal(userName, (string)jsonData["UserName"]);
            Assert.True(jsonData.ContainsKey("Email"));
            Assert.Equal(userName, (string)jsonData["Email"]);
            Assert.True(jsonData.ContainsKey("EmailConfirmed"));
            Assert.False((bool)jsonData["EmailConfirmed"]);
            Assert.True(jsonData.ContainsKey("PhoneNumber"));
            Assert.Equal("null", (string)jsonData["PhoneNumber"]);
            Assert.True(jsonData.ContainsKey("PhoneNumberConfirmed"));
            Assert.False((bool)jsonData["PhoneNumberConfirmed"]);
            Assert.Equal(twoFactor, (bool)jsonData["TwoFactorEnabled"]);

            if (twoFactor)
            {
                Assert.NotNull(jsonData["Authenticator Key"]);
            }
            else
            {
                Assert.Null((string)jsonData["Authenticator Key"]);
            }

            if (social)
            {
                Assert.Equal(userName, (string)jsonData["Contoso external login provider key"]);
            }
            else
            {
                Assert.Null((string)jsonData["Contoso external login provider key"]);
            }
        }
Exemplo n.º 20
0
        public async Task CanRegisterAUser()
        {
            // Arrange
            var client = ServerFactory.CreateDefaultClient();

            var userName = $"{Guid.NewGuid()}@example.com";
            var password = $"!Test.Password1$";

            // Act & Assert
            await UserStories.RegisterNewUserAsync(client, userName, password);
        }
Exemplo n.º 21
0
        public async Task AuthenticatedUserCanAccessAuthorizedPages(string url)
        {
            // Arrange
            var client = ServerFactory.CreateDefaultClient();
            await UserStories.RegisterNewUserAsync(client);

            // Act
            var response = await client.GetAsync(url);

            // Assert
            await ResponseAssert.IsHtmlDocumentAsync(response);
        }
Exemplo n.º 22
0
        public async Task CanEnableTwoFactorAuthentication()
        {
            // Arrange
            var client = ServerFactory.CreateDefaultClient();

            var userName = $"{Guid.NewGuid()}@example.com";
            var password = $"!Test.Password1$";

            var index = await UserStories.RegisterNewUserAsync(client, userName, password);

            // Act & Assert
            await UserStories.EnableTwoFactorAuthentication(index, twoFactorEnabled : false);
        }
Exemplo n.º 23
0
        public async Task CanRegisterWithASocialLoginProvider()
        {
            // Arrange
            var server = ServerFactory.CreateServer(builder =>
                                                    builder.ConfigureServices(services => services.SetupTestThirdPartyLogin()));
            var client = ServerFactory.CreateDefaultClient(server);

            var guid     = Guid.NewGuid();
            var userName = $"{guid}";
            var email    = $"{guid}@example.com";

            // Act & Assert
            await UserStories.RegisterNewUserWithSocialLoginAsync(client, userName, email);
        }
Exemplo n.º 24
0
        public async Task CannotEnableTwoFactorAuthenticationWithoutCookieConsent()
        {
            // Arrange
            var client = ServerFactory
                         .CreateClient();

            var userName = $"{Guid.NewGuid()}@example.com";
            var password = $"!Test.Password1$";

            var index = await UserStories.RegisterNewUserAsync(client, userName, password);

            // Act & Assert
            Assert.Null(await UserStories.EnableTwoFactorAuthentication(index, consent: false));
        }
Exemplo n.º 25
0
        public async Task GetOnDownloadPersonalData_ReturnsNotFound()
        {
            // Arrange
            var client = ServerFactory
                         .CreateClient();

            await UserStories.RegisterNewUserAsync(client);

            // Act
            var response = await client.GetAsync("/Identity/Account/Manage/DownloadPersonalData");

            // Assert
            Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
        }
Exemplo n.º 26
0
        public async Task CanEnableTwoFactorAuthentication()
        {
            // Arrange
            var client = ServerFactory
                         .CreateClient();

            var userName = $"{Guid.NewGuid()}@example.com";
            var password = $"[PLACEHOLDER]-1a";

            var index = await UserStories.RegisterNewUserAsync(client, userName, password);

            // Act & Assert
            Assert.NotNull(await UserStories.EnableTwoFactorAuthentication(index));
        }
Exemplo n.º 27
0
        public async Task CanDeleteUser()
        {
            // Arrange
            var client = ServerFactory
                         .CreateClient();

            var userName = $"{Guid.NewGuid()}@example.com";
            var password = $"[PLACEHOLDER]-1a";

            var index = await UserStories.RegisterNewUserAsync(client, userName, password);

            // Act & Assert
            await UserStories.DeleteUser(index, password);
        }
Exemplo n.º 28
0
        public async Task AuthenticatedUserCanAccessAuthorizedPages(string url)
        {
            using (StartLog(out var loggerFactory, $"{nameof(AuthenticatedUserCanAccessAuthorizedPages)}_{WebUtility.UrlEncode(url)}"))
            {
                // Arrange
                var client = ServerFactory.CreateDefaultClient(loggerFactory);
                await UserStories.RegisterNewUserAsync(client);

                // Act
                var response = await client.GetAsync(url);

                // Assert
                await ResponseAssert.IsHtmlDocumentAsync(response);
            }
        }
Exemplo n.º 29
0
        public async Task CanLogInWithAPreviouslyRegisteredUser()
        {
            // Arrange
            var client    = ServerFactory.CreateClient();
            var newClient = ServerFactory.CreateClient();

            var userName = $"{Guid.NewGuid()}@example.com";
            var password = $"[PLACEHOLDER]-1a";

            // Act & Assert
            await UserStories.RegisterNewUserAsync(client, userName, password);

            // Use a new client to simulate a new browser session.
            await UserStories.LoginExistingUserAsync(newClient, userName, password);
        }
Exemplo n.º 30
0
        public async Task CanRegisterAUser_WithGlobalAuthorizeFilter()
        {
            // Arrange
            void ConfigureTestServices(IServiceCollection services) =>
            services.SetupGlobalAuthorizeFilter();

            var client = ServerFactory
                         .WithWebHostBuilder(whb => whb.ConfigureServices(ConfigureTestServices))
                         .CreateClient();

            var userName = $"{Guid.NewGuid()}@example.com";
            var password = $"!Test.Password1$";

            // Act & Assert
            await UserStories.RegisterNewUserAsync(client, userName, password);
        }