UniqueAttributePluginTestCase.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 2008 Sun Microsystems, Inc.
* Portions Copyright 2011-2015 ForgeRock AS
*/
/**
* Unit test to test the unique attribute plugin.
*/
public class UniqueAttributePluginTestCase extends PluginTestCase {
private DN uidConfigDN;
private DN testConfigDN;
/**
* Ensures that the Directory Server is running.
*
* @throws Exception If an unexpected problem occurs.
*/
public void startServer()
throws Exception
{
//Add entries to two backends to test public naming context.
}
/**
* Clears configuration information before each method run.
*
* @throws Exception If an unexpected problem occurs.
*/
public void clearConfigEntries() throws Exception {
//Put an attribute type there that won't impact the rest of the unit
//tests.
}
/**
* Clears things up after the unit test is completed.
*
* @throws Exception If an unexpected problem occurs.
*/
clearAcis("o=test");
}
/**
* Retrieves a set of valid configuration entries that may be used to
* initialize the plugin.
*
* @return An array of config entries.
*
* @throws Exception If an unexpected problem occurs.
*/
public Object[][] getValidConfigs()
throws Exception
{
"dn: cn=UID Unique Attribute,cn=Plugins,cn=config",
"objectClass: top",
"objectClass: ds-cfg-plugin",
"objectClass: ds-cfg-unique-attribute-plugin",
"cn: UID Unique Attribute",
"ds-cfg-java-class: org.opends.server.plugins.UniqueAttributePlugin",
"ds-cfg-enabled: true",
"ds-cfg-plugin-type: preOperationAdd",
"ds-cfg-plugin-type: preOperationModify",
"ds-cfg-plugin-type: preOperationModifyDN",
"ds-cfg-type: uid",
"",
"dn: cn=mail Unique Attribute,cn=Plugins,cn=config",
"objectClass: top",
"objectClass: ds-cfg-plugin",
"objectClass: ds-cfg-unique-attribute-plugin",
"cn: mail Unique Attribute",
"ds-cfg-java-class: org.opends.server.plugins.UniqueAttributePlugin",
"ds-cfg-enabled: true",
"ds-cfg-plugin-type: preOperationAdd",
"ds-cfg-plugin-type: preOperationModify",
"ds-cfg-plugin-type: preOperationModifyDN",
"ds-cfg-type: mail",
"ds-cfg-type: sn",
"",
"dn: cn=phone Unique Attribute,cn=Plugins,cn=config",
"objectClass: top",
"objectClass: ds-cfg-plugin",
"objectClass: ds-cfg-unique-attribute-plugin",
"cn: phone Unique Attribute",
"ds-cfg-java-class: org.opends.server.plugins.UniqueAttributePlugin",
"ds-cfg-enabled: true",
"ds-cfg-plugin-type: preOperationAdd",
"ds-cfg-plugin-type: preOperationModify",
"ds-cfg-plugin-type: preOperationModifyDN",
"ds-cfg-type: telephoneNumber",
"ds-cfg-type: mobile",
"ds-cfg-type: facsimileTelephoneNumber",
"ds-cfg-base-dn: dc=example,dc=com",
"ds-cfg-base-dn: o=test",
"",
"dn: cn=UID0 Unique Attribute,cn=Plugins,cn=config",
"objectClass: top",
"objectClass: ds-cfg-plugin",
"objectClass: ds-cfg-unique-attribute-plugin",
"cn: UUID0 Unique Attribute",
"ds-cfg-java-class: org.opends.server.plugins.UniqueAttributePlugin",
"ds-cfg-enabled: true",
"ds-cfg-plugin-type: preOperationAdd",
"ds-cfg-type: uid",
"",
"dn: cn=UID1 Unique Attribute,cn=Plugins,cn=config",
"objectClass: top",
"objectClass: ds-cfg-plugin",
"objectClass: ds-cfg-unique-attribute-plugin",
"cn: UUID1 Unique Attribute",
"ds-cfg-java-class: org.opends.server.plugins.UniqueAttributePlugin",
"ds-cfg-enabled: true",
"ds-cfg-plugin-type: preOperationModify",
"ds-cfg-type: uid",
"",
"dn: cn=UID2 Unique Attribute,cn=Plugins,cn=config",
"objectClass: top",
"objectClass: ds-cfg-plugin",
"objectClass: ds-cfg-unique-attribute-plugin",
"cn: UUID2 Unique Attribute",
"ds-cfg-java-class: org.opends.server.plugins.UniqueAttributePlugin",
"ds-cfg-enabled: true",
"ds-cfg-plugin-type: preOperationModifyDN",
"ds-cfg-type: uid");
{
}
return array;
}
/**
* Tests the process of initializing the server with valid configurations.
*
* @param e The configuration entry to use for the initialization.
*
* @throws Exception If an unexpected problem occurs.
*/
public void testInitializeWithValidConfigs(Entry e)
throws Exception
{
}
/**
* Retrieves a set of valid configuration entries that may be used to
* initialize the plugin.
* @return An array of config entries.
*
* @throws Exception If an unexpected problem occurs.
*/
public Object[][] getInValidConfigs()
throws Exception
{
"dn: cn=UID Unique Attribute,cn=Plugins,cn=config",
"objectClass: top",
"objectClass: ds-cfg-plugin",
"objectClass: ds-cfg-unique-attribute-plugin",
"cn: UID Unique Attribute",
"ds-cfg-java-class: org.opends.server.plugins.UniqueAttributePlugin",
"ds-cfg-enabled: true",
"ds-cfg-plugin-type: preOperationAdd",
"ds-cfg-plugin-type: preOperationModify",
"ds-cfg-plugin-type: preOperationModifyDN",
"",
"dn: cn=UID Unique Attribute,cn=Plugins,cn=config",
"objectClass: top",
"objectClass: ds-cfg-plugin",
"objectClass: ds-cfg-unique-attribute-plugin",
"cn: UID Unique Attribute",
"ds-cfg-java-class: org.opends.server.plugins.UniqueAttributePlugin",
"ds-cfg-enabled: true",
"ds-cfg-plugin-type: preOperationAdd",
"ds-cfg-plugin-type: preOperationModify",
"ds-cfg-plugin-type: ldifImport",
"",
"dn: cn=phone Unique Attribute,cn=Plugins,cn=config",
"objectClass: top",
"objectClass: ds-cfg-plugin",
"cn: phone Unique Attribute",
"ds-cfg-java-class: org.opends.server.plugins.UniqueAttributePlugin",
"ds-cfg-enabled: true",
"ds-cfg-plugin-type: preOperationAdd",
"ds-cfg-plugin-type: preOperationModify",
"ds-cfg-plugin-type: preOperationModifyDN",
"ds-cfg-type: telephone",
"ds-cfg-type: mobile",
"ds-cfg-type: fax",
"ds-cfg-base-dn: dc=example,dc=com",
"",
"dn: cn=phone Unique Attribute,cn=Plugins,cn=config",
"objectClass: top",
"objectClass: ds-cfg-plugin",
"objectClass: ds-cfg-unique-attribute-plugin",
"cn: phone Unique Attribute",
"ds-cfg-java-class: org.opends.server.plugins.UniqueAttributePlugin",
"ds-cfg-enabled: true",
"ds-cfg-plugin-type: preOperationAdd",
"ds-cfg-plugin-type: preOperationModify",
"ds-cfg-plugin-type: preOperationModifyDN",
"ds-cfg-type: telephone",
"ds-cfg-type: mobile",
"ds-cfg-type: fax",
"ds-cfg-base-dn: dc=example,dc=com",
"ds-cfg-base-dn: badDN",
"",
"dn: cn=phone Unique Attribute,cn=Plugins,cn=config",
"objectClass: top",
"objectClass: ds-cfg-plugin",
"objectClass: ds-cfg-unique-attribute-plugin",
"cn: phone Unique Attribute",
"ds-cfg-java-class: org.opends.server.plugins.UniqueAttributePlugin",
"ds-cfg-enabled: true",
"ds-cfg-plugin-type: preOperationAdd",
"ds-cfg-plugin-type: preOperationModify",
"ds-cfg-plugin-type: preOperationModifyDN",
"ds-cfg-type: telephone",
"ds-cfg-type: mobile",
"ds-cfg-type: badattribute",
"ds-cfg-base-dn: dc=example,dc=com" );
{
}
return array;
}
/**
* Tests the process of initializing the server with invalid configurations.
*
* @param e The configuration entry to use for the initialization.
*
* @throws Exception If an unexpected problem occurs.
*/
expectedExceptions = { ConfigException.class })
public void testInitializeWithInvalidConfigs(Entry e)
throws Exception
{
}
/**
* Test modify DN operation with various scenerios. See method comments.
*
* @throws Exception If an unexpected result occurs.
*/
@Test
public void testModDNOperation() throws Exception {
//Add an entry under the new superior DN that has a value for uid
//that will be tested for.
//Setup uid attribute to be unique. Test using public naming contexts
//for base DNs.
//Rename with new rdn, should fail, there is an entry already with that
//uid value.
//Rename with multi-valued RDN, should fail there is an entry already with
//that uid value.
//Now add a base dn to be unique under, so new superior move can be tested.
//Try to move the entry to a new superior.
//Should fail, there is an entry under the new superior already with
//that uid value.
//Test again with different superior, should succeed, new superior DN is
//not in base DN scope.
}
/**
* Test various modification scenarios using a configuration with no base
* DNs defined. Use default of public naming contexts for base DNs.
*
* @throws Exception If an unexpected result occurs.
*/
@Test
public void testModOperationNameContexts() throws Exception {
//Fail because user1t@test already exists under "o=people,o=test".
"user1t@test");
//Fail because user1t@test already exists under "o=people,o=test".
//Ok because adding mail value user1t@test to entry that already
//contains mail value user1t@test.
//Replace employeenumber as the unique attribute.
//Test modify increment extension.
//Fail because incremented value of employeenumber (2) already exists.
}
/**
* Test setting the plugins up to get DSEE behavior. Basically two or more
* base DNs can have the same value, but not within the trees. This uses two
* plugins to accomplish this.
*
* @throws Exception If an unexpected result occurs.
*/
@Test
public void testDseeCompatAdd() throws Exception {
//Set up one plugin with mail attribute and a suffix.
//Set up another plugin with the mail attribute and a different suffix.
//Add two entries with same mail attribute value into the different
//base DNs.
//Now try to add two more entries with the same mail attribute value.
}
/**
* Test various add operation scenerios using defined base DNs.
* See comments in method.
*
* @throws Exception If an unexpected result occurs.
*/
@Test
public void testAddOperation() throws Exception {
"ou=People, o=test");
//Fail because mail attribute already exists under "ou=people,o=test".
delAttribute(e, "mail");
//Replace mobile, pager, telephonenumber to config.
"pager","telephonenumber");
//Fail because "2-333-9012" already exists in "ou=people,o=test" in
//telephonenumber attribute.
delAttribute(e, "mobile");
//Fail because "2-111-9012" already exists in "ou=people1,o=test" in
//mobile attribute.
//Test two plugin configuration. Add mail attribute to second plugin
//instance, leave the first instance as it is.
//Add suffix to second plugin.
delAttribute(e, "pager");
//Add some values that will pass the first plugin.
//Add a value that will fail the second plugin.
//Should pass frirail through second plugin configuration.
}
/**
* Test attempting to add entries using a configuration with no base
* DNs defined. Use default of public naming contexts for base DNs.
*
* @throws Exception If an unexpected result occurs.
*/
@Test
public void testAddOperationNameContext() throws Exception {
//Fail because mail value "user77x@test" is a value under the
//"dc=example,dc=com" naming context.
delAttribute(e, "mail");
"pager","telephonenumber");
//Fail because "2-777-9012" is a telephone value under the
//"dc=example,dc=com" naming context.
delAttribute(e, "mobile");
//Fail because "2-777-9012" is a telephone value under the
//"dc=example,dc=com" naming context.
}
/**
* Create entries under the specified suffix and add them to the server.
* The character argument is used to make the mail attribute unique.
*
* @param suffix The suffix to use in building the entries.
* @param c Character used to make the mail attribute unique.
* @throws Exception If a problem occurs.
*/
"dn: ou=People," + suffix,
"objectClass: top",
"objectClass: organizationalUnit",
"ou: People",
"aci: (targetattr= \"*\")" +
"(version 3.0; acl \"allow all\";" +
"allow(all) userdn=\"ldap:///anyone\";)",
"",
"dn: ou=People1," + suffix,
"objectClass: top",
"objectClass: organizationalUnit",
"ou: People1",
"aci: (targetattr= \"*\")" +
"(version 3.0; acl \"allow all\";" +
"allow(all) userdn=\"ldap:///anyone\";)",
"",
"dn: ou=New People1," + suffix,
"objectClass: top",
"objectClass: organizationalUnit",
"ou: New People",
"",
"",
"dn: ou=New People," + suffix,
"objectClass: top",
"objectClass: organizationalUnit",
"ou: New People",
"",
"dn: uid=1user.1,ou=People," + suffix,
"objectClass: top",
"objectClass: person",
"objectClass: organizationalPerson",
"objectClass: inetOrgPerson",
"uid: 1",
"givenName: 1User",
"sn: 1",
"cn: 1User 1",
"userPassword: password",
"mail: user1" + c +"@test",
"employeeNumber: 1",
"mobile: 1-111-1234",
"pager: 1-111-5678",
"telephoneNumber: 1-111-9012",
"",
"dn: uid=2user.2,ou=People," + suffix,
"objectClass: top",
"objectClass: person",
"objectClass: organizationalPerson",
"objectClass: inetOrgPerson",
"uid: 2",
"givenName: 2User",
"sn: 2",
"cn: User 2",
"mail: user2" + c + "@test",
"userPassword: password",
"employeeNumber: 2",
"mobile: 1-222-1234",
"pager: 1-222-5678",
"telephoneNumber: 1-222-9012",
"",
"dn: uid=3user.3,ou=People," + suffix,
"objectClass: top",
"objectClass: person",
"objectClass: organizationalPerson",
"objectClass: inetOrgPerson",
"uid: 3",
"givenName: 3User",
"sn: 3",
"cn: User 3",
"mail: user3" + c + "@test",
"userPassword: password",
"employeeNumber: 3",
"mobile: 1-333-1234",
"pager: 1-333-5678",
"telephoneNumber: 1-333-9012",
"",
"dn: uid=4user.4,ou=People," + suffix,
"objectClass: top",
"objectClass: person",
"objectClass: organizationalPerson",
"objectClass: inetOrgPerson",
"uid: 4",
"givenName: 4User",
"sn: 4",
"cn: User 4",
"mail: user4" + c + "@test",
"userPassword: password",
"employeeNumber: 4",
"mobile: 1-444-1234",
"pager: 1-444-5678",
"telephoneNumber: 1-444-9012",
"",
"dn: uid=5user.5,ou=People," + suffix,
"objectClass: top",
"objectClass: person",
"objectClass: organizationalPerson",
"objectClass: inetOrgPerson",
"uid: 5",
"givenName: 5User",
"sn: 5",
"cn: User 5",
"mail: user5" + c + "@test",
"userPassword: password",
"employeeNumber: 5",
"mobile: 1-555-1234",
"pager: 1-555-5678",
"telephoneNumber: 1-555-9012",
"",
"dn: uid=1user.1,ou=People1," + suffix,
"objectClass: top",
"objectClass: person",
"objectClass: organizationalPerson",
"objectClass: inetOrgPerson",
"uid: 1",
"givenName: 1User",
"sn: 11",
"cn: 1User 11",
"userPassword: password",
"mail: user11" + c + "@test",
"employeeNumber: 111",
"mobile: 2-111-1234",
"pager: 2-111-5678",
"telephoneNumber: 2-111-9012",
"",
"dn: uid=2user.22,ou=People1," + suffix,
"objectClass: top",
"objectClass: person",
"objectClass: organizationalPerson",
"objectClass: inetOrgPerson",
"uid: 2",
"givenName: 2User",
"sn: 22",
"cn: User 22",
"mail: user22" + c + "@test",
"userPassword: password",
"employeeNumber: 222",
"mobile: 2-222-1234",
"pager: 2-222-5678",
"telephoneNumber: 2-222-9012",
"",
"dn: uid=3user.33,ou=People1," + suffix,
"objectClass: top",
"objectClass: person",
"objectClass: organizationalPerson",
"objectClass: inetOrgPerson",
"uid: 33",
"givenName: 3User",
"sn: 3",
"cn: User 33",
"mail: user33" + c + "@test",
"userPassword: password",
"employeeNumber: 333",
"mobile: 2-333-1234",
"pager: 2-333-5678",
"telephoneNumber: 2-333-9012"
);
//Add an additional entry if the suffix is "dc=example,dc=com".
"dn: uid=2user.77,ou=People," + suffix,
"objectClass: top",
"objectClass: person",
"objectClass: organizationalPerson",
"objectClass: inetOrgPerson",
"uid: 2",
"givenName: 2User",
"sn: 22",
"cn: User 22",
"mail: user77" + c + "@test",
"userPassword: password",
"employeeNumber: 777",
"mobile: 2-777-1234",
"pager: 2-777-5678",
"telephoneNumber: 2-777-9012"
);
}
}
{
}
/**
* Remove the attributes specified by the attribute type strings from the
* entry corresponding to the dn argument.
*
* @param dn The entry to remove the attributes from.
* @param attrTypeStrings The attribute type string list to remove from the
* entry.
* @throws Exception If an error occurs.
*/
private void
}
}
}
/**
* Try to add an entry to the server checking for the expected return
* code.
*
* @param e The entry to add.
* @param rc The expected return code.
* @throws Exception If an error occurs.
*/
}
/**
* Make a entry with the specified dn.
*
* @param dn The dn of the entry.
* @return The created entry.
* @throws Exception If the entry can't be created.
*/
return TestCaseUtils.makeEntry(
"dn: " + dn,
"objectClass: top",
"objectClass: person",
"objectClass: organizationalPerson",
"objectClass: inetOrgPerson",
"uid: 1",
"givenName: 1User",
"sn: 1",
"cn: 1User 1"
);
}
/**
* Remove an attribute from the specified entry.
*
* @param entry The entry to remove the attribute from.
* @param attrTypeString The attribute type string to remove.
*/
}
/**
* Add an attribute to an entry with specified values.
*
* @param entry The entry to add the attribute to.
* @param attrName The attribute type string name.
* @param attrValues The values use in building the attribute.
*/
}
/**
* Add a new modification for attribute type string and values of modification
* type to a list of modifications.
*
* @param mods The modification list to add to.
* @param attrName The attribute type string name.
* @param modificationType The modification type.
* @param attrValues The values to build the modification from.
*/
private void
}
}
/**
* Perform modify operation with list of modifications. Expect return code
* of value rc.
*
* @param mods The modification list to use.
* @param dn The DN of the entry to modify.
* @param rc The expected return code.
*/
}
/**
* Perform modify DN operation. Expect return value of rc.
*
* @param dn The DN to rename or move.
* @param rdn RDN value.
* @param delOld Delete old flag.
* @param newSuperior New superior to move to.
* @param rc Expected return code from operation.
*/
ModifyDNOperation modifyDNOperation = getRootConnection().processModifyDN(dn, rdn, delOld, newSuperior);
}
}