mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

neil_a_wilson
23.47.2007 b25fe5e9c226441bbcaf23ce002924422e3e54e4
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 Issue Number: 1275
3 files modified
73 ■■■■■ changed files
opends/src/server/org/opends/server/messages/CoreMessages.java 14 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/types/Entry.java 21 ●●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/core/AddOperationTestCase.java 38 ●●●●● patch | view | raw | blame | history
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 " +
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,14 +2649,22 @@
        return false;
      }
      if (t.isSingleValue())
      {
        List<Attribute> attrList = userAttributes.get(t);
        if (attrList != null)
        {
          for (Attribute a : attrList)
          {
            if (a.getValues().size() > 1)
          LinkedHashSet<AttributeValue> values = a.getValues();
          if (values.isEmpty())
          {
            int    msgID   = MSGID_ENTRY_SCHEMA_ATTR_NO_VALUES;
            String message = getMessage(msgID, String.valueOf(dn),
                                        t.getNameOrOID());
            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),
@@ -2668,7 +2676,6 @@
          }
        }
      }
    }
    // Iterate through all of the operational attributes and make sure
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.
   *