Search in sources :

Example 1 with PasswordPolicyManagerProvider

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"));
    });
}
Also used : RealmModel(org.keycloak.models.RealmModel) PasswordPolicyManagerProvider(org.keycloak.policy.PasswordPolicyManagerProvider) Test(org.junit.Test) AbstractKeycloakTest(org.keycloak.testsuite.AbstractKeycloakTest)

Example 2 with PasswordPolicyManagerProvider

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"));
    });
}
Also used : RealmModel(org.keycloak.models.RealmModel) PasswordPolicyManagerProvider(org.keycloak.policy.PasswordPolicyManagerProvider) Test(org.junit.Test) AbstractKeycloakTest(org.keycloak.testsuite.AbstractKeycloakTest)

Example 3 with PasswordPolicyManagerProvider

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"));
    });
}
Also used : RealmModel(org.keycloak.models.RealmModel) PasswordPolicyManagerProvider(org.keycloak.policy.PasswordPolicyManagerProvider) Test(org.junit.Test) AbstractKeycloakTest(org.keycloak.testsuite.AbstractKeycloakTest)

Example 4 with PasswordPolicyManagerProvider

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"));
    });
}
Also used : RealmModel(org.keycloak.models.RealmModel) PasswordPolicyManagerProvider(org.keycloak.policy.PasswordPolicyManagerProvider) Test(org.junit.Test) AbstractKeycloakTest(org.keycloak.testsuite.AbstractKeycloakTest)

Example 5 with PasswordPolicyManagerProvider

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"));
    });
}
Also used : RealmModel(org.keycloak.models.RealmModel) PasswordPolicyManagerProvider(org.keycloak.policy.PasswordPolicyManagerProvider) Test(org.junit.Test) AbstractKeycloakTest(org.keycloak.testsuite.AbstractKeycloakTest)

Aggregations

Test (org.junit.Test)11 RealmModel (org.keycloak.models.RealmModel)11 PasswordPolicyManagerProvider (org.keycloak.policy.PasswordPolicyManagerProvider)11 AbstractKeycloakTest (org.keycloak.testsuite.AbstractKeycloakTest)11 ModelException (org.keycloak.models.ModelException)2 PasswordPolicy (org.keycloak.models.PasswordPolicy)1