Esempio n. 1
0
            public void WillSaveTheNewUserAsConfirmedWhenConfigured()
            {
                var userService = new TestableUserService();

                userService.MockConfig
                .Setup(x => x.ConfirmEmailAddresses)
                .Returns(false);

                userService.MockCrypto
                .Setup(x => x.GenerateSaltedHash(It.IsAny <string>(), It.IsAny <string>()))
                .Returns("theHashedPassword");

                userService.Create(
                    "theUsername",
                    "thePassword",
                    "theEmailAddress");

                userService.MockUserRepository
                .Verify(x => x.InsertOnCommit(
                            It.Is <User>(
                                u =>
                                u.Username == "theUsername" &&
                                u.HashedPassword == "theHashedPassword" &&
                                u.Confirmed)));
                userService.MockUserRepository
                .Verify(x => x.CommitChanges());
            }
Esempio n. 2
0
            public void SetsAnApiKey()
            {
                var userService = new TestableUserService();

                var user = userService.Create(
                    "theUsername",
                    "thePassword",
                    "theEmailAddress");

                Assert.NotEqual(Guid.Empty, user.ApiKey);
            }
Esempio n. 3
0
            public void WillHashThePassword()
            {
                var userService = new TestableUserService();

                var user = userService.Create(
                    "theUsername",
                    "thePassword",
                    "theEmailAddress");

                Assert.Equal("PBKDF2", user.PasswordHashAlgorithm);
                Assert.True(VerifyPasswordHash(user, "thePassword"));
            }
Esempio n. 4
0
            public void SetsAConfirmationToken()
            {
                var userService = new TestableUserService();

                var user = userService.Create(
                    "theUsername",
                    "thePassword",
                    "theEmailAddress");

                Assert.NotEmpty(user.EmailConfirmationToken);
                Assert.False(user.Confirmed);
            }
Esempio n. 5
0
            public void SetsCreatedDate()
            {
                var userService = new TestableUserService();

                var user = userService.Create(
                    "theUsername",
                    "thePassword",
                    "theEmailAddress");

                Assert.NotNull(user.CreatedUtc);

                // Allow for up to 5 secs of time to have elapsed between Create call and now. Should be plenty
                Assert.True((DateTime.UtcNow - user.CreatedUtc) < TimeSpan.FromSeconds(5));
            }
Esempio n. 6
0
            public void SetsTheUserToConfirmedWhenEmailConfirmationIsNotEnabled()
            {
                var userService = new TestableUserService();

                userService.MockConfig
                .Setup(x => x.ConfirmEmailAddresses)
                .Returns(false);

                var user = userService.Create(
                    "theUsername",
                    "thePassword",
                    "theEmailAddress");

                Assert.Equal(true, user.Confirmed);
            }
Esempio n. 7
0
            public void WillHashThePassword()
            {
                var userService = new TestableUserService();

                userService.MockCrypto
                .Setup(x => x.GenerateSaltedHash("thePassword", It.IsAny <string>()))
                .Returns("theHashedPassword");

                var user = userService.Create(
                    "theUsername",
                    "thePassword",
                    "theEmailAddress");

                Assert.Equal("theHashedPassword", user.HashedPassword);
            }
Esempio n. 8
0
            public void SetsAConfirmationToken()
            {
                var userService = new TestableUserService();

                userService.MockCrypto
                .Setup(c => c.GenerateToken())
                .Returns("secret!");

                var user = userService.Create(
                    "theUsername",
                    "thePassword",
                    "theEmailAddress");

                Assert.Equal("secret!", user.EmailConfirmationToken);
                Assert.False(user.Confirmed);
            }
Esempio n. 9
0
            public void WillSaveTheNewUser()
            {
                var userService = new TestableUserService();


                userService.Create(
                    "theUsername",
                    "thePassword",
                    "theEmailAddress");

                userService.MockUserRepository
                .Verify(x => x.InsertOnCommit(
                            It.Is <User>(
                                u =>
                                u.Username == "theUsername" &&
                                u.UnconfirmedEmailAddress == "theEmailAddress")));
                userService.MockUserRepository
                .Verify(x => x.CommitChanges());
            }
Esempio n. 10
0
            public void SetsAConfirmationToken()
            {
                var userService = new TestableUserService();

                var user = userService.Create(
                    "theUsername",
                    "thePassword",
                    "theEmailAddress");

                Assert.NotEmpty(user.EmailConfirmationToken);
                Assert.False(user.Confirmed);
            }
Esempio n. 11
0
            public void WillHashThePassword()
            {
                var userService = new TestableUserService();
                userService.MockCrypto
                           .Setup(x => x.GenerateSaltedHash("thePassword", It.IsAny<string>()))
                           .Returns("theHashedPassword");

                var user = userService.Create(
                    "theUsername",
                    "thePassword",
                    "theEmailAddress");

                Assert.Equal("theHashedPassword", user.HashedPassword);
            }
Esempio n. 12
0
            public void WillSaveTheNewUser()
            {
                var userService = new TestableUserService();

                userService.MockCrypto
                           .Setup(x => x.GenerateSaltedHash(It.IsAny<string>(), It.IsAny<string>()))
                           .Returns("theHashedPassword");

                userService.Create(
                    "theUsername",
                    "thePassword",
                    "theEmailAddress");

                userService.MockUserRepository
                           .Verify(x => x.InsertOnCommit(
                                It.Is<User>(
                                    u =>
                                    u.Username == "theUsername" &&
                                    u.HashedPassword == "theHashedPassword" &&
                                    u.UnconfirmedEmailAddress == "theEmailAddress")));
                userService.MockUserRepository
                           .Verify(x => x.CommitChanges());
            }
Esempio n. 13
0
            public void SetsAConfirmationToken()
            {
                var userService = new TestableUserService();
                userService.MockCrypto
                           .Setup(c => c.GenerateToken())
                           .Returns("secret!");

                var user = userService.Create(
                    "theUsername",
                    "thePassword",
                    "theEmailAddress");

                Assert.Equal("secret!", user.EmailConfirmationToken);
                Assert.False(user.Confirmed);
            }
Esempio n. 14
0
            public void SetsTheUserToConfirmedWhenEmailConfirmationIsNotEnabled()
            {
                var userService = new TestableUserService();
                userService.MockConfig
                           .Setup(x => x.ConfirmEmailAddresses)
                           .Returns(false);

                var user = userService.Create(
                    "theUsername",
                    "thePassword",
                    "theEmailAddress");

                Assert.Equal(true, user.Confirmed);
            }
Esempio n. 15
0
            public void SetsAnApiKey()
            {
                var userService = new TestableUserService();

                var user = userService.Create(
                    "theUsername",
                    "thePassword",
                    "theEmailAddress");

                userService.MockUserRepository
                    .Verify(x => x.InsertOnCommit(user));
                Assert.NotEqual(Guid.Empty, user.ApiKey);

                var apiKeyCred = user.Credentials.FirstOrDefault(c => c.Type == CredentialTypes.ApiKeyV1);
                Assert.NotNull(apiKeyCred);
                Assert.Equal(user.ApiKey.ToString().ToLowerInvariant(), apiKeyCred.Value);
            }
Esempio n. 16
0
            public void WillHashThePassword()
            {
                var userService = new TestableUserService();

                var user = userService.Create(
                    "theUsername",
                    "thePassword",
                    "theEmailAddress");

                Assert.Equal("PBKDF2", user.PasswordHashAlgorithm);
                Assert.True(VerifyPasswordHash(user, "thePassword"));
            }
Esempio n. 17
0
            public void SetsAnApiKey()
            {
                var userService = new TestableUserService();

                var user = userService.Create(
                    "theUsername",
                    "thePassword",
                    "theEmailAddress");

                Assert.NotEqual(Guid.Empty, user.ApiKey);
            }
Esempio n. 18
0
            public void WillSaveTheNewUserAsConfirmedWhenConfigured()
            {
                var userService = new TestableUserService();

                userService.MockConfig
                           .Setup(x => x.ConfirmEmailAddresses)
                           .Returns(false);

                userService.Create(
                    "theUsername",
                    "thePassword",
                    "theEmailAddress");

                userService.MockUserRepository
                           .Verify(x => x.InsertOnCommit(
                               It.Is<User>(
                                   u =>
                                   u.Username == "theUsername" &&
                                   u.Confirmed)));
                userService.MockUserRepository
                           .Verify(x => x.CommitChanges());
            }
Esempio n. 19
0
            public void WillSaveTheNewUser()
            {
                var userService = new TestableUserService();


                userService.Create(
                    "theUsername",
                    "thePassword",
                    "theEmailAddress");

                userService.MockUserRepository
                           .Verify(x => x.InsertOnCommit(
                                It.Is<User>(
                                    u =>
                                    u.Username == "theUsername" &&
                                    u.UnconfirmedEmailAddress == "theEmailAddress")));
                userService.MockUserRepository
                           .Verify(x => x.CommitChanges());
            }
Esempio n. 20
0
            public void SetsCreatedDate()
            {
                var userService = new TestableUserService();

                var user = userService.Create(
                    "theUsername",
                    "thePassword",
                    "theEmailAddress");

                Assert.NotNull(user.CreatedUtc);

                // Allow for up to 5 secs of time to have elapsed between Create call and now. Should be plenty
                Assert.True((DateTime.UtcNow - user.CreatedUtc) < TimeSpan.FromSeconds(5));
            }
Esempio n. 21
0
            public void WillSaveThePasswordInTheCredentialsTable()
            {
                var userService = new TestableUserService();
                
                var user = userService.Create(
                    "theUsername",
                    "thePassword",
                    "theEmailAddress");

                Assert.NotNull(user);
                var passwordCred = user.Credentials.FirstOrDefault(c => c.Type == CredentialTypes.Password.Pbkdf2);
                Assert.NotNull(passwordCred);
                Assert.Equal(CredentialTypes.Password.Pbkdf2, passwordCred.Type);
                Assert.True(VerifyPasswordHash(passwordCred.Value, Constants.PBKDF2HashAlgorithmId, "thePassword"));

                userService.MockUserRepository
                    .Verify(x => x.InsertOnCommit(user));
                userService.MockUserRepository
                    .Verify(x => x.CommitChanges());
            }