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

neil_a_wilson
23.47.2007 710fd572ca85a5b1eb9734e00794617c0beeb005
opendj-sdk/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 " +
opendj-sdk/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;
          }
        }
      }
opendj-sdk/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.
   *