public void Should_FailValidation_When_PasswordIsEmpty()
        {
            // Arrange
            var userAccountValidator = new UserAccountValidator();
            var userAccount          = new UserAccount(username: "******", password: "", isActive: true, isFirstTimeUser: false, roleType: "public");

            // Act
            var result  = userAccountValidator.Validate(userAccount, ruleSet: "CreateUser");
            var isValid = result.IsValid;

            // Assert
            isValid.Should().Be(false);
        }
        public void Should_FailValidation_When_UsernameContainsSpecialCharacters()
        {
            // Arrange
            var userAccountValidator = new UserAccountValidator();
            var userAccount          = new UserAccount(username: "******", password: "******", isActive: true, isFirstTimeUser: false, roleType: "public");

            // Act
            var result  = userAccountValidator.Validate(userAccount, ruleSet: "CreateUser");
            var isValid = result.IsValid;

            // Assert
            isValid.Should().Be(false);
        }
        public void Should_FailSsoValidation_When_UsernameIsEmpty()
        {
            // Arrange
            var userAccountValidator = new UserAccountValidator();
            var userAccount          = new UserAccount(username: "", password: "******", isActive: false, isFirstTimeUser: false, roleType: "public");

            // Act
            var result  = userAccountValidator.Validate(userAccount, ruleSet: "SsoRegistration");
            var isValid = result.IsValid;

            // Assert
            result.IsValid.Should().BeFalse();
            isValid.Should().Be(false);
        }
        static void Main(string[] args)
        {
            UserAccount userAccount = UserAccountDataCapture.CaptureFirstName();

            userAccount = UserAccountDataCapture.CaptureLastName();

            bool isUserAccountValid = UserAccountValidator.Validate(userAccount);

            if (!isUserAccountValid)
            {
                StandardMessages.EndApplication();
                return;
            }

            AccountGenerator.CreateAccount(userAccount);
            StandardMessages.EndApplication();
        }
        public void User_Account_Is_Valid()
        {
            var expectedIsValid = true;

            var viewModel = new UserAccountViewModel
            {
                FirstName         = "Simon",
                Username          = "******",
                EmailAddress      = "*****@*****.**",
                MobilePhoneNumber = "+447890123456",
            };

            var validator = new UserAccountValidator();

            var validationResult = validator.Validate(viewModel);

            Assert.Equal(expectedIsValid, validationResult.IsValid);
        }
        public void User_Account_Is_Not_Valid()
        {
            var expectedIsValid = false;

            var userAccount = new UserAccount
            {
                FirstName         = "",
                Username          = "******",
                EmailAddress      = "hello_simongilbert.net",
                MobilePhoneNumber = "07890123456",
                DateOfBirth       = new DateTime(2019, 11, 24),
            };

            var validator = new UserAccountValidator();

            var validationResult = validator.Validate(userAccount);

            Assert.Equal(expectedIsValid, validationResult.IsValid);
        }
        public void User_Account_Is_Valid()
        {
            var expectedIsValid = true;

            var userAccount = new UserAccount
            {
                FirstName         = "Simon",
                Username          = "******",
                EmailAddress      = "*****@*****.**",
                MobilePhoneNumber = "+447890123456",
                DateOfBirth       = new DateTime(1987, 11, 24),
            };

            var validator = new UserAccountValidator();

            var validationResult = validator.Validate(userAccount);

            Assert.Equal(expectedIsValid, validationResult.IsValid);
        }
Beispiel #8
0
        /// <summary>
        /// Validates the specified username and password.
        /// </summary>
        /// <param name="username">
        /// A string containing the username of the account to to validate.
        /// </param>
        /// <param name="password">
        /// A string containing the password of the account to validate.
        /// </param>
        public override void Validate(string username, string password)
        {
            if (String.IsNullOrEmpty(username))
            {
                throw new ArgumentException("The specified username parameter is invalid.");
            }

            string tenant = string.Empty;

            // Split the tenant and username fields
            string[] credentials = username.Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries);
            if (credentials.Length > 1)
            {
                tenant   = credentials[0];
                username = credentials[1];
            }

            // Validate the credentials
            // Don't store the credentials in the thread context.
            // This is due to the fact that the validator may operate on a different
            // thread than the actual service code.
            UserAccountValidator.Validate(username, password, tenant, false);
        }
        public void Validate_NoLockout(int logonAttemptOffset, bool expectLockedOut)
        {
            const string   password = "******";
            UserAccount    userAccount;
            PasswordPolicy passwordPolicy;

            passwordPolicy = Entity.Get <PasswordPolicy>("core:passwordPolicyInstance");

            userAccount      = new UserAccount();
            userAccount.Name = "Test user " + Guid.NewGuid();
            userAccount.AccountStatus_Enum = UserAccountStatusEnum_Enumeration.Active;
            userAccount.Password           = password;
            userAccount.Save();

            for (int i = 0; i < passwordPolicy.AccountLockoutThreshold + logonAttemptOffset; i++)
            {
                try
                {
                    UserAccountValidator.Validate(
                        userAccount.Name,
                        userAccount.Password + "_foo", // Invalid password
                        RequestContext.GetContext().Tenant.Name,
                        false);
                }
                catch (Exception)
                {
                    // This will throw exceptions if the user is locked, disabled or expired. Ignore these exceptions in this test.
                }
            }

            userAccount = Entity.Get <UserAccount>(userAccount.Id);
            Assert.That(userAccount.AccountStatus_Enum,
                        expectLockedOut
                    ? Is.EqualTo(UserAccountStatusEnum_Enumeration.Locked)
                    : Is.EqualTo(UserAccountStatusEnum_Enumeration.Active));
        }
 public void Validate_NullPassword()
 {
     Assert.That(() => UserAccountValidator.Validate("username", null, "tenant", false),
                 Throws.TypeOf <ArgumentNullException>().And.Property("ParamName").EqualTo("password"));
 }