Exemplo n.º 1
0
        public void ValidateCorrectUserIdAndWrongPassword()
        {
            // Arrange
            _passwordRepoMock.Setup(m => m.SaveUserInfo(It.IsAny <UserPasswordInfo>()))
            .Returns(true);
            _service = new PasswordApi.Service.PasswordService(_passwordRepoMock.Object, _passwordExpiryMock.Object, new Rfc2898CryptoService());
            var sampleUserId  = "user1";
            var password      = _service.GeneratePassword(sampleUserId);
            var wrongPassword = _service.GeneratePassword("user2");
            var hash          = new Rfc2898CryptoService().HashPassword(password);

            _passwordRepoMock.Setup(m => m.GetUserInfo(sampleUserId))
            .Returns(new UserPasswordInfo
            {
                HashedPassword = hash.HashedPassword,
                HashSalt       = hash.HashSalt,
                Expiry         = DateTime.Now.AddSeconds(-1), //valid
            });

            // Act
            var result = _service.IsPasswordValid(sampleUserId, wrongPassword);

            // Assert
            Assert.IsFalse(result, "userid and password must not be valid");
        }
Exemplo n.º 2
0
        public void GeneratePassword()
        {
            // Arrange
            _passwordRepoMock.Setup(m => m.SaveUserInfo(It.IsAny <UserPasswordInfo>()))
            .Returns(true);
            _service = new PasswordApi.Service.PasswordService(_passwordRepoMock.Object, _passwordExpiryMock.Object, new Rfc2898CryptoService());
            var sampleUserId = "user1";

            // Act
            var password = _service.GeneratePassword(sampleUserId);

            // Assert
            password.Should().NotBeNullOrEmpty();
        }
Exemplo n.º 3
0
        public void GetRandomPassword()
        {
            // Arrange
            _passwordRepoMock.Setup(m => m.SaveUserInfo(It.IsAny <UserPasswordInfo>()))
            .Returns(true);
            _service = new PasswordApi.Service.PasswordService(_passwordRepoMock.Object, _passwordExpiryMock.Object, new Rfc2898CryptoService());
            var sampleUserId = "user1";

            // Act
            var password1 = _service.GeneratePassword(sampleUserId);
            var password2 = _service.GeneratePassword(sampleUserId);

            // Assert
            Assert.AreNotEqual <string>(password1, password2,
                                        "Calling the generator with the same data should not create same password.");
        }