diff --git a/testing/conntest/src/test/java/com/evolveum/midpoint/testing/conntest/AbstractEDirTest.java b/testing/conntest/src/test/java/com/evolveum/midpoint/testing/conntest/AbstractEDirTest.java index c65538da755..710b5712fba 100644 --- a/testing/conntest/src/test/java/com/evolveum/midpoint/testing/conntest/AbstractEDirTest.java +++ b/testing/conntest/src/test/java/com/evolveum/midpoint/testing/conntest/AbstractEDirTest.java @@ -49,6 +49,7 @@ import com.evolveum.midpoint.schema.SearchResultList; import com.evolveum.midpoint.schema.SearchResultMetadata; import com.evolveum.midpoint.schema.constants.MidPointConstants; +import com.evolveum.midpoint.schema.constants.SchemaConstants; import com.evolveum.midpoint.schema.processor.ResourceAttribute; import com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition; import com.evolveum.midpoint.schema.result.OperationResult; @@ -58,6 +59,7 @@ import com.evolveum.midpoint.schema.util.ShadowUtil; import com.evolveum.midpoint.task.api.Task; import com.evolveum.midpoint.test.IntegrationTestTools; +import com.evolveum.midpoint.test.util.MidPointAsserts; import com.evolveum.midpoint.test.util.MidPointTestConstants; import com.evolveum.midpoint.test.util.TestUtil; import com.evolveum.midpoint.util.DOMUtil; @@ -322,6 +324,7 @@ public void test110GetJack() throws Exception { display("Shadow", shadow); assertAccountShadow(shadow, toDn(ACCOUNT_JACK_UID)); assertLockout(shadow, LockoutStatusType.NORMAL); + assertPasswordAllowChange(shadow, null); jackAccountOid = shadow.getOid(); IntegrationTestTools.assertAssociation(shadow, getAssociationGroupQName(), groupPiratesOid); @@ -466,6 +469,7 @@ public void test200AssignAccountBarbossa() throws Exception { assertEquals("Wrong ICFS UID", MiscUtil.binaryToHex(entry.get(getPrimaryIdentifierAttributeName()).getBytes()), accountBarbossaIcfUid); assertLdapPassword(USER_BARBOSSA_USERNAME, "deadjacktellnotales"); + assertPasswordAllowChange(shadow, null); ResourceAttribute createTimestampAttribute = ShadowUtil.getAttribute(shadow, new QName(MidPointConstants.NS_RI, "createTimestamp")); assertNotNull("No createTimestamp in "+shadow, createTimestampAttribute); @@ -600,7 +604,48 @@ public void test239EnableBarbossa() throws Exception { PrismObject shadow = getObject(ShadowType.class, shadowOid); assertAdministrativeStatus(shadow, ActivationStatusType.ENABLED); } - + + /** + * passwordAllowChange is a boolean attribute + */ + @Test + public void test240ModifyAccountBarbossaPasswordAllowChangeFalse() throws Exception { + final String TEST_NAME = "test240ModifyAccountBarbossaPasswordAllowChangeFalse"; + TestUtil.displayTestTile(this, TEST_NAME); + + // GIVEN + Task task = taskManager.createTaskInstance(this.getClass().getName() + "." + TEST_NAME); + OperationResult result = task.getResult(); + + ObjectDelta delta = ObjectDelta.createEmptyModifyDelta(ShadowType.class, accountBarbossaOid, prismContext); + QName attrQName = new QName(MidPointConstants.NS_RI, "passwordAllowChange"); + ResourceAttributeDefinition attrDef = accountObjectClassDefinition.findAttributeDefinition(attrQName); + PropertyDelta attrDelta = PropertyDelta.createModificationReplaceProperty( + new ItemPath(ShadowType.F_ATTRIBUTES, attrQName), attrDef, Boolean.FALSE); + delta.addModification(attrDelta); + + // WHEN + TestUtil.displayWhen(TEST_NAME); + modelService.executeChanges(MiscSchemaUtil.createCollection(delta), null, task, result); + + // THEN + TestUtil.displayThen(TEST_NAME); + result.computeStatus(); + TestUtil.assertSuccess(result); + + Entry entry = assertLdapAccount(USER_BARBOSSA_USERNAME, USER_BARBOSSA_FULL_NAME); + assertAttribute(entry, "passwordAllowChange", "FALSE"); + + PrismObject user = getUser(USER_BARBOSSA_OID); + String shadowOid = getSingleLinkOid(user); + assertEquals("Shadows have moved", accountBarbossaOid, shadowOid); + + PrismObject shadow = getObject(ShadowType.class, shadowOid); + display("Shadow after", shadow); + assertPasswordAllowChange(shadow, false); + + } + /** * This should create account with a group. And disabled. */ @@ -1011,6 +1056,11 @@ protected void assertAccountShadow(PrismObject shadow, String dn) th assertTrue("Unexpected chars in primary ID: '"+primaryId+"'", primaryId.matches("[a-z0-9]+")); } + protected void assertPasswordAllowChange(PrismObject shadow, Boolean expected) throws SchemaException { + Boolean passwordAllowChange = ShadowUtil.getAttributeValue(shadow, new QName(MidPointConstants.NS_RI, "passwordAllowChange")); + assertEquals("Wrong passwordAllowChange in "+shadow, expected, passwordAllowChange); + } + private void makeBadLoginAttempt(String uid) throws LdapException { LdapNetworkConnection conn = ldapConnect(toDn(uid), "thisIsAwRoNgPASSW0RD"); if (conn.isAuthenticated()) {