From e6d55f1cb96307f6c23b49eef784888ae20de373 Mon Sep 17 00:00:00 2001
From: sin <sin@localhost>
Date: Sat, 07 Feb 2009 03:12:59 +0000
Subject: [PATCH] Fix for issue#3391:Custom DIT Structure Rules are not added in 99-user.ldif but in 03-uddiv3.ldif
---
opendj-sdk/opends/src/messages/messages/backend.properties | 5 +
opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/types/DITContentRuleTestCase.java | 177 ++++++++++++++++++++++++++++++++++++++++++++
opendj-sdk/opends/src/server/org/opends/server/backends/SchemaBackend.java | 17 ++++
3 files changed, 197 insertions(+), 2 deletions(-)
diff --git a/opendj-sdk/opends/src/messages/messages/backend.properties b/opendj-sdk/opends/src/messages/messages/backend.properties
index b39b2fb..5f365cc 100644
--- a/opendj-sdk/opends/src/messages/messages/backend.properties
+++ b/opendj-sdk/opends/src/messages/messages/backend.properties
@@ -20,7 +20,7 @@
#
# CDDL HEADER END
#
-# Copyright 2006-2008 Sun Microsystems, Inc.
+# Copyright 2006-2009 Sun Microsystems, Inc.
@@ -1133,3 +1133,6 @@
SEVERE_ERR_BACKUP_CANNOT_UPDATE_BACKUP_DESCRIPTOR_408=An error occurred \
while attempting to update the backup descriptor file %s with information \
about the backup: %s
+MILD_ERR_SCHEMA_MODIFY_RULEID_CONFLICTS_FOR_ADD_DSR_409=Unable to add DIT \
+ structure rule %s because its rule identifier conflicts with existing DIT structure \
+ rule (%s)
diff --git a/opendj-sdk/opends/src/server/org/opends/server/backends/SchemaBackend.java b/opendj-sdk/opends/src/server/org/opends/server/backends/SchemaBackend.java
index 72a789f..541eb36 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/backends/SchemaBackend.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/backends/SchemaBackend.java
@@ -22,7 +22,7 @@
* CDDL HEADER END
*
*
- * Copyright 2006-2008 Sun Microsystems, Inc.
+ * Copyright 2006-2009 Sun Microsystems, Inc.
*/
package org.opends.server.backends;
@@ -2768,6 +2768,8 @@
// refuse the operation).
DITStructureRule existingDSR =
schema.getDITStructureRule(ditStructureRule.getRuleID());
+ //Boolean to check if the new rule is in use or not.
+ boolean inUse = false;
for (DITStructureRule dsr : schema.getDITStructureRulesByID().values())
{
for (String name : ditStructureRule.getNames().keySet())
@@ -2784,10 +2786,23 @@
throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM,
message);
}
+ inUse = true;
}
}
}
+ if(existingDSR != null && !inUse)
+ {
+ //We have an existing DSR with the same rule id but we couldn't find
+ //any existing rules sharing this name. It means that it is a
+ //new rule with a conflicting rule id.Raise an Exception as the
+ //rule id should be unique.
+ Message message = ERR_SCHEMA_MODIFY_RULEID_CONFLICTS_FOR_ADD_DSR.
+ get(ditStructureRule.getNameOrRuleID(),
+ existingDSR.getNameOrRuleID());
+ throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM,
+ message);
+ }
// Get the name form for the new DIT structure rule and see if there's
// already an existing rule that is associated with that name form. If
diff --git a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/types/DITContentRuleTestCase.java b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/types/DITContentRuleTestCase.java
new file mode 100644
index 0000000..3396c1f
--- /dev/null
+++ b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/types/DITContentRuleTestCase.java
@@ -0,0 +1,177 @@
+/*
+ * 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
+ * trunk/opends/resource/legal-notices/OpenDS.LICENSE
+ * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
+ * 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
+ * trunk/opends/resource/legal-notices/OpenDS.LICENSE. 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 2009 Sun Microsystems, Inc.
+ */
+package org.opends.server.types;
+
+
+
+import static org.testng.Assert.*;
+
+import org.opends.server.TestCaseUtils;
+import org.opends.server.tools.LDAPModify;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+
+
+/**
+ * This class provides a set of test cases for virtual attributes.
+ */
+public class DITContentRuleTestCase
+ extends TypesTestCase
+{
+
+
+
+ /**
+ * Ensures that the Directory Server is running.
+ *
+ * @throws Exception If an unexpected problem occurs.
+ */
+ @BeforeClass()
+ public void startServer()
+ throws Exception
+ {
+ TestCaseUtils.startServer();
+ }
+
+
+
+ /**
+ * Tests the addition of a new DITConentRule with a conflicting
+ * rule identifier.
+ *
+ * @throws Exception If an unexpected problem occurs.
+ */
+ @Test()
+ public void testInvalidDITContentRule()
+ throws Exception
+ {
+ String filePath = TestCaseUtils.createTempFile(
+ "dn: cn=schema",
+ "changetype: modify",
+ "add: nameForms",
+ "nameForms: ( 1.3.6.1.1.10.15.100 NAME 'domainNameForm' OC domain MUST ( dc ) )",
+ "-",
+ "add: dITStructureRules",
+ "dITStructureRules: ( 1 NAME 'domainStructureRule' FORM domainNameForm )"
+ );
+ String[] args = new String []
+ {
+ "-h", "127.0.0.1",
+ "-p", String.valueOf(TestCaseUtils.getServerLdapPort()),
+ "-D","cn=directory manager",
+ "-w","password",
+ "-a",
+ "-f", filePath
+ };
+ int err = LDAPModify.mainModify(args, false, null,null);
+ //Shouldn't perform this operation.
+ assertEquals(err,53);
+ }
+
+
+
+ /**
+ * Tests the addition of new DITContentRules with unique rule ids.
+ *
+ * @throws Exception If an unexpected problem occurs.
+ */
+ @Test(dependsOnMethods = {"org.opends.server.types."+
+ "DITContentRuleTestCase.testInvalidDITContentRule"})
+ public void testValidDITRContentRules()
+ throws Exception
+ {
+ String filePath = TestCaseUtils.createTempFile(
+ "dn: cn=schema",
+ "changetype: modify",
+ "add: nameForms",
+ "nameForms: ( 1.3.6.1.1.10.15.11 NAME 'domainNameForm' OC domain MUST ( dc ) )",
+ "nameForms: ( 1.3.6.1.1.10.15.12 NAME 'organizationalUnitNameForm' OC organizationalUnit MUST ( ou ) )",
+ "nameForms: ( 1.3.6.1.1.10.15.13 NAME 'inetOrgPersonNameForm' OC inetOrgPerson MUST ( uid ) )",
+ "nameForms: ( 1.3.6.1.1.10.15.14 NAME 'groupOfNamesNameForm' OC groupOfNames MUST ( cn ) )",
+ "-",
+ "add: dITStructureRules",
+ "dITStructureRules: ( 11 NAME 'domainStructureRule' FORM domainNameForm )",
+ "dITStructureRules: ( 12 NAME 'organizationalUnitStructureRule' FORM organizationalUnitNameForm SUP 1 )",
+ "dITStructureRules: ( 13 NAME 'inetOrgPersonStructureRule' FORM inetOrgPersonNameForm SUP 2 )",
+ "dITStructureRules: ( 14 NAME 'groupOfNamesStructureRule' FORM groupOfNamesNameForm SUP 2 )"
+ );
+ String[] args = new String []
+ {
+ "-h", "127.0.0.1",
+ "-p", String.valueOf(TestCaseUtils.getServerLdapPort()),
+ "-D","cn=directory manager",
+ "-w","password",
+ "-a",
+ "-f", filePath
+ };
+ int err = LDAPModify.mainModify(args, false, null,null);
+ //Should add the above entries.
+ assertEquals(err,0);
+ }
+
+
+
+ /**
+ * Cleans up the DITContentRules.
+ *
+ * @throws Exception If an unexpected problem occurs.
+ */
+ @Test(dependsOnMethods = {"org.opends.server.types."+
+ "DITContentRuleTestCase.testValidDITRContentRules"})
+ public void cleanUpDITRContentRules()
+ throws Exception
+ {
+ String filePath = TestCaseUtils.createTempFile(
+ "dn: cn=schema",
+ "changetype: modify",
+ "delete: dITStructureRules",
+ "dITStructureRules: ( 11 NAME 'domainStructureRule' FORM domainNameForm )",
+ "dITStructureRules: ( 12 NAME 'organizationalUnitStructureRule' FORM organizationalUnitNameForm SUP 1 )",
+ "dITStructureRules: ( 13 NAME 'inetOrgPersonStructureRule' FORM inetOrgPersonNameForm SUP 2 )",
+ "dITStructureRules: ( 14 NAME 'groupOfNamesStructureRule' FORM groupOfNamesNameForm SUP 2 )",
+ "-",
+ "delete: nameForms",
+ "nameForms: ( 1.3.6.1.1.10.15.11 NAME 'domainNameForm' OC domain MUST ( dc ) )",
+ "nameForms: ( 1.3.6.1.1.10.15.12 NAME 'organizationalUnitNameForm' OC organizationalUnit MUST ( ou ) )",
+ "nameForms: ( 1.3.6.1.1.10.15.13 NAME 'inetOrgPersonNameForm' OC inetOrgPerson MUST ( uid ) )",
+ "nameForms: ( 1.3.6.1.1.10.15.14 NAME 'groupOfNamesNameForm' OC groupOfNames MUST ( cn ) )"
+ );
+ String[] args = new String []
+ {
+ "-h", "127.0.0.1",
+ "-p", String.valueOf(TestCaseUtils.getServerLdapPort()),
+ "-D","cn=directory manager",
+ "-w","password",
+ "-a",
+ "-f", filePath
+ };
+ int err = LDAPModify.mainModify(args, false, null,null);
+ //Should delete the above entries.
+ assertEquals(err,0);
+ }
+}
\ No newline at end of file
--
Gitblit v1.10.0