Skip to content

Commit

Permalink
Fixing simulated activation (+tests)
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Jul 14, 2014
1 parent b9b6b4a commit 710e55f
Show file tree
Hide file tree
Showing 7 changed files with 550 additions and 89 deletions.
Expand Up @@ -40,6 +40,7 @@
import java.util.jar.JarEntry;
import java.util.jar.JarFile;

import org.apache.commons.io.IOUtils;
import org.opends.messages.Message;
import org.opends.messages.MessageBuilder;
import org.opends.server.config.ConfigException;
Expand Down Expand Up @@ -677,8 +678,23 @@ public ChangeRecordEntry executeRenameChange(String filename) throws LDIFExcepti

}

public ChangeRecordEntry executeLdifChange(String filename) throws IOException, LDIFException {
LDIFImportConfig importConfig = new LDIFImportConfig(filename);
public ChangeRecordEntry executeLdifChange(File file) throws IOException, LDIFException {
LDIFImportConfig importConfig = new LDIFImportConfig(file.getPath());
LDIFReader ldifReader = new LDIFReader(importConfig);
ChangeRecordEntry entry = ldifReader.readChangeRecord(false);

ModifyOperation modifyOperation = getInternalConnection()
.processModify((ModifyChangeRecordEntry) entry);

if (ResultCode.SUCCESS != modifyOperation.getResultCode()) {
throw new RuntimeException("LDAP operation error: "+modifyOperation.getResultCode()+": "+modifyOperation.getErrorMessage());
}
return entry;
}

public ChangeRecordEntry executeLdifChange(String ldif) throws IOException, LDIFException {
InputStream ldifInputStream = IOUtils.toInputStream(ldif, "UTF-8");
LDIFImportConfig importConfig = new LDIFImportConfig(ldifInputStream);
LDIFReader ldifReader = new LDIFReader(importConfig);
ChangeRecordEntry entry = ldifReader.readChangeRecord(false);

Expand Down

Large diffs are not rendered by default.

Expand Up @@ -80,9 +80,12 @@ public abstract class AbstractOpenDJTest extends AbstractIntegrationTest {
protected static final String ACCOUNT_NEW_WITH_PASSWORD_FILENAME = TEST_DIR_NAME + "/account-new-with-password.xml";;
protected static final String ACCOUNT_NEW_WITH_PASSWORD_OID = "c0c010c0-d34d-b44f-f11d-333222124422";

protected static final String ACCOUNT_NEW_DISABLED_FILENAME = TEST_DIR_NAME + "/account-new-disabled.xml";;
protected static final File ACCOUNT_NEW_DISABLED_FILE = new File (TEST_DIR, "account-new-disabled.xml");
protected static final String ACCOUNT_NEW_DISABLED_OID = "c0c010c0-d34d-b44f-f11d-d3d2d2d2d4d2";


protected static final File ACCOUNT_NEW_ENABLED_FILE = new File (TEST_DIR, "account-new-enabled.xml");
protected static final String ACCOUNT_NEW_ENABLED_OID = "c0c010c0-d34d-b44f-f11d-d3d2d2d2d4d3";

protected static final String ACCOUNT_DISABLE_SIMULATED_FILENAME = TEST_DIR_NAME + "/account-disable-simulated-opendj.xml";
protected static final String ACCOUNT_DISABLE_SIMULATED_OID = "dbb0c37d-9ee6-44a4-8d39-016dbce1aaaa";

Expand Down
Expand Up @@ -71,6 +71,7 @@
import com.evolveum.midpoint.schema.CapabilityUtil;
import com.evolveum.midpoint.schema.DeltaConvertor;
import com.evolveum.midpoint.schema.ResultHandler;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition;
import com.evolveum.midpoint.schema.processor.ResourceSchema;
import com.evolveum.midpoint.schema.result.OperationResult;
Expand Down Expand Up @@ -101,6 +102,7 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.CachingMetadataType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.CapabilityCollectionType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.LockoutStatusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ProvisioningScriptHostType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType;
Expand Down Expand Up @@ -897,14 +899,13 @@ public void test170DisableAccount() throws Exception{
}

@Test
public void test180AddDisabledAccount() throws Exception {
final String TEST_NAME = "test180AddDisabledAccount";
public void test175AddDisabledAccount() throws Exception {
final String TEST_NAME = "test175AddDisabledAccount";
TestUtil.displayTestTile(TEST_NAME);

OperationResult result = new OperationResult(TestOpenDJ.class.getName()
+ "." + TEST_NAME);
OperationResult result = new OperationResult(TestOpenDJ.class.getName() + "." + TEST_NAME);

ShadowType object = parseObjectTypeFromFile(ACCOUNT_NEW_DISABLED_FILENAME, ShadowType.class);
ShadowType object = parseObjectType(ACCOUNT_NEW_DISABLED_FILE, ShadowType.class);

IntegrationTestTools.display("Adding object", object);

Expand Down Expand Up @@ -945,6 +946,131 @@ public void test180AddDisabledAccount() throws Exception {
XmlTypeConverter.createXMLGregorianCalendar(1999, 8, 7, 6, 5, 4), repoDisableTimestamp);
}

/**
* Adding account with EXPLICIT enable. This triggers simulated activation in a different way.
*/
@Test
public void test176AddEnabledAccount() throws Exception {
final String TEST_NAME = "test176AddEnabledAccount";
TestUtil.displayTestTile(TEST_NAME);

OperationResult result = new OperationResult(TestOpenDJ.class.getName() + "." + TEST_NAME);

ShadowType object = parseObjectType(ACCOUNT_NEW_ENABLED_FILE, ShadowType.class);

IntegrationTestTools.display("Adding object", object);

// WHEN
String addedObjectOid = provisioningService.addObject(object.asPrismObject(), null, null, taskManager.createTaskInstance(), result);

// THEN
assertEquals(ACCOUNT_NEW_ENABLED_OID, addedObjectOid);

ShadowType accountType = repositoryService.getObject(ShadowType.class, ACCOUNT_NEW_ENABLED_OID,
null, result).asObjectable();
PrismAsserts.assertEqualsPolyString("Wrong ICF name (repo)", "uid=cook,ou=People,dc=example,dc=com", accountType.getName());

ShadowType provisioningAccountType = provisioningService.getObject(ShadowType.class, ACCOUNT_NEW_ENABLED_OID,
null, taskManager.createTaskInstance(), result).asObjectable();
PrismAsserts.assertEqualsPolyString("Wrong ICF name (provisioning)", "uid=cook,ou=People,dc=example,dc=com", provisioningAccountType.getName());

String uid = ShadowUtil.getSingleStringAttributeValue(accountType, ConnectorFactoryIcfImpl.ICFS_UID);
assertNotNull(uid);

// Check if object was modified in LDAP

SearchResultEntry response = openDJController.searchAndAssertByEntryUuid(uid);
display("LDAP account", response);

String disabled = openDJController.getAttributeValue(response, "ds-pwp-account-disabled");
assertNull("unexpected ds-pwp-account-disabled attribute in account "+uid, disabled);
}

@Test
public void test180GetUnlockedAccount() throws Exception {
final String TEST_NAME = "test180GetUnlockedAccount";
TestUtil.displayTestTile(TEST_NAME);

OperationResult result = new OperationResult(TestOpenDJ.class.getName() + "." + TEST_NAME);
Task task = taskManager.createTaskInstance();

// WHEN
PrismObject<ShadowType> shadow = provisioningService.getObject(ShadowType.class, ACCOUNT_NEW_OID,
null, task, result);

// THEN
result.computeStatus();
assertSuccess(result);

PrismAsserts.assertPropertyValue(shadow, SchemaConstants.PATH_ACTIVATION_LOCKOUT_STATUS,
LockoutStatusType.NORMAL);
}

@Test
public void test182GetLockedAccount() throws Exception {
final String TEST_NAME = "test182GetLockedAccount";
TestUtil.displayTestTile(TEST_NAME);

OperationResult result = new OperationResult(TestOpenDJ.class.getName() + "." + TEST_NAME);
Task task = taskManager.createTaskInstance();

openDJController.executeLdifChange(
"dn: uid=will,ou=People,dc=example,dc=com\n" +
"changetype: modify\n" +
"replace: pager\n" +
"pager: 1"
);

// WHEN
PrismObject<ShadowType> shadow = provisioningService.getObject(ShadowType.class, ACCOUNT_NEW_OID,
null, task, result);

// THEN
result.computeStatus();
assertSuccess(result);

PrismAsserts.assertPropertyValue(shadow, SchemaConstants.PATH_ACTIVATION_LOCKOUT_STATUS,
LockoutStatusType.LOCKED);
}

@Test
public void test184UnlockAccount() throws Exception{
final String TEST_NAME = "test184UnlockAccount";
TestUtil.displayTestTile(TEST_NAME);
Task task = taskManager.createTaskInstance(TestOpenDJ.class.getName()+"."+TEST_NAME);
OperationResult result = task.getResult();

ObjectDelta<ShadowType> delta = ObjectDelta.createModificationReplaceProperty(ShadowType.class,
ACCOUNT_NEW_OID, SchemaConstants.PATH_ACTIVATION_LOCKOUT_STATUS, prismContext, LockoutStatusType.NORMAL);

// WHEN
provisioningService.modifyObject(ShadowType.class, delta.getOid(),
delta.getModifications(), null, null, task, result);

// THEN
result.computeStatus();
assertSuccess(result);

PrismObject<ShadowType> shadow = provisioningService.getObject(ShadowType.class,
ACCOUNT_NEW_OID, null, taskManager.createTaskInstance(), result);

display("Object after change",shadow);

String uid = ShadowUtil.getSingleStringAttributeValue(shadow.asObjectable(), ConnectorFactoryIcfImpl.ICFS_UID);
assertNotNull(uid);

// Check if object was modified in LDAP

SearchResultEntry response = openDJController.searchAndAssertByEntryUuid(uid);
display("LDAP account", response);

String pager = openDJController.getAttributeValue(response, "pager");
assertNull("Pager attribute found in account "+uid+": "+pager, pager);

PrismAsserts.assertPropertyValue(shadow, SchemaConstants.PATH_ACTIVATION_LOCKOUT_STATUS,
LockoutStatusType.NORMAL);
}

@Test
public void test190AddGroupSwashbucklers() throws Exception {
final String TEST_NAME = "test190AddGroupSwashbucklers";
Expand Down
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2010-2014 Evolveum
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->


<c:account oid="c0c010c0-d34d-b44f-f11d-d3d2d2d2d4d3"
xmlns:c="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:icfs="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/resource-schema-3"
xmlns:ri="http://midpoint.evolveum.com/xml/ns/public/resource/instance/ef2bc95b-76e0-59e2-86d6-3d4f02d3ffff">
<c:name>uid=cook,ou=People,dc=example,dc=com</c:name>
<c:resourceRef oid="ef2bc95b-76e0-59e2-86d6-3d4f02d3ffff" />
<c:objectClass>ri:AccountObjectClass</c:objectClass>
<c:attributes>
<icfs:name>uid=cook,ou=People,dc=example,dc=com</icfs:name>
<ri:uid>cook</ri:uid>
<ri:cn>The Cook</ri:cn>
<ri:sn>Cook</ri:sn>
</c:attributes>
<c:activation>
<c:administrativeStatus>enabled</c:administrativeStatus>
</c:activation>
</c:account>
Expand Up @@ -121,6 +121,12 @@
<cap:enableValue/>
<cap:disableValue>true</cap:disableValue>
</cap:status>
<cap:lockoutStatus>
<!-- This is fake. But OpenDJ lockout attribute is not modifiable using normal LDAP operations. -->
<cap:attribute>ri:pager</cap:attribute>
<cap:normalValue/>
<cap:lockedValue>1</cap:lockedValue>
</cap:lockoutStatus>
</cap:activation>
<!--
<cap:credentials>
Expand Down
Expand Up @@ -299,7 +299,7 @@ public class TestSanity extends AbstractModelIntegrationTest {
private static final String REQUEST_ACCOUNT_MODIFY_ATTRS_FILENAME = REQUEST_DIR_NAME + "account-modify-attrs.xml";

private static final String LDIF_WILL_FILENAME = REQUEST_DIR_NAME + "will.ldif";
private static final String LDIF_WILL_MODIFY_FILENAME = REQUEST_DIR_NAME + "will-modify.ldif";
private static final File LDIF_WILL_MODIFY_FILE = new File (REQUEST_DIR_NAME, "will-modify.ldif");
private static final String LDIF_WILL_WITHOUT_LOCATION_FILENAME = REQUEST_DIR_NAME + "will-without-location.ldif";
private static final String WILL_NAME = "wturner";

Expand All @@ -312,7 +312,7 @@ public class TestSanity extends AbstractModelIntegrationTest {
private static final String LDIF_ELAINE_FILENAME = REQUEST_DIR_NAME + "elaine.ldif";
private static final String ELAINE_NAME = "elaine";

private static final String LDIF_GIBBS_MODIFY_FILENAME = REQUEST_DIR_NAME + "gibbs-modify.ldif";
private static final File LDIF_GIBBS_MODIFY_FILE = new File (REQUEST_DIR_NAME, "gibbs-modify.ldif");

private static final String LDIF_HERMAN_FILENAME = REQUEST_DIR_NAME + "herman.ldif";

Expand Down Expand Up @@ -999,7 +999,8 @@ public void test010AddUser() throws Exception {
*/
@Test
public void test013AddOpenDjAccountToUser() throws Exception {
TestUtil.displayTestTile("test013AddOpenDjAccountToUser");
final String TEST_NAME = "test013AddOpenDjAccountToUser";
TestUtil.displayTestTile(TEST_NAME);
try{
// GIVEN
checkRepoOpenDjResource();
Expand All @@ -1014,9 +1015,11 @@ public void test013AddOpenDjAccountToUser() throws Exception {
REQUEST_USER_MODIFY_ADD_ACCOUNT_OPENDJ_FILENAME, ObjectDeltaType.class);

// WHEN
TestUtil.displayWhen(TEST_NAME);
OperationResultType result = modifyObjectViaModelWS(objectChange);

// THEN
TestUtil.displayThen(TEST_NAME);
assertNoRepoCache();
displayJaxb("modifyObject result", result, SchemaConstants.C_RESULT);
TestUtil.assertSuccess("modifyObject has failed", result);
Expand Down Expand Up @@ -2829,7 +2832,7 @@ public void test102LiveSyncModify() throws Exception {

// WHEN
display("Modifying LDAP entry");
ChangeRecordEntry entry = openDJController.executeLdifChange(LDIF_WILL_MODIFY_FILENAME);
ChangeRecordEntry entry = openDJController.executeLdifChange(LDIF_WILL_MODIFY_FILE);

// THEN
display("Entry from LDIF", entry);
Expand Down Expand Up @@ -3004,7 +3007,7 @@ public void test200ImportFromResource() throws Exception {
+ "." + TEST_NAME);

// Make sure Mr. Gibbs has "l" attribute set to the same value as an outbound expression is setting
ChangeRecordEntry entry = openDJController.executeLdifChange(LDIF_GIBBS_MODIFY_FILENAME);
ChangeRecordEntry entry = openDJController.executeLdifChange(LDIF_GIBBS_MODIFY_FILE);
display("Entry from LDIF", entry);

// Let's add an entry with multiple uids.
Expand Down

0 comments on commit 710e55f

Please sign in to comment.