use of org.keycloak.policy.PasswordPolicyManagerProvider in project keycloak by keycloak.
the class PasswordPolicyTest method testUpperCase.
@Test
public void testUpperCase() {
testingClient.server("passwordPolicy").run(session -> {
RealmModel realmModel = session.getContext().getRealm();
PasswordPolicyManagerProvider policyManager = session.getProvider(PasswordPolicyManagerProvider.class);
realmModel.setPasswordPolicy(PasswordPolicy.parse(session, "upperCase"));
Assert.assertEquals("invalidPasswordMinUpperCaseCharsMessage", policyManager.validate("jdoe", "abcd1234").getMessage());
Assert.assertArrayEquals(new Object[] { 1 }, policyManager.validate("jdoe", "abcd1234").getParameters());
assertNull(policyManager.validate("jdoe", "abCd1234"));
realmModel.setPasswordPolicy(PasswordPolicy.parse(session, "upperCase(2)"));
Assert.assertEquals("invalidPasswordMinUpperCaseCharsMessage", policyManager.validate("jdoe", "abCd1234").getMessage());
Assert.assertArrayEquals(new Object[] { 2 }, policyManager.validate("jdoe", "abCd1234").getParameters());
assertNull(policyManager.validate("jdoe", "AbCd1234"));
});
}
use of org.keycloak.policy.PasswordPolicyManagerProvider in project keycloak by keycloak.
the class PasswordPolicyTest method testSpecialChars.
@Test
public void testSpecialChars() {
testingClient.server("passwordPolicy").run(session -> {
RealmModel realmModel = session.getContext().getRealm();
PasswordPolicyManagerProvider policyManager = session.getProvider(PasswordPolicyManagerProvider.class);
realmModel.setPasswordPolicy(PasswordPolicy.parse(session, "specialChars"));
Assert.assertEquals("invalidPasswordMinSpecialCharsMessage", policyManager.validate("jdoe", "abcd1234").getMessage());
Assert.assertArrayEquals(new Object[] { 1 }, policyManager.validate("jdoe", "abcd1234").getParameters());
assertNull(policyManager.validate("jdoe", "ab&d1234"));
realmModel.setPasswordPolicy(PasswordPolicy.parse(session, "specialChars(2)"));
Assert.assertEquals("invalidPasswordMinSpecialCharsMessage", policyManager.validate("jdoe", "ab&d1234").getMessage());
Assert.assertArrayEquals(new Object[] { 2 }, policyManager.validate("jdoe", "ab&d1234").getParameters());
assertNull(policyManager.validate("jdoe", "ab&d-234"));
});
}
use of org.keycloak.policy.PasswordPolicyManagerProvider in project keycloak by keycloak.
the class PasswordPolicyTest method testLength.
@Test
public void testLength() {
testingClient.server("passwordPolicy").run(session -> {
RealmModel realmModel = session.getContext().getRealm();
PasswordPolicyManagerProvider policyManager = session.getProvider(PasswordPolicyManagerProvider.class);
realmModel.setPasswordPolicy(PasswordPolicy.parse(session, "length"));
Assert.assertEquals("invalidPasswordMinLengthMessage", policyManager.validate("jdoe", "1234567").getMessage());
Assert.assertArrayEquals(new Object[] { 8 }, policyManager.validate("jdoe", "1234567").getParameters());
assertNull(policyManager.validate("jdoe", "12345678"));
realmModel.setPasswordPolicy(PasswordPolicy.parse(session, "length(4)"));
Assert.assertEquals("invalidPasswordMinLengthMessage", policyManager.validate("jdoe", "123").getMessage());
Assert.assertArrayEquals(new Object[] { 4 }, policyManager.validate("jdoe", "123").getParameters());
assertNull(policyManager.validate("jdoe", "1234"));
});
}
use of org.keycloak.policy.PasswordPolicyManagerProvider in project keycloak by keycloak.
the class PasswordPolicyTest method testLowerCase.
@Test
public void testLowerCase() {
testingClient.server("passwordPolicy").run(session -> {
RealmModel realmModel = session.getContext().getRealm();
PasswordPolicyManagerProvider policyManager = session.getProvider(PasswordPolicyManagerProvider.class);
realmModel.setPasswordPolicy(PasswordPolicy.parse(session, "lowerCase"));
Assert.assertEquals("invalidPasswordMinLowerCaseCharsMessage", policyManager.validate("jdoe", "ABCD1234").getMessage());
Assert.assertArrayEquals(new Object[] { 1 }, policyManager.validate("jdoe", "ABCD1234").getParameters());
assertNull(policyManager.validate("jdoe", "ABcD1234"));
realmModel.setPasswordPolicy(PasswordPolicy.parse(session, "lowerCase(2)"));
Assert.assertEquals("invalidPasswordMinLowerCaseCharsMessage", policyManager.validate("jdoe", "ABcD1234").getMessage());
Assert.assertArrayEquals(new Object[] { 2 }, policyManager.validate("jdoe", "ABcD1234").getParameters());
assertNull(policyManager.validate("jdoe", "aBcD1234"));
});
}
use of org.keycloak.policy.PasswordPolicyManagerProvider in project keycloak by keycloak.
the class PasswordPolicyTest method testNotUsername.
@Test
public void testNotUsername() {
testingClient.server("passwordPolicy").run(session -> {
RealmModel realmModel = session.getContext().getRealm();
PasswordPolicyManagerProvider policyManager = session.getProvider(PasswordPolicyManagerProvider.class);
realmModel.setPasswordPolicy(PasswordPolicy.parse(session, "notUsername"));
Assert.assertEquals("invalidPasswordNotUsernameMessage", policyManager.validate("jdoe", "jdoe").getMessage());
assertNull(policyManager.validate("jdoe", "ab&d1234"));
});
}
Aggregations