KEYCLOAK-824 Wrong digit shown in Invalid Password message

This commit is contained in:
Stian Thorgersen 2014-11-06 12:30:24 +01:00
parent e7625c2bb1
commit 9343cf2aca
2 changed files with 14 additions and 14 deletions

View file

@ -132,7 +132,7 @@ public class PasswordPolicy {
count++;
}
}
return count < min ? "Invalid password: must contain at least " + count + " numerical digits" : null;
return count < min ? "Invalid password: must contain at least " + min + " numerical digits" : null;
}
}
@ -152,7 +152,7 @@ public class PasswordPolicy {
count++;
}
}
return count < min ? "Invalid password: must contain at least " + count + " lower case characters": null;
return count < min ? "Invalid password: must contain at least " + min + " lower case characters": null;
}
}
@ -172,7 +172,7 @@ public class PasswordPolicy {
count++;
}
}
return count < min ? "Invalid password: must contain at least " + count + " upper case characters" : null;
return count < min ? "Invalid password: must contain at least " + min + " upper case characters" : null;
}
}
@ -192,7 +192,7 @@ public class PasswordPolicy {
count++;
}
}
return count < min ? "Invalid password: must contain at least " + count + " special characters" : null;
return count < min ? "Invalid password: must contain at least " + min + " special characters" : null;
}
}

View file

@ -11,55 +11,55 @@ public class PasswordPolicyTest {
@Test
public void testLength() {
PasswordPolicy policy = new PasswordPolicy("length");
Assert.assertNotNull(policy.validate("1234567"));
Assert.assertEquals("Invalid password: minimum length 8", policy.validate("1234567"));
Assert.assertNull(policy.validate("12345678"));
policy = new PasswordPolicy("length(4)");
Assert.assertNotNull(policy.validate("123"));
Assert.assertEquals("Invalid password: minimum length 4", policy.validate("123"));
Assert.assertNull(policy.validate("1234"));
}
@Test
public void testDigits() {
PasswordPolicy policy = new PasswordPolicy("digits");
Assert.assertNotNull(policy.validate("abcd"));
Assert.assertEquals("Invalid password: must contain at least 1 numerical digits", policy.validate("abcd"));
Assert.assertNull(policy.validate("abcd1"));
policy = new PasswordPolicy("digits(2)");
Assert.assertNotNull(policy.validate("abcd1"));
Assert.assertEquals("Invalid password: must contain at least 2 numerical digits", policy.validate("abcd1"));
Assert.assertNull(policy.validate("abcd12"));
}
@Test
public void testLowerCase() {
PasswordPolicy policy = new PasswordPolicy("lowerCase");
Assert.assertNotNull(policy.validate("ABCD1234"));
Assert.assertEquals("Invalid password: must contain at least 1 lower case characters", policy.validate("ABCD1234"));
Assert.assertNull(policy.validate("ABcD1234"));
policy = new PasswordPolicy("lowerCase(2)");
Assert.assertNotNull(policy.validate("ABcD1234"));
Assert.assertEquals("Invalid password: must contain at least 2 lower case characters", policy.validate("ABcD1234"));
Assert.assertNull(policy.validate("aBcD1234"));
}
@Test
public void testUpperCase() {
PasswordPolicy policy = new PasswordPolicy("upperCase");
Assert.assertNotNull(policy.validate("abcd1234"));
Assert.assertEquals("Invalid password: must contain at least 1 upper case characters", policy.validate("abcd1234"));
Assert.assertNull(policy.validate("abCd1234"));
policy = new PasswordPolicy("upperCase(2)");
Assert.assertNotNull(policy.validate("abCd1234"));
Assert.assertEquals("Invalid password: must contain at least 2 upper case characters", policy.validate("abCd1234"));
Assert.assertNull(policy.validate("AbCd1234"));
}
@Test
public void testSpecialChars() {
PasswordPolicy policy = new PasswordPolicy("specialChars");
Assert.assertNotNull(policy.validate("abcd1234"));
Assert.assertEquals("Invalid password: must contain at least 1 special characters", policy.validate("abcd1234"));
Assert.assertNull(policy.validate("ab&d1234"));
policy = new PasswordPolicy("specialChars(2)");
Assert.assertNotNull(policy.validate("ab&d1234"));
Assert.assertEquals("Invalid password: must contain at least 2 special characters", policy.validate("ab&d1234"));
Assert.assertNull(policy.validate("ab&d-234"));
}