From b25fe5e9c226441bbcaf23ce002924422e3e54e4 Mon Sep 17 00:00:00 2001
From: neil_a_wilson <neil_a_wilson@localhost>
Date: Fri, 23 Feb 2007 19:47:24 +0000
Subject: [PATCH] Update the entry schema checking code to ensure that all attributes have at least one value. This will prevent add requests from being able to add entries containing attributes with no values.
---
opends/tests/unit-tests-testng/src/server/org/opends/server/core/AddOperationTestCase.java | 38 +++++++++++++++++++
opends/src/server/org/opends/server/types/Entry.java | 37 +++++++++++-------
opends/src/server/org/opends/server/messages/CoreMessages.java | 14 +++++++
3 files changed, 74 insertions(+), 15 deletions(-)
diff --git a/opends/src/server/org/opends/server/messages/CoreMessages.java b/opends/src/server/org/opends/server/messages/CoreMessages.java
index 365473e..e3980ad 100644
--- a/opends/src/server/org/opends/server/messages/CoreMessages.java
+++ b/opends/src/server/org/opends/server/messages/CoreMessages.java
@@ -6248,6 +6248,16 @@
/**
+ * The message ID for the message that will be used if an entry includes an
+ * attribute with no values. This takes two arguments, which are the DN of
+ * the entry and the name of the attribute.
+ */
+ public static final int MSGID_ENTRY_SCHEMA_ATTR_NO_VALUES =
+ CATEGORY_MASK_CORE | SEVERITY_MASK_MILD_ERROR | 597;
+
+
+
+ /**
* Associates a set of generic messages with the message IDs defined
* in this class.
*/
@@ -6638,6 +6648,10 @@
"configuration because it includes attribute %s which is " +
"not allowed by any of the objectclasses defined in that " +
"entry.");
+ registerMessage(MSGID_ENTRY_SCHEMA_ATTR_NO_VALUES,
+ "Entry %s violates the Directory Server schema " +
+ "configuration because it includes attribute %s without " +
+ "any values.");
registerMessage(MSGID_ENTRY_SCHEMA_ATTR_SINGLE_VALUED,
"Entry %s violates the Directory Server schema " +
"configuration because it includes multiple values for " +
diff --git a/opends/src/server/org/opends/server/types/Entry.java b/opends/src/server/org/opends/server/types/Entry.java
index bca93d4..c9cd45e 100644
--- a/opends/src/server/org/opends/server/types/Entry.java
+++ b/opends/src/server/org/opends/server/types/Entry.java
@@ -2617,9 +2617,9 @@
}
- // Make sure all the user attributes are allowed, and make sure
- // that if they are single-valued that they properly conform to
- // that.
+ // Make sure all the user attributes are allowed, have at least
+ // one value, and if they are single-valued that they have exactly
+ // one value.
for (AttributeType t : userAttributes.keySet())
{
boolean found = false;
@@ -2649,22 +2649,29 @@
return false;
}
- if (t.isSingleValue())
+ List<Attribute> attrList = userAttributes.get(t);
+ if (attrList != null)
{
- List<Attribute> attrList = userAttributes.get(t);
- if (attrList != null)
+ for (Attribute a : attrList)
{
- for (Attribute a : attrList)
+ LinkedHashSet<AttributeValue> values = a.getValues();
+ if (values.isEmpty())
{
- if (a.getValues().size() > 1)
- {
- int msgID = MSGID_ENTRY_SCHEMA_ATTR_SINGLE_VALUED;
- String message = getMessage(msgID, String.valueOf(dn),
- t.getNameOrOID());
+ int msgID = MSGID_ENTRY_SCHEMA_ATTR_NO_VALUES;
+ String message = getMessage(msgID, String.valueOf(dn),
+ t.getNameOrOID());
- invalidReason.append(message);
- return false;
- }
+ invalidReason.append(message);
+ return false;
+ }
+ else if (t.isSingleValue() && (values.size() != 1))
+ {
+ int msgID = MSGID_ENTRY_SCHEMA_ATTR_SINGLE_VALUED;
+ String message = getMessage(msgID, String.valueOf(dn),
+ t.getNameOrOID());
+
+ invalidReason.append(message);
+ return false;
}
}
}
diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/core/AddOperationTestCase.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/core/AddOperationTestCase.java
index fffdfbd..12acf73 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/server/core/AddOperationTestCase.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/server/core/AddOperationTestCase.java
@@ -31,6 +31,7 @@
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
import java.util.concurrent.locks.Lock;
import org.testng.annotations.DataProvider;
@@ -1546,6 +1547,43 @@
/**
+ * Tests the behavior of the server when attempting to perform an add \
+ * operation with an entry containing an attribute with zero values.
+ *
+ * @throws Exception If an unexpected problem occurs.
+ */
+ @Test()
+ public void testInternalAddFailureEmptyAttribute()
+ throws Exception
+ {
+ TestCaseUtils.initializeTestBackend(false);
+
+ Entry entry = TestCaseUtils.makeEntry(
+ "dn: o=test",
+ "objectClass: top",
+ "objectClass: organization",
+ "o: test");
+
+ Map<AttributeType,List<Attribute>> userAttrs = entry.getUserAttributes();
+
+ AttributeType attrType = DirectoryServer.getAttributeType("description");
+ ArrayList<Attribute> attrList = new ArrayList<Attribute>();
+ attrList.add(new Attribute(attrType));
+ userAttrs.put(attrType, attrList);
+
+
+ InternalClientConnection conn =
+ InternalClientConnection.getRootConnection();
+
+ AddOperation addOperation =
+ conn.processAdd(entry.getDN(), entry.getObjectClasses(), userAttrs,
+ entry.getOperationalAttributes());
+ assertFalse(addOperation.getResultCode() == ResultCode.SUCCESS);
+ }
+
+
+
+ /**
* Tests a failed internal add operation with the server in complete read-only
* mode.
*
--
Gitblit v1.10.0