public async Task FailsIfTooShortTests(string input) { const string error = "Passwords must be at least 6 characters."; var manager = MockHelpers.TestUserManager <PocoUser>(); var valid = new PasswordValidator <PocoUser>(); manager.Options.Password.RequireUppercase = false; manager.Options.Password.RequireNonAlphanumeric = false; manager.Options.Password.RequireLowercase = false; manager.Options.Password.RequireDigit = false; IdentityResultAssert.IsFailure(await valid.ValidateAsync(manager, null, input), error); }
public async Task FailsWithoutRequiredNonAlphanumericTests(string input) { var manager = MockHelpers.TestUserManager <PocoUser>(); var valid = new PasswordValidator <PocoUser>(); manager.Options.Password.RequireUppercase = false; manager.Options.Password.RequireNonAlphanumeric = true; manager.Options.Password.RequireLowercase = false; manager.Options.Password.RequireDigit = false; manager.Options.Password.RequiredLength = 0; IdentityResultAssert.IsFailure(await valid.ValidateAsync(manager, null, input), "Passwords must have at least one non alphanumeric character."); }
public async Task FailsWithoutRequiredUniqueCharsTests(string input, int uniqueChars) { var manager = MockHelpers.TestUserManager <PocoUser>(); var valid = new PasswordValidator <PocoUser>(); manager.Options.Password.RequireUppercase = false; manager.Options.Password.RequireNonAlphanumeric = false; manager.Options.Password.RequireLowercase = false; manager.Options.Password.RequireDigit = false; manager.Options.Password.RequiredLength = 0; manager.Options.Password.RequiredUniqueChars = uniqueChars; IdentityResultAssert.IsFailure(await valid.ValidateAsync(manager, null, input), $"Passwords must use at least {uniqueChars} different characters."); }
public async Task ValidateFailsWithTooShortUserNames(string input) { // Setup var manager = MockHelpers.TestUserManager(new NoopUserStore()); var validator = new UserValidator <PocoUser>(); var user = new PocoUser { UserName = input }; // Act var result = await validator.ValidateAsync(manager, user); // Assert IdentityResultAssert.IsFailure(result, new IdentityErrorDescriber().InvalidUserName(input)); }
public async Task ValidateFailsWithTooShortRoleName(string input) { // Setup var validator = new RoleValidator <PocoRole>(); var manager = MockHelpers.TestRoleManager <PocoRole>(); var user = new PocoRole { Name = input }; // Act var result = await validator.ValidateAsync(manager, user); // Assert IdentityResultAssert.IsFailure(result, new IdentityErrorDescriber().InvalidRoleName(input)); }
public async Task UberMixedRequiredTests(string input, Errors errorMask) { const string alphaError = "Passwords must have at least one non alphanumeric character."; const string upperError = "Passwords must have at least one uppercase ('A'-'Z')."; const string lowerError = "Passwords must have at least one lowercase ('a'-'z')."; const string digitError = "Passwords must have at least one digit ('0'-'9')."; const string lengthError = "Passwords must be at least 6 characters."; var manager = MockHelpers.TestUserManager <PocoUser>(); var valid = new PasswordValidator <PocoUser>(); var errors = new List <string>(); if ((errorMask & Errors.Length) != Errors.None) { errors.Add(lengthError); } if ((errorMask & Errors.Alpha) != Errors.None) { errors.Add(alphaError); } if ((errorMask & Errors.Digit) != Errors.None) { errors.Add(digitError); } if ((errorMask & Errors.Lower) != Errors.None) { errors.Add(lowerError); } if ((errorMask & Errors.Upper) != Errors.None) { errors.Add(upperError); } var result = await valid.ValidateAsync(manager, null, input); if (errors.Count == 0) { IdentityResultAssert.IsSuccess(result); } else { IdentityResultAssert.IsFailure(result); foreach (var error in errors) { Assert.Contains(result.Errors, e => e.Description == error); } } }
public async Task DefaultAlphaNumericOnlyUserNameValidation(string userName, bool expectSuccess) { // Setup var manager = MockHelpers.TestUserManager(new NoopUserStore()); var validator = new UserValidator <PocoUser>(); var user = new PocoUser { UserName = userName }; // Act var result = await validator.ValidateAsync(manager, user); // Assert if (expectSuccess) { IdentityResultAssert.IsSuccess(result); } else { IdentityResultAssert.IsFailure(result); } }
public async Task CanAllowNonAlphaNumericUserName(string userName, bool expectSuccess) { // Setup var manager = MockHelpers.TestUserManager(new NoopUserStore()); manager.Options.User.AllowedUserNameCharacters = null; var validator = new UserValidator <PocoUser>(); var user = new PocoUser { UserName = userName }; // Act var result = await validator.ValidateAsync(manager, user); // Assert if (expectSuccess) { IdentityResultAssert.IsSuccess(result); } else { IdentityResultAssert.IsFailure(result); } }