public void IsValid_NonString_FailsValidation() { PasswordValidatorRegistration.Register(); var attr = new PasswordValidationAttribute(); var result = attr.IsValid(123); Assert.IsFalse(result); }
public void IsValid_NoSettings_UsesConfigFile() { PasswordValidatorRegistration.Register(); var attr = new PasswordValidationAttribute(); var result = attr.IsValid("Short"); Assert.IsFalse(result); }
public void IsValid_BasicSettings_IsTrue() { PasswordValidatorRegistration.Register(); var attr = new PasswordValidationAttribute(); attr.Settings = new PasswordValidationSettings(); var result = attr.IsValid("MyPassword"); Assert.IsTrue(result); }
public void IsValid_LengthTooShort_IsFalse() { PasswordValidatorRegistration.Register(); var attr = new PasswordValidationAttribute(); attr.Settings = new PasswordValidationSettings(); attr.Settings.MinimumPasswordLength = 10; var result = attr.IsValid("Short"); Assert.IsFalse(result); }
public void Register_SetsMapPath_MappedPath() { var t = typeof(CustomWordListFactory); var fi = t.GetField("_mapPath", BindingFlags.NonPublic | BindingFlags.Static); var mapPathValue = fi.GetValue(null); Assert.IsNull(mapPathValue); PasswordValidatorRegistration.Register(); mapPathValue = fi.GetValue(null); Assert.IsNotNull(mapPathValue); }
public void IsValid_NullPassword_FailsValidation() { // Even although the minimum length is zero, a null password always fails // the validation. PasswordValidatorRegistration.Register(); var attr = new PasswordValidationAttribute(); attr.Settings = new PasswordValidationSettings(); attr.Settings.MinimumPasswordLength = 0; var result = attr.IsValid(null); Assert.IsFalse(result); }
public static void Register() { PasswordValidatorRegistration.Register(); var settings = new PasswordValidationSettings(); settings.NeedsNumber = true; settings.NeedsSymbol = true; settings.MinimumPasswordLength = 6; settings.StandardWordLists.Add(StandardWordList.FemaleNames); settings.StandardWordLists.Add(StandardWordList.MaleNames); settings.StandardWordLists.Add(StandardWordList.Surnames); settings.StandardWordLists.Add(StandardWordList.MostCommon500Passwords); settings.CustomValidators.Add(typeof(NoDatesValidationHandler)); settings.WordListProcessOptions.CustomBuilders.Add(typeof(NumericPrefixBuilder)); PasswordValidationSettingsCache.Add("NoDates", settings); settings = new PasswordValidationSettings(); settings.MinimumPasswordLength = 6; settings.CustomValidators.Add(typeof(PasswordHistoryValidationHandler)); settings.CustomSettings.Add(typeof(PasswordHistoryValidationHandler), new Repository()); PasswordValidationSettingsCache.Add("History", settings); }
public void IsRegistered_AfterCallingRegister_IsTrue() { PasswordValidatorRegistration.Register(); Assert.IsTrue(PasswordValidatorRegistration.IsRegistered); }