Search in sources :

Example 36 with ValuePolicyType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ValuePolicyType in project midpoint by Evolveum.

the class TestPasswordPolicy method passwordValidationTestTri.

@Test
public void passwordValidationTestTri() throws Exception {
    final String TEST_NAME = "passwordValidationTestTri";
    TestUtil.displayTestTile(TEST_NAME);
    ValuePolicyType pp = parsePasswordPolicy("password-policy-tri.xml");
    // WHEN, THEN
    AssertJUnit.assertTrue(pwdValidHelper("Password1", pp));
    // no capital letter
    AssertJUnit.assertFalse(pwdValidHelper("password1", pp));
    // no lowecase letter
    AssertJUnit.assertFalse(pwdValidHelper("1PASSWORD", pp));
    // no numeral
    AssertJUnit.assertFalse(pwdValidHelper("Password", pp));
    // too short
    AssertJUnit.assertFalse(pwdValidHelper("Pa1", pp));
    // too long
    AssertJUnit.assertFalse(pwdValidHelper("PPPPPPPPPPPPPPPPPPPPPPPaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa11111111111111111111111111111111111111111111111111111111111111111111", pp));
}
Also used : ValuePolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.ValuePolicyType) Test(org.testng.annotations.Test) AbstractInternalModelIntegrationTest(com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)

Example 37 with ValuePolicyType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ValuePolicyType in project midpoint by Evolveum.

the class TestPasswordPolicy method testValueGenerateEmpty.

@Test
public void testValueGenerateEmpty() throws Exception {
    final String TEST_NAME = "testValueGenerateEmpty";
    TestUtil.displayTestTile(TEST_NAME);
    Task task = createTask(TEST_NAME);
    OperationResult result = task.getResult();
    File file = new File(TEST_DIR, "value-policy-generate-empty.xml");
    LOGGER.info("Positive testing {}: {}", "testValueGenerate", "value-policy-generate-empty.xml");
    ValuePolicyType pp = (ValuePolicyType) PrismTestUtil.parseObject(file).asObjectable();
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    String psswd = valuePolicyProcessor.generate(SchemaConstants.PATH_PASSWORD_VALUE, pp.getStringPolicy(), 10, true, null, TEST_NAME, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    display("Generated password", psswd);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    assertNotNull(psswd);
    assertPassword(psswd, pp);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ValuePolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.ValuePolicyType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) File(java.io.File) Test(org.testng.annotations.Test) AbstractInternalModelIntegrationTest(com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)

Example 38 with ValuePolicyType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ValuePolicyType in project midpoint by Evolveum.

the class TestPasswordPolicy method testUserProps.

/**
	 * MID-1657
	 */
@Test
public void testUserProps() throws Exception {
    final String TEST_NAME = "testUserProps";
    TestUtil.displayTestTile(TEST_NAME);
    PrismObject<UserType> user = createUserAb();
    display("User", user);
    ValuePolicyType pp = parsePasswordPolicy("password-policy-props.xml");
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    for (int i = 0; i < USER_PROPS_ATTEMPTS; i++) {
        Task task = createTask(TEST_NAME + ":" + i);
        OperationResult result = task.getResult();
        String psswd = valuePolicyProcessor.generate(SchemaConstants.PATH_PASSWORD_VALUE, pp.getStringPolicy(), 10, true, user, TEST_NAME, task, result);
        display("Generated password (" + i + ")", psswd);
        result.computeStatus();
        TestUtil.assertSuccess(result);
        assertNotNull(psswd);
        assertPassword(psswd, pp, user);
        assertNotContains(psswd, USER_AB_USERNAME);
        assertNotContains(psswd, USER_AB_GIVEN_NAME);
        assertNotContains(psswd, USER_AB_ADDITIONAL_NAME);
    }
    // THEN
    TestUtil.displayThen(TEST_NAME);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ValuePolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.ValuePolicyType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test) AbstractInternalModelIntegrationTest(com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)

Example 39 with ValuePolicyType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ValuePolicyType in project midpoint by Evolveum.

the class TestPasswordPolicy method testValueGenerate.

@Test
public void testValueGenerate() throws Exception {
    final String TEST_NAME = "testValueGenerate";
    TestUtil.displayTestTile(TEST_NAME);
    Task task = createTask(TEST_NAME);
    OperationResult result = task.getResult();
    ValuePolicyType pp = parsePasswordPolicy("value-policy-generate.xml");
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    String psswd = valuePolicyProcessor.generate(SchemaConstants.PATH_PASSWORD_VALUE, pp.getStringPolicy(), 10, true, null, TEST_NAME, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    display("Generated password", psswd);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    assertNotNull(psswd);
    assertPassword(psswd, pp);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ValuePolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.ValuePolicyType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test) AbstractInternalModelIntegrationTest(com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)

Example 40 with ValuePolicyType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ValuePolicyType in project midpoint by Evolveum.

the class TestPasswordPolicy method testUsername.

/**
	 * MID-1657
	 */
@Test
public void testUsername() throws Exception {
    final String TEST_NAME = "testUsername";
    TestUtil.displayTestTile(TEST_NAME);
    PrismObject<UserType> user = createUserAb();
    ValuePolicyType pp = parsePasswordPolicy("password-policy-username.xml");
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    for (int i = 0; i < USERNAME_ATTEMPTS; i++) {
        Task task = createTask(TEST_NAME + ":" + i);
        OperationResult result = task.getResult();
        String psswd = valuePolicyProcessor.generate(SchemaConstants.PATH_PASSWORD_VALUE, pp.getStringPolicy(), 10, true, user, TEST_NAME, task, result);
        display("Generated password (" + i + ")", psswd);
        result.computeStatus();
        TestUtil.assertSuccess(result);
        assertNotNull(psswd);
        assertPassword(psswd, pp, user);
        assertFalse("Generated password that matches the username: " + psswd, psswd.equals(USER_AB_USERNAME));
    }
    // THEN
    TestUtil.displayThen(TEST_NAME);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ValuePolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.ValuePolicyType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test) AbstractInternalModelIntegrationTest(com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)

Aggregations

ValuePolicyType (com.evolveum.midpoint.xml.ns._public.common.common_3.ValuePolicyType)35 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)19 Test (org.testng.annotations.Test)14 Task (com.evolveum.midpoint.task.api.Task)12 AbstractInternalModelIntegrationTest (com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)10 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)8 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)8 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)7 File (java.io.File)7 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)6 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)6 StringPolicyType (com.evolveum.midpoint.xml.ns._public.common.common_3.StringPolicyType)6 PrismObject (com.evolveum.midpoint.prism.PrismObject)5 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)5 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)4 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)4 StringPolicyResolver (com.evolveum.midpoint.repo.common.expression.StringPolicyResolver)4 ProtectedStringType (com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)4 ItemDefinition (com.evolveum.midpoint.prism.ItemDefinition)3 PrismContext (com.evolveum.midpoint.prism.PrismContext)3