SearchOperationTestCase.java revision 9aa1482c49865483f798f91ef7d16f03cc3ec811
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at legal-notices/CDDLv1_0.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2006-2010 Sun Microsystems, Inc.
* Portions Copyright 2011-2015 ForgeRock AS
*/
@SuppressWarnings("javadoc")
public class SearchOperationTestCase extends OperationTestCase
{
private int ldapAttrCount;
{
{
}
{
}
"dn: cn=subentry," + BASE,
"objectclass: ldapsubentry");
// Add a test entry.
"dn: uid=rogasawara," + BASE,
"userpassword: password",
"objectclass: top",
"objectclass: person",
"objectclass: organizationalPerson",
"objectclass: inetOrgPerson",
"uid: rogasawara",
"mail: rogasawara@airius.co.jp",
"givenname;lang-ja:: 44Ot44OJ44OL44O8",
"sn;lang-ja:: 5bCP56yg5Y6f",
"cn;lang-ja:: 5bCP56yg5Y6fIOODreODieODi+ODvA==",
"title;lang-ja:: 5Za25qWt6YOoIOmDqOmVtw==",
"preferredlanguage: ja",
"givenname:: 44Ot44OJ44OL44O8",
"sn:: 5bCP56yg5Y6f",
"cn:: 5bCP56yg5Y6fIOODreODieODi+ODvA==",
"title:: 5Za25qWt6YOoIOmDqOmVtw==",
"givenname;lang-ja;phonetic:: 44KN44Gp44Gr44O8",
"sn;lang-ja;phonetic:: 44GK44GM44GV44KP44KJ",
"cn;lang-ja;phonetic:: 44GK44GM44GV44KP44KJIOOCjeOBqeOBq+ODvA==",
"title;lang-ja;phonetic:: " +
"44GI44GE44GO44KH44GG44G2IOOBtuOBoeOCh+OBhg==",
"givenname;lang-en: Rodney",
"sn;lang-en: Ogasawara",
"cn;lang-en: Rodney Ogasawara",
"title;lang-en: Sales, Director"
);
// Calculate the total number of LDAP attributes in this entry.
{
ldapAttrCount += a.size();
}
// The add operation changes the attributes, so let's duplicate the entry.
// referral entry.
"dn: ou=People," + BASE,
"objectclass: extensibleobject",
"objectclass: referral",
// level 1 entry.
"dn: ou=level1," + BASE,
"objectclass: top",
"objectclass: organizationalunit",
"ou: level1");
// level 2 entry.
"dn: ou=level2,ou=level1," + BASE,
"objectclass: top",
"objectclass: organizationalunit",
"ou: level2");
// referral 2 entry.
"dn: ou=level3,ou=level2,ou=level1," + BASE,
"objectclass: extensibleobject",
"objectclass: referral",
}
{
}
{
return new Operation[0];
}
/**
* Invokes a number of operation methods on the provided search operation
* for which all processing has been completed.
*
* @param searchOperation The operation to be tested.
*/
{
// assertEquals(InvocationCounterPlugin.getPreParseCount(), 1);
// assertEquals(InvocationCounterPlugin.getPreOperationCount(), 1);
// assertEquals(InvocationCounterPlugin.getPostOperationCount(), 1);
// assertEquals(InvocationCounterPlugin.getPostResponseCount(), 1);
}
{
}
throws Exception
{
// Establish a connection to the server.
try
{
LDAPWriter w = new LDAPWriter(s);
bindAsManager(w, r);
// Since we are going to be watching the post-response count, we need to
// wait for the server to become idle before kicking off the next request
// to ensure that any remaining post-response processing from the previous
// operation has completed.
w.writeMessage(message);
{
switch (message.getProtocolOpType())
{
break;
break;
// assertEquals(InvocationCounterPlugin.waitForPostResponse(), 1);
searchesDone++;
break;
}
}
return searchResultEntry;
}
finally
{
s.close();
}
}
{
// Since we are going to be watching the post-response count, we need to
// wait for the server to become idle before kicking off the next request to
// ensure that any remaining post-response processing from the previous
// operation has completed.
w.writeMessage(message);
message = r.readMessage();
// assertEquals(InvocationCounterPlugin.waitForPostResponse(), 1);
}
@Test
public void testSearchInternal() throws Exception
{
}
@Test
public void testSearchInternalUnspecifiedAttributes() throws Exception
{
InternalSearchOperation searchOperation = newInternalSearchOperation("(objectclass=inetorgperson)");
// Search results contain objectClass as an attribute.
}
@Test
public void testSearchInternalUnspecifiedAttributesOmitValues() throws Exception
{
SearchRequest request = Requests.newSearchRequest(BASE, SearchScope.WHOLE_SUBTREE, "(objectclass=inetorgperson)")
.setTypesOnly(true);
}
@Test
public void testSearchInternalAllOperationalAttributes() throws Exception
{
InternalSearchOperation searchOperation = newInternalSearchOperation("(objectclass=inetorgperson)", "+");
}
@Test
public void testSearchInternalAllUserAndOperationalAttributes() throws Exception
{
InternalSearchOperation searchOperation = newInternalSearchOperation("(objectclass=inetorgperson)", "*", "+");
// Search results contain objectClass as an attribute.
}
@Test
public void testSearchInternalAllUserAttributesPlusSelectedOperational() throws Exception
{
// Search results contain objectClass as an attribute.
}
@Test
public void testSearchInternalSelectedAttributes() throws Exception
{
}
private InternalSearchOperation newInternalSearchOperation(String filter, String... attributes) throws Exception
{
}
@Test
public void testSearchExternalUnspecifiedAttributes() throws Exception
{
false,
null);
}
@Test
public void testSearchExternalAllUserAttributes() throws Exception
{
false,
}
@Test
public void testSearchExternalUnspecifiedAttributesOmitValues()
throws Exception
{
true,
null);
// The attributes will include the objectclass type.
{
}
}
@Test
public void testSearchExternalAllUserAttributesOmitValues() throws Exception
{
true,
// The attributes will include the objectclass type.
{
}
}
@Test
public void testSearchExternalObjectClassAttribute() throws Exception
{
false,
}
@Test
public void testSearchExternalObjectClassAttributeOmitValues()
throws Exception
{
true,
}
@Test
public void testSearchExternalSelectedAttributes() throws Exception
{
false,
}
@Test
public void testSearchExternalAttributeWithSubtypes() throws Exception
{
false,
}
@Test
public void testSearchExternalAttributeWithSubtypesOmitValues()
throws Exception
{
true,
{
}
}
@Test
public void testSearchExternalAttributeWithOptions() throws Exception
{
false,
}
@Test
public void testSearchExternalMatchedValues() throws Exception
{
// Add a matched values control.
ArrayList<MatchedValuesFilter> filters = newArrayList(MatchedValuesFilter.createFromLDAPFilter(ldapFilter));
false,
null);
// Per RFC 3876, an attribute that has no values selected is returned
// with an empty set of values. We should therefore expect all the
// attributes but only one value.
int valueCount = 0;
{
}
}
@Test
public void testSearchInternalReferences() throws Exception
{
SearchRequest request = newSearchRequest(BASE, SearchScope.WHOLE_SUBTREE, "(objectclass=inetorgperson)");
// One contains 2 URLs, the other contains 3. Cannot guarantee
// ordering of the returned references, so just check the total is correct.
}
/**
* This does a single-level search that finds one referral object, but
* not the one in a deeper subtree.
*
* @throws Exception
*/
@Test
public void testSearchSingleDeepReferences() throws Exception
{
}
@Test
public void testSearchInternalSubEntryEqualityFilter() throws Exception
{
SearchRequest request = newSearchRequest(BASE, SearchScope.WHOLE_SUBTREE, "(objectclass=ldapsubentry)");
}
@Test
public void testSearchInternalSubEntryControl() throws Exception
{
.addControl(new SubentriesControl(true, true));
}
@Test
public void testSearchInternalLegacySubEntryControl() throws Exception
{
}
@Test
public void testSearchInternalSubEntryAndFilter() throws Exception
{
SearchRequest request1 = newSearchRequest(BASE, SearchScope.WHOLE_SUBTREE, "(&(cn=*)(objectclass=ldapsubentry))");
}
@Test
public void testSearchInternalSubEntryOrFilter() throws Exception
{
newSearchRequest(BASE, SearchScope.WHOLE_SUBTREE, "(|(objectclass=ldapsubentry)(objectclass=top))");
}
@Test
public void testSearchInternalMatchedDN() throws Exception
{
SearchRequest request = newSearchRequest(DN.valueOf("ou=nonexistent,o=test"), SearchScope.WHOLE_SUBTREE);
}
/**
* Determines how attributes should be filtered in search operations.
*/
private enum AttributeFilterType {
}
/**
* Returns test data for testSearchInternalAttributeFilters.
*
* @return The test data.
*/
public Object[][] createTestSearchInternalAttributeFiltersData()
{
// It was quicker to cut n paste...
return new Object[][] {
{AttributeFilterType.DEFAULT, false, false, false},
{AttributeFilterType.DEFAULT, false, false, true},
{AttributeFilterType.DEFAULT, false, true, false},
{AttributeFilterType.DEFAULT, false, true, true},
{AttributeFilterType.DEFAULT, true, false, false},
{AttributeFilterType.DEFAULT, true, false, true},
{AttributeFilterType.DEFAULT, true, true, false},
{AttributeFilterType.DEFAULT, true, true, true},
{AttributeFilterType.WILDCARDS, false, false, false},
{AttributeFilterType.WILDCARDS, false, false, true},
{AttributeFilterType.WILDCARDS, false, true, false},
{AttributeFilterType.WILDCARDS, false, true, true},
{AttributeFilterType.WILDCARDS, true, false, false},
{AttributeFilterType.WILDCARDS, true, false, true},
{AttributeFilterType.WILDCARDS, true, true, false},
{AttributeFilterType.WILDCARDS, true, true, true},
{AttributeFilterType.ENUMERATED, false, false, false},
{AttributeFilterType.ENUMERATED, false, false, true},
{AttributeFilterType.ENUMERATED, false, true, false},
{AttributeFilterType.ENUMERATED, false, true, true},
{AttributeFilterType.ENUMERATED, true, false, false},
{AttributeFilterType.ENUMERATED, true, false, true},
{AttributeFilterType.ENUMERATED, true, true, false},
{AttributeFilterType.ENUMERATED, true, true, true},
};
}
/**
* Tests that attribute filtering is performed correctly for real and
* virtual attributes when various combinations of typesOnly, and the
* real-attributes-only and virtual-attributes-only controls are used
* (issues 3446 and 3726).
*
* @param filterType
* Specifies how attributes should be filtered.
* @param typesOnly
* Strip attribute values.
* @param stripVirtualAttributes
* Strip virtual attributes.
* @param stripRealAttributes
* Strip real attributes.
* @throws Exception
* If an unexpected problem occurs.
*/
public void testSearchInternalAttributeFilters(
boolean stripVirtualAttributes, boolean stripRealAttributes)
throws Exception
{
// Real attributes (these are all user attributes).
// Virtual attributes (these are all operational attributes).
"subschemasubentry", "entrydn", "ismemberof");
"objectClass: top",
"objectClass: person",
"objectClass: organizationalPerson",
"objectClass: inetOrgPerson",
"uid: test.user",
"givenName: Test",
"sn: User",
"cn: Test User",
"userPassword: password");
switch (filterType)
{
case DEFAULT:
// Only user attributes.
break;
case WILDCARDS:
break;
case ENUMERATED:
break;
}
if (stripRealAttributes)
{
}
{
}
// Check real attributes.
{
if (stripRealAttributes)
{
{
}
}
else
{
{
}
else
{
if (typesOnly)
{
{
}
}
else
{
{
}
}
}
}
}
// Check virtual (operational) attributes.
{
{
{
}
}
{
{
}
}
{
// isMemberOf should never be returned as user is not in any
// groups.
{
}
}
else
{
{
}
else
{
if (typesOnly)
{
{
}
}
else
{
{
}
}
}
}
}
}
/**
* Returns test data for testSearchInternalUserAttributeNames.
*
* @return The test data.
*/
public Object[][] createTestSearchInternalUserAttributeNamesData()
{
// First array is the requested attributes.
// Second array is the expected attribute names in the entry.
return new Object[][] {
{
{
{
{
{
"commonName;LANG-FR", "entrydn", "CREATETIMESTAMP"),
}
/**
* Tests that attributes are returned from internal searches using the
* attribute name requested by the user.
*
* @param requestedAttributes
* The list of requested attributes names.
* @param expectedAttributes
* The list of expected attribute names.
* @throws Exception
* If an unexpected problem occurs.
*/
public void testSearchInternalUserAttributeNames(
throws Exception
{
"objectClass: top",
"objectClass: person",
"objectClass: organizationalPerson",
"objectClass: inetOrgPerson",
"uid: test.user",
"givenName: Test",
"sn: User",
"cn: Test User",
"cn;lang-fr: Test Usager",
"userPassword: password");
// Check all expected attributes are present and have
// the user requested name.
{
}
}
/**
* Tests that attributes are returned from external searches using the
* attribute name requested by the user.
*
* @param requestedAttributes
* The list of requested attributes names.
* @param expectedAttributes
* The list of expected attribute names.
* @throws Exception
* If an unexpected problem occurs.
*/
public void testSearchExternalUserAttributeNames(
throws Exception
{
"objectClass: top",
"objectClass: person",
"objectClass: organizationalPerson",
"objectClass: inetOrgPerson",
"uid: test.user",
"givenName: Test",
"sn: User",
"cn: Test User",
"cn;lang-fr: Test Usager",
"userPassword: password");
false,
// Check all expected attributes are present and have
// the user requested name.
{
}
}
/**
* Tests the one-level search with a lower allid threshold value.
*/
@Test
public void testOneLevelSearchWithAllIDThreshold() throws Exception
{
//Set a lower value for allid threshold. We set 2.
//Add entries.
"dn: ou=unit1,dc=example,dc=com\n" +
"objectclass: top\n" +
"objectclass: organizationalUnit\n" +
"ou: unit1\n" +
"\n" +
"dn: ou=unit2,dc=example,dc=com\n" +
"objectclass: top\n" +
"objectclass: organizationalUnit\n" +
"ou: unit2\n" +
"\n" +
"dn: ou=unit3,dc=example,dc=com\n" +
"objectclass: top\n" +
"objectclass: organizationalUnit\n" +
"ou: unit3\n");
{
"-h", "127.0.0.1",
"-D","cn=directory manager",
"-w","password",
"-a",
"-f", filePath
};
newSearchRequest("dc=example,dc=com", SearchScope.SINGLE_LEVEL, "(objectclass=organizationalUnit)");
//restore the allid threshold.
setAllIdThreshold(4000);
}
/** Sets a value of the allid threshold. */
{
//Change the allid threshold value.
"dn: ds-cfg-backend-id=userRoot,cn=Backends,cn=config",
"changetype: modify",
"delete: ds-cfg-index-entry-limit",
"-",
"add: ds-cfg-index-entry-limit",
"ds-cfg-index-entry-limit: "+value
);
{
"-h", "127.0.0.1",
"-D","cn=directory manager",
"-w","password",
"-a",
"-f", filePath
};
}
}