示例#1
0
            public void ThrowsIfUserPasswordNotSet()
            {
                var repository = new InMemoryRepository();
                repository.Add(new ChatUser
                {
                    Name = "SomeUser"
                });
                var service = new MembershipService(repository, new Mock<ICryptoService>().Object);

                ChatUser user;
                Assert.False(service.TryAuthenticateUser("SomeUser", "password", out user));
            }
示例#2
0
            public void ThrowsIfUserPasswordDoesNotMatch()
            {
                var repository = new InMemoryRepository();
                repository.Add(new ChatUser
                {
                    Name = "SomeUser",
                    Salt = "salt",
                    HashedPassword = "******".ToSha256("salt")
                });
                var service = new MembershipService(repository, new Mock<ICryptoService>().Object);

                ChatUser user;
                Assert.False(service.TryAuthenticateUser("SomeUser", "foo", out user));
            }
示例#3
0
            public void ThrowsIfUserDoesNotExist()
            {
                var repository = new InMemoryRepository();
                var service = new MembershipService(repository, new Mock<ICryptoService>().Object);

                ChatUser user;
                Assert.False(service.TryAuthenticateUser("SomeUser", "foo", out user));
            }
示例#4
0
            public void EnsuresStoredPasswordIsSalted()
            {
                var crypto = new Mock<ICryptoService>();
                crypto.Setup(c => c.CreateSalt()).Returns("salted");
                var repository = new InMemoryRepository();
                var user = new ChatUser
                {
                    Name = "foo",
                    HashedPassword = "******"
                };
                repository.Add(user);
                var service = new MembershipService(repository, crypto.Object);

                Assert.True(service.TryAuthenticateUser("foo", "passwords", out user));

                Assert.Equal("salted", user.Salt);
                Assert.Equal("9ce70d2ab42c9a9012ed6f80f85ab400ef1483f70e227a42b6d77faea204db26", user.HashedPassword);
            }
示例#5
0
 public void DoesNotThrowIfSaltedPasswordsMatch()
 {
     var repository = new InMemoryRepository();
     repository.Add(new ChatUser
     {
         Name = "foo",
         Salt = "salted",
         HashedPassword = "******"
     });
     var service = new MembershipService(repository, new Mock<ICryptoService>().Object);
     ChatUser user;
     Assert.True(service.TryAuthenticateUser("foo", "password", out user));
 }
示例#6
0
 public void DoesNotThrowIfPasswordsMatch()
 {
     var repository = new InMemoryRepository();
     repository.Add(new ChatUser
     {
         Name = "foo",
         HashedPassword = "******"
     });
     var service = new MembershipService(repository, new Mock<ICryptoService>().Object);
     ChatUser user;
     Assert.True(service.TryAuthenticateUser("foo", "passwords", out user));
 }