Skip to content

Commit

Permalink
Tests for DN search error handling (MID-3730)
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Feb 6, 2017
1 parent 355c0f3 commit 0a4862b
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 0 deletions.
Expand Up @@ -78,6 +78,8 @@ public abstract class AbstractOpenDjTest extends AbstractIntegrationTest {
protected static final String ACCOUNT_JACK_NAME = "jack";
protected static final File ACCOUNT_JACK_CHANGE_FILE = new File(TEST_DIR, "account-jack-change.xml");

protected static final String ACCOUNT_BARBOSSA_DN = "uid=hbarbossa,ou=People,dc=example,dc=com";

protected static final File ACCOUNT_MODIFY_PASSWORD_FILE = new File(TEST_DIR_NAME, "account-modify-password.xml");
protected static final String ACCOUNT_MODIFY_PASSWORD_OID = "c0c010c0-d34d-b44f-f11d-333222444566";

Expand Down
Expand Up @@ -73,6 +73,7 @@
import com.evolveum.midpoint.prism.match.UuidMatchingRule;
import com.evolveum.midpoint.prism.match.XmlMatchingRule;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.query.ObjectFilter;
import com.evolveum.midpoint.prism.query.ObjectOrdering;
import com.evolveum.midpoint.prism.query.ObjectPaging;
import com.evolveum.midpoint.prism.query.ObjectQuery;
Expand Down Expand Up @@ -1618,10 +1619,15 @@ public void test202SearchObjectsCompexFilter() throws Exception {
rememberConnectorSimulatedPagingSearchCount();

// WHEN
TestUtil.displayWhen(TEST_NAME);
List<PrismObject<ShadowType>> objListType =
provisioningService.searchObjects(ShadowType.class, query, null, null, result);

// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);

for (PrismObject<ShadowType> objType : objListType) {
assertNotNull("Null search result", objType);
display("found object", objType);
Expand All @@ -1632,6 +1638,83 @@ public void test202SearchObjectsCompexFilter() throws Exception {
assertConnectorOperationIncrement(1, 3);
assertConnectorSimulatedPagingSearchIncrement(0);
}

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

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

ObjectQuery query = createAccountShadowQuerySecondaryIdentifier(ACCOUNT_BARBOSSA_DN, resource);

rememberConnectorOperationCount();
rememberConnectorSimulatedPagingSearchCount();

// WHEN
TestUtil.displayWhen(TEST_NAME);
List<PrismObject<ShadowType>> objListType =
provisioningService.searchObjects(ShadowType.class, query, null, null, result);

// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);

for (PrismObject<ShadowType> objType : objListType) {
assertNotNull("Null search result", objType);
display("found object", objType);
}

assertEquals("Unexpected number of objects found", 1, objListType.size());

PrismObject<ShadowType> shadow = objListType.get(0);
assertAttribute(shadow, "dn", ACCOUNT_BARBOSSA_DN);

assertConnectorOperationIncrement(1, 3);
assertConnectorSimulatedPagingSearchIncrement(0);
}

/**
* Search for non-existent DN should return no results. It should NOT
* throw an error.
* MID-3730
*/
@Test
public void test205SearchObjectsByDnNotExists() throws Exception {
final String TEST_NAME = "test205SearchObjectsByDnNotExists";
TestUtil.displayTestTile(TEST_NAME);

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

ObjectQuery query = createAccountShadowQuerySecondaryIdentifier(
"uid=DoesNOTeXXXiSt,ou=People,dc=example,dc=com", resource);

rememberConnectorOperationCount();
rememberConnectorSimulatedPagingSearchCount();

// WHEN
TestUtil.displayWhen(TEST_NAME);
List<PrismObject<ShadowType>> objListType =
provisioningService.searchObjects(ShadowType.class, query, null, null, result);

// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);

for (PrismObject<ShadowType> objType : objListType) {
assertNotNull("Null search result", objType);
display("found object", objType);
}

assertEquals("Unexpected number of objects found", 0, objListType.size());

assertConnectorOperationIncrement(1, 3);
assertConnectorSimulatedPagingSearchIncrement(0);
}

@Test
public void test230SearchObjectsPagedNoOffset() throws Exception {
Expand Down
Expand Up @@ -1067,6 +1067,21 @@ protected ObjectQuery createShadowQuerySecondaryIdentifier(ObjectClassComplexTyp
.and().item(ShadowType.F_RESOURCE_REF).ref(resource.getOid())
.build();
}

protected ObjectQuery createAccountShadowQueryByAttribute(String attributeName, String attributeValue, PrismObject<ResourceType> resource) throws SchemaException {
RefinedResourceSchema rSchema = RefinedResourceSchemaImpl.getRefinedSchema(resource);
RefinedObjectClassDefinition rAccount = rSchema.getDefaultRefinedDefinition(ShadowKindType.ACCOUNT);
return createShadowQueryByAttribute(rAccount, attributeName, attributeValue, resource);
}

protected ObjectQuery createShadowQueryByAttribute(ObjectClassComplexTypeDefinition rAccount, String attributeName, String attributeValue, PrismObject<ResourceType> resource) throws SchemaException {
ResourceAttributeDefinition<Object> attrDef = rAccount.findAttributeDefinition(attributeName);
return QueryBuilder.queryFor(ShadowType.class, prismContext)
.itemWithDef(attrDef, ShadowType.F_ATTRIBUTES, attrDef.getName()).eq(attributeValue)
.and().item(ShadowType.F_OBJECT_CLASS).eq(rAccount.getTypeName())
.and().item(ShadowType.F_RESOURCE_REF).ref(resource.getOid())
.build();
}

protected PrismObjectDefinition<UserType> getUserDefinition() {
return prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(UserType.class);
Expand Down
Expand Up @@ -323,6 +323,7 @@ public void test100SeachJackBySamAccountName() throws Exception {
SearchResultList<PrismObject<ShadowType>> shadows = modelService.searchObjects(ShadowType.class, query, null, task, result);

// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);

Expand All @@ -344,6 +345,88 @@ public void test100SeachJackBySamAccountName() throws Exception {
assertLdapConnectorInstances(1);
}

/**
* MID-3730
*/
@Test
public void test101SeachJackByDn() throws Exception {
final String TEST_NAME = "test101SeachJackByDn";
TestUtil.displayTestTile(this, TEST_NAME);

// GIVEN
Task task = taskManager.createTaskInstance(this.getClass().getName() + "." + TEST_NAME);
OperationResult result = task.getResult();

String jackDn = toAccountDn(ACCOUNT_JACK_SAM_ACCOUNT_NAME, ACCOUNT_JACK_FULL_NAME);
ObjectQuery query = createAccountShadowQueryByAttribute("dn", jackDn, resource);

rememberConnectorOperationCount();
rememberConnectorSimulatedPagingSearchCount();

// WHEN
TestUtil.displayWhen(TEST_NAME);
SearchResultList<PrismObject<ShadowType>> shadows = modelService.searchObjects(ShadowType.class, query, null, task, result);

// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);

assertEquals("Unexpected search result: "+shadows, 1, shadows.size());

PrismObject<ShadowType> shadow = shadows.get(0);
display("Shadow", shadow);
assertAccountShadow(shadow, jackDn);

// assertConnectorOperationIncrement(2);
assertConnectorSimulatedPagingSearchIncrement(0);

SearchResultMetadata metadata = shadows.getMetadata();
if (metadata != null) {
assertFalse(metadata.isPartialResults());
}

assertLdapConnectorInstances(1);
}

/**
* Search for non-existent DN should return no results. It should NOT
* throw an error.
*
* MID-3730
*/
@Test
public void test102SeachNotExistByDn() throws Exception {
final String TEST_NAME = "test102SeachNotExistByDn";
TestUtil.displayTestTile(this, TEST_NAME);

// GIVEN
Task task = taskManager.createTaskInstance(this.getClass().getName() + "." + TEST_NAME);
OperationResult result = task.getResult();

String dn = toAccountDn("idonoexist", "I am a Fiction");
ObjectQuery query = createAccountShadowQueryByAttribute("dn", dn, resource);

rememberConnectorOperationCount();
rememberConnectorSimulatedPagingSearchCount();

// WHEN
TestUtil.displayWhen(TEST_NAME);
SearchResultList<PrismObject<ShadowType>> shadows = modelService.searchObjects(ShadowType.class, query, null, task, result);

// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);

assertEquals("Unexpected search result: "+shadows, 0, shadows.size());

// assertConnectorOperationIncrement(2);
assertConnectorSimulatedPagingSearchIncrement(0);

assertLdapConnectorInstances(1);
}

@Test
public void test105SeachPiratesByCn() throws Exception {
final String TEST_NAME = "test105SeachPiratesByCn";
Expand Down

0 comments on commit 0a4862b

Please sign in to comment.