diff --git a/model/api/src/main/java/org/keycloak/models/PasswordPolicy.java b/model/api/src/main/java/org/keycloak/models/PasswordPolicy.java index bea471db0f..dc82bcc5f5 100755 --- a/model/api/src/main/java/org/keycloak/models/PasswordPolicy.java +++ b/model/api/src/main/java/org/keycloak/models/PasswordPolicy.java @@ -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; } } diff --git a/model/api/src/test/java/org/keycloak/models/PasswordPolicyTest.java b/model/api/src/test/java/org/keycloak/models/PasswordPolicyTest.java index 3fd7271470..3481498884 100644 --- a/model/api/src/test/java/org/keycloak/models/PasswordPolicyTest.java +++ b/model/api/src/test/java/org/keycloak/models/PasswordPolicyTest.java @@ -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")); }