2165N/A/*
2165N/A * CDDL HEADER START
2165N/A *
2165N/A * The contents of this file are subject to the terms of the
2165N/A * Common Development and Distribution License, Version 1.0 only
2165N/A * (the "License"). You may not use this file except in compliance
2165N/A * with the License.
2165N/A *
6982N/A * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
6982N/A * or http://forgerock.org/license/CDDLv1.0.html.
2165N/A * See the License for the specific language governing permissions
2165N/A * and limitations under the License.
2165N/A *
2165N/A * When distributing Covered Code, include this CDDL HEADER in each
6982N/A * file and include the License file at legal-notices/CDDLv1_0.txt.
6982N/A * If applicable, add the following below this CDDL HEADER, with the
6982N/A * fields enclosed by brackets "[]" replaced with your own identifying
6982N/A * information:
2165N/A * Portions Copyright [yyyy] [name of copyright owner]
2165N/A *
2165N/A * CDDL HEADER END
2165N/A *
2165N/A *
3232N/A * Copyright 2008 Sun Microsystems, Inc.
6907N/A * Portions Copyright 2011-2013 ForgeRock AS
2165N/A */
2165N/A
2165N/A
2165N/Apackage org.opends.server.plugins;
2165N/A
2165N/Aimport org.testng.annotations.*;
2165N/Aimport static org.testng.Assert.assertEquals;
2165N/Aimport org.opends.server.types.*;
2165N/Aimport org.opends.server.TestCaseUtils;
2165N/Aimport org.opends.server.core.ModifyOperation;
2165N/Aimport org.opends.server.core.DirectoryServer;
2165N/Aimport org.opends.server.core.AddOperation;
2165N/Aimport org.opends.server.core.ModifyDNOperation;
2165N/Aimport org.opends.server.protocols.internal.InternalClientConnection;
2165N/Aimport org.opends.server.config.ConfigException;
2165N/Aimport org.opends.server.admin.std.server.UniqueAttributePluginCfg;
2165N/Aimport org.opends.server.admin.std.meta.UniqueAttributePluginCfgDefn;
2165N/Aimport org.opends.server.admin.server.AdminTestCaseUtils;
2165N/Aimport org.opends.server.api.plugin.PluginType;
2165N/A
2165N/Aimport java.util.List;
2165N/Aimport java.util.HashSet;
2165N/Aimport java.util.LinkedList;
2165N/A
2165N/A
2165N/A/**
2165N/A * Unit test to test the unique attribute plugin.
2165N/A */
2165N/A
2165N/Apublic class UniqueAttributePluginTestCase extends PluginTestCase {
2165N/A
2165N/A private DN uidConfigDN;
2165N/A private DN testConfigDN;
2624N/A private String dsConfigAttrType="ds-cfg-type";
2624N/A private String dsConfigBaseDN="ds-cfg-base-dn";
2165N/A
2165N/A /**
2165N/A * Ensures that the Directory Server is running.
2165N/A *
2165N/A * @throws Exception If an unexpected problem occurs.
2165N/A */
2165N/A @BeforeClass()
2165N/A public void startServer()
2165N/A throws Exception
2165N/A {
2342N/A TestCaseUtils.restartServer();
2342N/A TestCaseUtils.initializeTestBackend(true);
4134N/A
2165N/A //Add entries to two backends to test public naming context.
2165N/A addTestEntries("o=test", 't');
2165N/A TestCaseUtils.clearJEBackend(true,"userRoot", "dc=example,dc=com");
2165N/A addTestEntries("dc=example,dc=com", 'x');
2165N/A uidConfigDN=DN.decode("cn=UID Unique Attribute ,cn=Plugins,cn=config");
2165N/A testConfigDN=DN.decode("cn=Test Unique Attribute,cn=Plugins,cn=config");
2165N/A }
2165N/A
2165N/A
2165N/A /**
2165N/A * Clears configuration information before each method run.
2165N/A *
2165N/A * @throws Exception If an unexpected problem occurs.
2165N/A */
2165N/A @BeforeMethod
2165N/A public void clearConfigEntries() throws Exception {
2250N/A deleteAttrsFromEntry(uidConfigDN, dsConfigBaseDN);
2250N/A deleteAttrsFromEntry(testConfigDN, dsConfigBaseDN);
2250N/A //Put an attribute type there that won't impact the rest of the unit
2250N/A //tests.
2250N/A replaceAttrInEntry(uidConfigDN, dsConfigAttrType,"oncRpcNumber");
2250N/A replaceAttrInEntry(testConfigDN, dsConfigAttrType,"bootParameter");
2165N/A }
2165N/A
2165N/A
2165N/A /**
2165N/A * Clears things up after the unit test is completed.
2165N/A *
2165N/A * @throws Exception If an unexpected problem occurs.
2165N/A */
2165N/A @AfterClass
2165N/A public void tearDown() throws Exception {
2165N/A clearConfigEntries();
2165N/A TestCaseUtils.clearJEBackend(false,"userRoot", "dc=example,dc=com");
6906N/A clearAcis("o=test");
6906N/A TestCaseUtils.clearMemoryBackend(TestCaseUtils.TEST_BACKEND_ID);
2165N/A }
2165N/A
2165N/A
2165N/A /**
2165N/A * Retrieves a set of valid configuration entries that may be used to
2165N/A * initialize the plugin.
2165N/A *
2165N/A * @return An array of config entries.
2165N/A *
2165N/A * @throws Exception If an unexpected problem occurs.
2165N/A */
2165N/A @DataProvider(name = "validConfigs")
2165N/A public Object[][] getValidConfigs()
2165N/A throws Exception
2165N/A {
2165N/A List<Entry> entries = TestCaseUtils.makeEntries(
2165N/A "dn: cn=UID Unique Attribute,cn=Plugins,cn=config",
2165N/A "objectClass: top",
2165N/A "objectClass: ds-cfg-plugin",
2165N/A "objectClass: ds-cfg-unique-attribute-plugin",
2165N/A "cn: UID Unique Attribute",
2624N/A "ds-cfg-java-class: org.opends.server.plugins.UniqueAttributePlugin",
2624N/A "ds-cfg-enabled: true",
2165N/A "ds-cfg-plugin-type: preOperationAdd",
2165N/A "ds-cfg-plugin-type: preOperationModify",
2165N/A "ds-cfg-plugin-type: preOperationModifyDN",
2624N/A "ds-cfg-type: uid",
2165N/A "",
2165N/A "dn: cn=mail Unique Attribute,cn=Plugins,cn=config",
2165N/A "objectClass: top",
2165N/A "objectClass: ds-cfg-plugin",
2165N/A "objectClass: ds-cfg-unique-attribute-plugin",
2165N/A "cn: mail Unique Attribute",
2624N/A "ds-cfg-java-class: org.opends.server.plugins.UniqueAttributePlugin",
2624N/A "ds-cfg-enabled: true",
2165N/A "ds-cfg-plugin-type: preOperationAdd",
2165N/A "ds-cfg-plugin-type: preOperationModify",
2165N/A "ds-cfg-plugin-type: preOperationModifyDN",
2624N/A "ds-cfg-type: mail",
2624N/A "ds-cfg-type: sn",
2165N/A "",
2165N/A "dn: cn=phone Unique Attribute,cn=Plugins,cn=config",
2165N/A "objectClass: top",
2165N/A "objectClass: ds-cfg-plugin",
2165N/A "objectClass: ds-cfg-unique-attribute-plugin",
2165N/A "cn: phone Unique Attribute",
2624N/A "ds-cfg-java-class: org.opends.server.plugins.UniqueAttributePlugin",
2624N/A "ds-cfg-enabled: true",
2165N/A "ds-cfg-plugin-type: preOperationAdd",
2165N/A "ds-cfg-plugin-type: preOperationModify",
2165N/A "ds-cfg-plugin-type: preOperationModifyDN",
2624N/A "ds-cfg-type: telephoneNumber",
2624N/A "ds-cfg-type: mobile",
2624N/A "ds-cfg-type: facsimileTelephoneNumber",
2624N/A "ds-cfg-base-dn: dc=example,dc=com",
2624N/A "ds-cfg-base-dn: o=test",
2165N/A "",
2250N/A "dn: cn=UID0 Unique Attribute,cn=Plugins,cn=config",
2165N/A "objectClass: top",
2165N/A "objectClass: ds-cfg-plugin",
2165N/A "objectClass: ds-cfg-unique-attribute-plugin",
2250N/A "cn: UUID0 Unique Attribute",
2624N/A "ds-cfg-java-class: org.opends.server.plugins.UniqueAttributePlugin",
2624N/A "ds-cfg-enabled: true",
2165N/A "ds-cfg-plugin-type: preOperationAdd",
2624N/A "ds-cfg-type: uid",
2165N/A "",
2250N/A "dn: cn=UID1 Unique Attribute,cn=Plugins,cn=config",
2165N/A "objectClass: top",
2165N/A "objectClass: ds-cfg-plugin",
2165N/A "objectClass: ds-cfg-unique-attribute-plugin",
2250N/A "cn: UUID1 Unique Attribute",
2624N/A "ds-cfg-java-class: org.opends.server.plugins.UniqueAttributePlugin",
2624N/A "ds-cfg-enabled: true",
2165N/A "ds-cfg-plugin-type: preOperationModify",
2624N/A "ds-cfg-type: uid",
2165N/A "",
2250N/A "dn: cn=UID2 Unique Attribute,cn=Plugins,cn=config",
2165N/A "objectClass: top",
2165N/A "objectClass: ds-cfg-plugin",
2165N/A "objectClass: ds-cfg-unique-attribute-plugin",
2250N/A "cn: UUID2 Unique Attribute",
2624N/A "ds-cfg-java-class: org.opends.server.plugins.UniqueAttributePlugin",
2624N/A "ds-cfg-enabled: true",
2250N/A "ds-cfg-plugin-type: preOperationModifyDN",
2624N/A "ds-cfg-type: uid");
2165N/A Object[][] array = new Object[entries.size()][1];
2165N/A for (int i=0; i < array.length; i++)
2165N/A {
2165N/A array[i] = new Object[] { entries.get(i) };
2165N/A }
2165N/A
2165N/A return array;
2165N/A }
2165N/A
2165N/A
2165N/A /**
2165N/A * Tests the process of initializing the server with valid configurations.
2165N/A *
2165N/A * @param e The configuration entry to use for the initialization.
2165N/A *
2165N/A * @throws Exception If an unexpected problem occurs.
2165N/A */
2165N/A @Test(dataProvider = "validConfigs")
2165N/A public void testInitializeWithValidConfigs(Entry e)
2165N/A throws Exception
2165N/A {
2165N/A HashSet<PluginType> pluginTypes = new HashSet<PluginType>();
2165N/A List<Attribute> attrList = e.getAttribute("ds-cfg-plugin-type");
2165N/A for (Attribute a : attrList){
3853N/A for (AttributeValue v : a)
4134N/A pluginTypes.add(PluginType.forName(
4134N/A v.getValue().toString().toLowerCase()));
2165N/A }
2165N/A UniqueAttributePluginCfg configuration =
2165N/A AdminTestCaseUtils.getConfiguration(
2165N/A UniqueAttributePluginCfgDefn.getInstance(), e);
2165N/A
2165N/A UniqueAttributePlugin plugin = new UniqueAttributePlugin();
2165N/A plugin.initializePlugin(pluginTypes, configuration);
2165N/A plugin.finalizePlugin();
2165N/A }
2165N/A
2165N/A /**
2165N/A * Retrieves a set of valid configuration entries that may be used to
2165N/A * initialize the plugin.
2165N/A
2165N/A * @return An array of config entries.
2165N/A *
2165N/A * @throws Exception If an unexpected problem occurs.
2165N/A */
2165N/A @DataProvider(name = "invalidConfigs")
2165N/A public Object[][] getInValidConfigs()
2165N/A throws Exception
2165N/A {
2165N/A List<Entry> entries = TestCaseUtils.makeEntries(
2165N/A "dn: cn=UID Unique Attribute,cn=Plugins,cn=config",
2165N/A "objectClass: top",
2165N/A "objectClass: ds-cfg-plugin",
2165N/A "objectClass: ds-cfg-unique-attribute-plugin",
2165N/A "cn: UID Unique Attribute",
2624N/A "ds-cfg-java-class: org.opends.server.plugins.UniqueAttributePlugin",
2624N/A "ds-cfg-enabled: true",
2165N/A "ds-cfg-plugin-type: preOperationAdd",
2165N/A "ds-cfg-plugin-type: preOperationModify",
2250N/A "ds-cfg-plugin-type: preOperationModifyDN",
2250N/A "",
2250N/A "dn: cn=UID Unique Attribute,cn=Plugins,cn=config",
2250N/A "objectClass: top",
2250N/A "objectClass: ds-cfg-plugin",
2250N/A "objectClass: ds-cfg-unique-attribute-plugin",
2250N/A "cn: UID Unique Attribute",
2624N/A "ds-cfg-java-class: org.opends.server.plugins.UniqueAttributePlugin",
2624N/A "ds-cfg-enabled: true",
2250N/A "ds-cfg-plugin-type: preOperationAdd",
2250N/A "ds-cfg-plugin-type: preOperationModify",
2165N/A "ds-cfg-plugin-type: ldifImport",
2165N/A "",
2165N/A "dn: cn=phone Unique Attribute,cn=Plugins,cn=config",
2165N/A "objectClass: top",
2165N/A "objectClass: ds-cfg-plugin",
2165N/A "cn: phone Unique Attribute",
2624N/A "ds-cfg-java-class: org.opends.server.plugins.UniqueAttributePlugin",
2624N/A "ds-cfg-enabled: true",
2165N/A "ds-cfg-plugin-type: preOperationAdd",
2165N/A "ds-cfg-plugin-type: preOperationModify",
2165N/A "ds-cfg-plugin-type: preOperationModifyDN",
2624N/A "ds-cfg-type: telephone",
2624N/A "ds-cfg-type: mobile",
2624N/A "ds-cfg-type: fax",
2624N/A "ds-cfg-base-dn: dc=example,dc=com",
2165N/A "",
2165N/A "dn: cn=phone Unique Attribute,cn=Plugins,cn=config",
2165N/A "objectClass: top",
2165N/A "objectClass: ds-cfg-plugin",
2165N/A "objectClass: ds-cfg-unique-attribute-plugin",
2165N/A "cn: phone Unique Attribute",
2624N/A "ds-cfg-java-class: org.opends.server.plugins.UniqueAttributePlugin",
2624N/A "ds-cfg-enabled: true",
2165N/A "ds-cfg-plugin-type: preOperationAdd",
2165N/A "ds-cfg-plugin-type: preOperationModify",
2165N/A "ds-cfg-plugin-type: preOperationModifyDN",
2624N/A "ds-cfg-type: telephone",
2624N/A "ds-cfg-type: mobile",
2624N/A "ds-cfg-type: fax",
2624N/A "ds-cfg-base-dn: dc=example,dc=com",
2624N/A "ds-cfg-base-dn: badDN",
2250N/A "",
2250N/A "dn: cn=phone Unique Attribute,cn=Plugins,cn=config",
2250N/A "objectClass: top",
2250N/A "objectClass: ds-cfg-plugin",
2250N/A "objectClass: ds-cfg-unique-attribute-plugin",
2250N/A "cn: phone Unique Attribute",
2624N/A "ds-cfg-java-class: org.opends.server.plugins.UniqueAttributePlugin",
2624N/A "ds-cfg-enabled: true",
2250N/A "ds-cfg-plugin-type: preOperationAdd",
2250N/A "ds-cfg-plugin-type: preOperationModify",
2250N/A "ds-cfg-plugin-type: preOperationModifyDN",
2624N/A "ds-cfg-type: telephone",
2624N/A "ds-cfg-type: mobile",
2624N/A "ds-cfg-type: badattribute",
2624N/A "ds-cfg-base-dn: dc=example,dc=com" );
2165N/A
2165N/A Object[][] array = new Object[entries.size()][1];
2165N/A for (int i=0; i < array.length; i++)
2165N/A {
2165N/A array[i] = new Object[] { entries.get(i) };
2165N/A }
2165N/A
2165N/A return array;
2165N/A }
2165N/A
2165N/A
2165N/A /**
2165N/A * Tests the process of initializing the server with invalid configurations.
2165N/A *
2165N/A * @param e The configuration entry to use for the initialization.
2165N/A *
2165N/A * @throws Exception If an unexpected problem occurs.
2165N/A */
2165N/A @Test(dataProvider = "invalidConfigs",
2165N/A expectedExceptions = { ConfigException.class })
2165N/A public void testInitializeWithInvalidConfigs(Entry e)
2165N/A throws Exception
2165N/A {
2165N/A HashSet<PluginType> pluginTypes = new HashSet<PluginType>();
2165N/A List<Attribute> attrList = e.getAttribute("ds-cfg-plugin-type");
2165N/A for (Attribute a : attrList)
2165N/A {
3853N/A for (AttributeValue v : a)
4134N/A pluginTypes.add(PluginType.forName(
4134N/A v.getValue().toString().toLowerCase()));
2165N/A }
2165N/A UniqueAttributePluginCfg configuration =
2165N/A AdminTestCaseUtils.getConfiguration(
2165N/A UniqueAttributePluginCfgDefn.getInstance(), e);
2165N/A UniqueAttributePlugin plugin = new UniqueAttributePlugin();
2165N/A plugin.initializePlugin(pluginTypes, configuration);
2165N/A plugin.finalizePlugin();
2165N/A }
2165N/A
2165N/A /**
2165N/A * Test modify DN operation with various scenerios. See method comments.
2165N/A *
2165N/A * @throws Exception If an unexpected result occurs.
2165N/A */
2165N/A @Test()
2165N/A public void testModDNOperation() throws Exception {
2165N/A //Add an entry under the new superior DN that has a value for uid
2165N/A //that will be tested for.
2165N/A Entry e = makeEntry("cn=test user, ou=new people,o=test");
2165N/A addAttribute(e, "uid", "3user.3");
2165N/A addEntry(e, ResultCode.SUCCESS);
2165N/A //Setup uid attribute to be unique. Test using public naming contexts
2165N/A //for base DNs.
2250N/A replaceAttrInEntry(uidConfigDN,dsConfigAttrType,"uid");
2165N/A //Rename with new rdn, should fail, there is an entry already with that
2165N/A //uid value.
2165N/A doModDN(DN.decode("uid=3user.3, ou=people, o=test"), RDN.decode("uid=4"),
2165N/A false, null, ResultCode.CONSTRAINT_VIOLATION);
2165N/A //Rename with multi-valued RDN, should fail there is an entry already with
2165N/A //that uid value.
2165N/A doModDN(DN.decode("uid=3user.3, ou=people, o=test"),
2165N/A RDN.decode("sn=xx+uid=4"),
2165N/A false, null, ResultCode.CONSTRAINT_VIOLATION);
2165N/A //Now add a base dn to be unique under, so new superior move can be tested.
2250N/A replaceAttrInEntry(uidConfigDN,dsConfigBaseDN,"ou=new people,o=test");
2165N/A
2165N/A
2165N/A //Try to move the entry to a new superior.
2165N/A //Should fail, there is an entry under the new superior already with
2165N/A //that uid value.
2165N/A doModDN(DN.decode("uid=3user.3, ou=people, o=test"),
2165N/A RDN.decode("uid=3user.3"), false,
2165N/A DN.decode("ou=new people, o=test"),
2165N/A ResultCode.CONSTRAINT_VIOLATION);
2165N/A //Test again with different superior, should succeed, new superior DN is
2165N/A //not in base DN scope.
2165N/A doModDN(DN.decode("uid=3user.3, ou=people, o=test"),
2165N/A RDN.decode("uid=3user.3"), false,
2165N/A DN.decode("ou=new people1, o=test"),
2165N/A ResultCode.SUCCESS);
2165N/A }
2165N/A
2165N/A /**
5323N/A * Test various modification scenarios using a configuration with no base
2165N/A * DNs defined. Use default of public naming contexts for base DNs.
2165N/A *
2165N/A * @throws Exception If an unexpected result occurs.
2165N/A */
2165N/A @Test()
2165N/A public void testModOperationNameContexts() throws Exception {
2250N/A replaceAttrInEntry(uidConfigDN,dsConfigAttrType,"mail");
2165N/A LinkedList<Modification> mods = new LinkedList<Modification>();
2165N/A addMods(mods,"mail",ModificationType.REPLACE,"userx@test","userxx@test",
2165N/A "user1t@test");
2165N/A //Fail because user1t@test already exists under "o=people,o=test".
2165N/A doMods(mods, DN.decode("uid=5user.5,ou=People,o=test"),
2165N/A ResultCode.CONSTRAINT_VIOLATION);
2165N/A mods.clear();
2165N/A addMods(mods,"pager",ModificationType.ADD,"2-999-1234","1-999-5678");
2165N/A addMods(mods,"mail",ModificationType.ADD,"userx@test","userxx@test",
2165N/A "user1t@test");
2165N/A //Fail because user1t@test already exists under "o=people,o=test".
2165N/A doMods(mods, DN.decode("uid=5user.5,ou=People,o=test"),
2165N/A ResultCode.CONSTRAINT_VIOLATION);
2165N/A mods.clear();
2165N/A addMods(mods,"pager",ModificationType.ADD,"2-999-1234","1-999-5678");
2165N/A addMods(mods,"mail",ModificationType.REPLACE,"userx@test","userxx@test",
2165N/A "user1t@test");
2165N/A //Ok because adding mail value user1t@test to entry that already
2165N/A //contains mail value user1t@test.
2165N/A doMods(mods, DN.decode("uid=1user.1,ou=People,o=test"),
2165N/A ResultCode.SUCCESS);
2165N/A mods.clear();
2250N/A //Replace employeenumber as the unique attribute.
2250N/A replaceAttrInEntry(uidConfigDN,dsConfigAttrType,"employeenumber");
2165N/A addMods(mods,"employeenumber",ModificationType.INCREMENT,"1");
2165N/A //Test modify increment extension.
2165N/A //Fail because incremented value of employeenumber (2) already exists.
2165N/A doMods(mods, DN.decode("uid=1user.1,ou=People,o=test"),
2165N/A ResultCode.CONSTRAINT_VIOLATION);
2165N/A }
2165N/A
2165N/A
2165N/A /**
2165N/A * Test setting the plugins up to get DSEE behavior. Basically two or more
2165N/A * base DNs can have the same value, but not within the trees. This uses two
2165N/A * plugins to accomplish this.
2165N/A *
2165N/A * @throws Exception If an unexpected result occurs.
2165N/A */
2165N/A @Test()
2165N/A public void testDseeCompatAdd() throws Exception {
2165N/A //Set up one plugin with mail attribute and a suffix.
2250N/A replaceAttrInEntry(uidConfigDN,dsConfigAttrType,"mail");
2250N/A replaceAttrInEntry(uidConfigDN,dsConfigBaseDN,"ou=People,o=test");
2165N/A //Set up another plugin with the mail attribute and a different suffix.
2250N/A replaceAttrInEntry(testConfigDN,dsConfigAttrType,"mail");
2250N/A replaceAttrInEntry(testConfigDN,dsConfigBaseDN,"ou=People1,o=test");
2165N/A //Add two entries with same mail attribute value into the different
2165N/A //base DNs.
2165N/A Entry e1 = makeEntry("cn=test user1, ou=People,o=test");
2165N/A addAttribute(e1, "mail", "mailtest@test");
2165N/A addEntry(e1, ResultCode.SUCCESS);
2165N/A Entry e2 = makeEntry("cn=test user2, ou=People1,o=test");
2165N/A addAttribute(e2, "mail", "mailtest@test");
2165N/A addEntry(e2, ResultCode.SUCCESS);
2165N/A //Now try to add two more entries with the same mail attribute value.
2165N/A Entry e3 = makeEntry("cn=test user3, ou=People,o=test");
2165N/A addAttribute(e3, "mail", "mailtest@test");
2165N/A addEntry(e3, ResultCode.CONSTRAINT_VIOLATION);
2165N/A Entry e4 = makeEntry("cn=test user4, ou=People1,o=test");
2165N/A addAttribute(e4, "mail", "mailtest@test");
2165N/A addEntry(e4, ResultCode.CONSTRAINT_VIOLATION);
2165N/A }
2165N/A
2165N/A /**
2165N/A * Test various add operation scenerios using defined base DNs.
2165N/A * See comments in method.
2165N/A *
2165N/A * @throws Exception If an unexpected result occurs.
2165N/A */
2165N/A @Test()
2165N/A public void testAddOperation() throws Exception {
2250N/A replaceAttrInEntry(uidConfigDN,dsConfigAttrType,"mail");
2250N/A replaceAttrInEntry(uidConfigDN,dsConfigBaseDN,"ou=People1,o=test",
2250N/A "ou=People, o=test");
2165N/A Entry e = makeEntry("cn=test user, ou=People,o=test");
2165N/A addAttribute(e, "mail", "user1t@test");
2165N/A //Fail because mail attribute already exists under "ou=people,o=test".
2165N/A addEntry(e, ResultCode.CONSTRAINT_VIOLATION);
2165N/A delAttribute(e, "mail");
2250N/A //Replace mobile, pager, telephonenumber to config.
2250N/A replaceAttrInEntry(uidConfigDN,dsConfigAttrType,"mobile",
2250N/A "pager","telephonenumber");
2165N/A addAttribute(e, "mobile", "1-999-1234","1-999-5678","1-444-9012");
2165N/A addEntry(e, ResultCode.CONSTRAINT_VIOLATION);
2165N/A e.setDN(DN.decode("cn=test user, ou=People,o=test"));
2165N/A //Fail because "2-333-9012" already exists in "ou=people,o=test" in
2165N/A //telephonenumber attribute.
2165N/A addEntry(e, ResultCode.CONSTRAINT_VIOLATION);
2165N/A delAttribute(e, "mobile");
2165N/A addAttribute(e, "pager", "2-111-1234","1-999-5678","1-999-9012");
2165N/A //Fail because "2-111-9012" already exists in "ou=people1,o=test" in
2165N/A //mobile attribute.
2165N/A addEntry(e, ResultCode.CONSTRAINT_VIOLATION);
2165N/A //Test two plugin configuration. Add mail attribute to second plugin
2165N/A //instance, leave the first instance as it is.
2250N/A replaceAttrInEntry(testConfigDN,dsConfigAttrType,"mail");
2165N/A //Add suffix to second plugin.
2250N/A replaceAttrInEntry(testConfigDN,dsConfigBaseDN,"ou=People,o=test");
2165N/A delAttribute(e, "pager");
2165N/A //Add some values that will pass the first plugin.
2165N/A addAttribute(e, "telephonenumber", "2-999-1234","1-999-5678","1-999-9012");
2165N/A //Add a value that will fail the second plugin.
2165N/A addAttribute(e, "mail", "user1t@test");
2165N/A //Should pass frirail through second plugin configuration.
2165N/A addEntry(e, ResultCode.CONSTRAINT_VIOLATION);
2165N/A }
2165N/A
2165N/A
2165N/A /**
2165N/A * Test attempting to add entries using a configuration with no base
2165N/A * DNs defined. Use default of public naming contexts for base DNs.
2165N/A *
2165N/A * @throws Exception If an unexpected result occurs.
2165N/A */
2165N/A @Test()
2165N/A public void testAddOperationNameContext() throws Exception {
2250N/A replaceAttrInEntry(uidConfigDN,dsConfigAttrType,"mail");
2165N/A Entry e = makeEntry("cn=test user, ou=People,o=test");
2165N/A addAttribute(e, "mail", "user77x@test");
2165N/A //Fail because mail value "user77x@test" is a value under the
2165N/A //"dc=example,dc=com" naming context.
2165N/A addEntry(e, ResultCode.CONSTRAINT_VIOLATION);
2165N/A delAttribute(e, "mail");
2250N/A replaceAttrInEntry(uidConfigDN,dsConfigAttrType,"mobile",
2165N/A "pager","telephonenumber");
2165N/A addAttribute(e, "mobile", "1-999-1234","1-999-5678","2-777-9012");
2165N/A //Fail because "2-777-9012" is a telephone value under the
2165N/A //"dc=example,dc=com" naming context.
2165N/A addEntry(e, ResultCode.CONSTRAINT_VIOLATION);
2165N/A e.setDN(DN.decode("cn=test user, ou=People,o=test"));
2165N/A addEntry(e, ResultCode.CONSTRAINT_VIOLATION);
2165N/A delAttribute(e, "mobile");
2165N/A addAttribute(e, "pager", "2-777-1234","1-999-5678","1-999-9012");
2165N/A //Fail because "2-777-9012" is a telephone value under the
2165N/A //"dc=example,dc=com" naming context.
2165N/A addEntry(e, ResultCode.CONSTRAINT_VIOLATION);
2165N/A }
2165N/A
2165N/A
2165N/A /**
2165N/A * Create entries under the specified suffix and add them to the server.
2165N/A * The character argument is used to make the mail attribute unique.
2165N/A *
2165N/A * @param suffix The suffix to use in building the entries.
2165N/A * @param c Character used to make the mail attribute unique.
2165N/A * @throws Exception If a problem occurs.
2165N/A */
2165N/A private void addTestEntries(String suffix, char c) throws Exception {
2165N/A TestCaseUtils.addEntries(
2165N/A "dn: ou=People," + suffix,
2165N/A "objectClass: top",
2165N/A "objectClass: organizationalUnit",
2165N/A "ou: People",
2165N/A "aci: (targetattr= \"*\")" +
2165N/A "(version 3.0; acl \"allow all\";" +
2165N/A "allow(all) userdn=\"ldap:///anyone\";)",
2165N/A "",
2165N/A "dn: ou=People1," + suffix,
2165N/A "objectClass: top",
2165N/A "objectClass: organizationalUnit",
2165N/A "ou: People1",
2165N/A "aci: (targetattr= \"*\")" +
2165N/A "(version 3.0; acl \"allow all\";" +
2165N/A "allow(all) userdn=\"ldap:///anyone\";)",
2165N/A "",
2165N/A "dn: ou=New People1," + suffix,
2165N/A "objectClass: top",
2165N/A "objectClass: organizationalUnit",
2165N/A "ou: New People",
2165N/A "",
2165N/A "",
2165N/A "dn: ou=New People," + suffix,
2165N/A "objectClass: top",
2165N/A "objectClass: organizationalUnit",
2165N/A "ou: New People",
2165N/A "",
2165N/A "dn: uid=1user.1,ou=People," + suffix,
2165N/A "objectClass: top",
2165N/A "objectClass: person",
2165N/A "objectClass: organizationalPerson",
2165N/A "objectClass: inetOrgPerson",
2165N/A "uid: 1",
2165N/A "givenName: 1User",
2165N/A "sn: 1",
2165N/A "cn: 1User 1",
2165N/A "userPassword: password",
2165N/A "mail: user1" + c +"@test",
2165N/A "employeeNumber: 1",
2165N/A "mobile: 1-111-1234",
2165N/A "pager: 1-111-5678",
2165N/A "telephoneNumber: 1-111-9012",
2165N/A "",
2165N/A "dn: uid=2user.2,ou=People," + suffix,
2165N/A "objectClass: top",
2165N/A "objectClass: person",
2165N/A "objectClass: organizationalPerson",
2165N/A "objectClass: inetOrgPerson",
2165N/A "uid: 2",
2165N/A "givenName: 2User",
2165N/A "sn: 2",
2165N/A "cn: User 2",
2165N/A "mail: user2" + c + "@test",
2165N/A "userPassword: password",
2165N/A "employeeNumber: 2",
2165N/A "mobile: 1-222-1234",
2165N/A "pager: 1-222-5678",
2165N/A "telephoneNumber: 1-222-9012",
2165N/A "",
2165N/A "dn: uid=3user.3,ou=People," + suffix,
2165N/A "objectClass: top",
2165N/A "objectClass: person",
2165N/A "objectClass: organizationalPerson",
2165N/A "objectClass: inetOrgPerson",
2165N/A "uid: 3",
2165N/A "givenName: 3User",
2165N/A "sn: 3",
2165N/A "cn: User 3",
2165N/A "mail: user3" + c + "@test",
2165N/A "userPassword: password",
2165N/A "employeeNumber: 3",
2165N/A "mobile: 1-333-1234",
2165N/A "pager: 1-333-5678",
2165N/A "telephoneNumber: 1-333-9012",
2165N/A "",
2165N/A "dn: uid=4user.4,ou=People," + suffix,
2165N/A "objectClass: top",
2165N/A "objectClass: person",
2165N/A "objectClass: organizationalPerson",
2165N/A "objectClass: inetOrgPerson",
2165N/A "uid: 4",
2165N/A "givenName: 4User",
2165N/A "sn: 4",
2165N/A "cn: User 4",
2165N/A "mail: user4" + c + "@test",
2165N/A "userPassword: password",
2165N/A "employeeNumber: 4",
2165N/A "mobile: 1-444-1234",
2165N/A "pager: 1-444-5678",
2165N/A "telephoneNumber: 1-444-9012",
2165N/A "",
2165N/A "dn: uid=5user.5,ou=People," + suffix,
2165N/A "objectClass: top",
2165N/A "objectClass: person",
2165N/A "objectClass: organizationalPerson",
2165N/A "objectClass: inetOrgPerson",
2165N/A "uid: 5",
2165N/A "givenName: 5User",
2165N/A "sn: 5",
2165N/A "cn: User 5",
2165N/A "mail: user5" + c + "@test",
2165N/A "userPassword: password",
2165N/A "employeeNumber: 5",
2165N/A "mobile: 1-555-1234",
2165N/A "pager: 1-555-5678",
2165N/A "telephoneNumber: 1-555-9012",
2165N/A "",
2165N/A "dn: uid=1user.1,ou=People1," + suffix,
2165N/A "objectClass: top",
2165N/A "objectClass: person",
2165N/A "objectClass: organizationalPerson",
2165N/A "objectClass: inetOrgPerson",
2165N/A "uid: 1",
2165N/A "givenName: 1User",
2165N/A "sn: 11",
2165N/A "cn: 1User 11",
2165N/A "userPassword: password",
2165N/A "mail: user11" + c + "@test",
2165N/A "employeeNumber: 111",
2165N/A "mobile: 2-111-1234",
2165N/A "pager: 2-111-5678",
2165N/A "telephoneNumber: 2-111-9012",
2165N/A "",
2165N/A "dn: uid=2user.22,ou=People1," + suffix,
2165N/A "objectClass: top",
2165N/A "objectClass: person",
2165N/A "objectClass: organizationalPerson",
2165N/A "objectClass: inetOrgPerson",
2165N/A "uid: 2",
2165N/A "givenName: 2User",
2165N/A "sn: 22",
2165N/A "cn: User 22",
2165N/A "mail: user22" + c + "@test",
2165N/A "userPassword: password",
2165N/A "employeeNumber: 222",
2165N/A "mobile: 2-222-1234",
2165N/A "pager: 2-222-5678",
2165N/A "telephoneNumber: 2-222-9012",
2165N/A "",
2165N/A "dn: uid=3user.33,ou=People1," + suffix,
2165N/A "objectClass: top",
2165N/A "objectClass: person",
2165N/A "objectClass: organizationalPerson",
2165N/A "objectClass: inetOrgPerson",
2165N/A "uid: 33",
2165N/A "givenName: 3User",
2165N/A "sn: 3",
2165N/A "cn: User 33",
2165N/A "mail: user33" + c + "@test",
2165N/A "userPassword: password",
2165N/A "employeeNumber: 333",
2165N/A "mobile: 2-333-1234",
2165N/A "pager: 2-333-5678",
2165N/A "telephoneNumber: 2-333-9012"
2165N/A );
2165N/A //Add an additional entry if the suffix is "dc=example,dc=com".
2165N/A if(suffix.equals("dc=example,dc=com")) {
2165N/A TestCaseUtils.addEntries(
2165N/A "dn: uid=2user.77,ou=People," + suffix,
2165N/A "objectClass: top",
2165N/A "objectClass: person",
2165N/A "objectClass: organizationalPerson",
2165N/A "objectClass: inetOrgPerson",
2165N/A "uid: 2",
2165N/A "givenName: 2User",
2165N/A "sn: 22",
2165N/A "cn: User 22",
2165N/A "mail: user77" + c + "@test",
2165N/A "userPassword: password",
2165N/A "employeeNumber: 777",
2165N/A "mobile: 2-777-1234",
2165N/A "pager: 2-777-5678",
2165N/A "telephoneNumber: 2-777-9012"
2165N/A );
2165N/A }
2165N/A }
2165N/A
6906N/A private void clearAcis(String suffix) throws Exception
6906N/A {
6906N/A deleteAttrsFromEntry(DN.decode("ou=People," + suffix), "aci");
6906N/A deleteAttrsFromEntry(DN.decode("ou=People1," + suffix), "aci");
6906N/A }
6906N/A
2165N/A /**
2165N/A * Remove the attributes specified by the attribute type strings from the
2165N/A * entry corresponding to the dn argument.
2165N/A *
2165N/A * @param dn The entry to remove the attributes from.
2165N/A * @param attrTypeStrings The attribute type string list to remove from the
2165N/A * entry.
2165N/A * @throws Exception If an error occurs.
2165N/A */
2165N/A private void
2165N/A deleteAttrsFromEntry(DN dn, String... attrTypeStrings) throws Exception {
2165N/A LinkedList<Modification> mods = new LinkedList<Modification>();
2165N/A for(String attrTypeString : attrTypeStrings) {
2165N/A AttributeType attrType = getAttrType(attrTypeString);
2165N/A mods.add(new Modification(ModificationType.DELETE,
3853N/A Attributes.empty(attrType)));
2165N/A }
2165N/A InternalClientConnection conn =
2165N/A InternalClientConnection.getRootConnection();
2165N/A conn.processModify(dn, mods);
2165N/A }
2165N/A
4134N/A
2165N/A
2250N/A private void
2250N/A replaceAttrInEntry(DN dn, String attrTypeString, String... attrValStrings) {
2250N/A LinkedList<Modification> mods = new LinkedList<Modification>();
2250N/A AttributeType attrType = getAttrType(attrTypeString);
3853N/A AttributeBuilder builder = new AttributeBuilder(attrType, attrTypeString);
3853N/A for(String valString : attrValStrings) {
4134N/A builder.add(AttributeValues.create(attrType, valString));
3853N/A }
3853N/A mods.add(new Modification(ModificationType.REPLACE, builder.toAttribute()));
2250N/A InternalClientConnection conn =
2250N/A InternalClientConnection.getRootConnection();
2250N/A conn.processModify(dn, mods);
2250N/A }
2250N/A
2250N/A
2165N/A /**
2165N/A * Try to add an entry to the server checking for the expected return
2165N/A * code.
2165N/A *
2165N/A * @param e The entry to add.
2165N/A * @param rc The expected return code.
2165N/A * @throws Exception If an error occurs.
2165N/A */
2165N/A private void addEntry(Entry e, ResultCode rc) throws Exception {
2165N/A InternalClientConnection conn =
2165N/A InternalClientConnection.getRootConnection();
2165N/A AddOperation addOperation = conn.processAdd(e);
2165N/A assertEquals(addOperation.getResultCode(), rc);
2165N/A }
2165N/A
2165N/A /**
2165N/A * Make a entry with the specified dn.
2165N/A *
2165N/A * @param dn The dn of the entry.
2165N/A * @return The created entry.
2165N/A * @throws Exception If the entry can't be created.
2165N/A */
2165N/A private Entry makeEntry(String dn) throws Exception {
2165N/A return TestCaseUtils.makeEntry(
2165N/A "dn: " + dn,
2165N/A "objectClass: top",
2165N/A "objectClass: person",
2165N/A "objectClass: organizationalPerson",
2165N/A "objectClass: inetOrgPerson",
2165N/A "uid: 1",
2165N/A "givenName: 1User",
2165N/A "sn: 1",
2165N/A "cn: 1User 1"
2165N/A );
2165N/A }
2165N/A
2165N/A /**
2165N/A * Remove an attribute from the specified entry.
2165N/A *
2165N/A * @param entry The entry to remove the attribute from.
2165N/A * @param attrTypeString The attribute type string to remove.
2165N/A */
2165N/A private void delAttribute(Entry entry, String attrTypeString) {
2165N/A entry.removeAttribute(getAttrType(attrTypeString));
2165N/A }
2165N/A
2165N/A /**
2165N/A * Add an attribute to an entry with specified values.
2165N/A *
2165N/A * @param entry The entry to add the attribute to.
2165N/A * @param attrTypeString The attribute type string name.
2165N/A * @param attrValues The values use in building the attribute.
2165N/A */
2165N/A private void
2165N/A addAttribute(Entry entry, String attrTypeString, String... attrValues) {
2165N/A AttributeType attrType=getAttrType(attrTypeString);
3853N/A AttributeBuilder builder = new AttributeBuilder(attrType, attrTypeString);
2165N/A for(String attrValue : attrValues) {
3853N/A builder.add(attrValue);
2165N/A }
3853N/A entry.addAttribute(builder.toAttribute(), null);
2165N/A }
2165N/A
2165N/A /**
2165N/A * Add a new modification for attribute type string and values of modification
2165N/A * type to a list of modifications.
2165N/A *
2165N/A * @param mods The modification list to add to.
2165N/A * @param attrTypeString The attribute type string name.
2165N/A * @param modificationType The modification type.
2165N/A * @param attrValues The values to build the modification from.
2165N/A */
2165N/A private void
2165N/A addMods(LinkedList<Modification> mods, String attrTypeString,
2165N/A ModificationType modificationType, String... attrValues) {
2165N/A AttributeType attrType=getAttrType(attrTypeString);
3853N/A AttributeBuilder builder = new AttributeBuilder(attrType, attrTypeString);
2165N/A for(String attrValue : attrValues) {
3853N/A builder.add(attrValue);
2165N/A }
2165N/A mods.add(new Modification(modificationType,
3853N/A builder.toAttribute()));
2165N/A }
2165N/A
2165N/A /**
2165N/A * Return the attribute type corresponding to the attribute type string.
2165N/A *
2165N/A * @param attrTypeString The attribute type string name.
2165N/A *
2165N/A * @return An attribute type object pertaining to the string.
2165N/A */
2165N/A private AttributeType getAttrType(String attrTypeString) {
2165N/A AttributeType attrType =
2165N/A DirectoryServer.getAttributeType(attrTypeString);
2165N/A if (attrType == null)
2165N/A attrType = DirectoryServer.getDefaultAttributeType(attrTypeString);
2165N/A return attrType;
2165N/A }
2165N/A
2165N/A /**
2165N/A * Perform modify operation with list of modifications. Expect return code
2165N/A * of value rc.
2165N/A *
2165N/A * @param mods The modification list to use.
2165N/A * @param dn The DN of the entry to modify.
2165N/A * @param rc The expected return code.
2165N/A */
2165N/A private void
2165N/A doMods(LinkedList<Modification> mods, DN dn, ResultCode rc ) {
2165N/A InternalClientConnection conn =
2165N/A InternalClientConnection.getRootConnection();
2165N/A ModifyOperation modifyOperation =
2165N/A conn.processModify(dn, mods);
2165N/A assertEquals(modifyOperation.getResultCode(), rc);
2165N/A }
2165N/A
2165N/A /**
2165N/A * Perform modify DN operation. Expect return value of rc.
2165N/A *
2165N/A * @param dn The DN to renmame or move.
2165N/A * @param rdn RDN value.
2165N/A * @param delOld Delete old flag.
2165N/A * @param newSuperior New superior to move to.
2165N/A * @param rc Expected return code from operation.
2165N/A */
2165N/A private void
2165N/A doModDN(DN dn, RDN rdn, boolean delOld, DN newSuperior, ResultCode rc) {
2165N/A InternalClientConnection conn =
2165N/A InternalClientConnection.getRootConnection();
2165N/A ModifyDNOperation modifyDNOperation =
2165N/A conn.processModifyDN(dn, rdn, delOld, newSuperior);
2165N/A assertEquals(modifyDNOperation.getResultCode(), rc);
2165N/A }
2165N/A}