Пример #1
0
        public async Task CanSetPasswordWithExternalLogin()
        {
            // 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 newClient = server.CreateClient();
            var loginAfterSetPasswordClient = server.CreateClient();

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

            // Act 1
            var index = await UserStories.RegisterNewUserWithSocialLoginAsync(client, userName, email);

            index = await UserStories.LoginWithSocialLoginAsync(newClient, userName);

            // Assert 1
            Assert.NotNull(principals[1].Identities.Single().Claims.Single(c => c.Type == ClaimTypes.AuthenticationMethod).Value);

            // Act 2
            await UserStories.SetPasswordAsync(index, "!Test.Password2");

            // Assert 2
            // RefreshSignIn uses the same AuthenticationMethod claim value
            AssertClaimsEqual(principals[1], principals[2], ClaimTypes.AuthenticationMethod);

            // Act & Assert 3
            // Can log in with the password set above
            await UserStories.LoginExistingUserAsync(loginAfterSetPasswordClient, email, "!Test.Password2");
        }