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

neil_a_wilson
30.11.2006 d18b5f40f835c8c56a677c213e51f381bf4ff9f9
Fix a bug in the server in which the SINGLE-VALUE constraint was not properly
enforced for operational attributes.

OpenDS Issue Number: 1048
2 files modified
128 ■■■■■ changed files
opends/src/server/org/opends/server/types/Entry.java 26 ●●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/core/ModifyOperationTestCase.java 102 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/types/Entry.java
@@ -2246,6 +2246,32 @@
    }
    // Iterate through all of the operational attributes and make sure
    // that all of the single-valued attributes only have one value.
    for (AttributeType t : operationalAttributes.keySet())
    {
      if (t.isSingleValue())
      {
        List<Attribute> attrList = operationalAttributes.get(t);
        if (attrList != null)
        {
          for (Attribute a : attrList)
          {
            if (a.getValues().size() > 1)
            {
              int    msgID   = MSGID_ENTRY_SCHEMA_ATTR_SINGLE_VALUED;
              String message = getMessage(msgID, String.valueOf(dn),
                                          t.getNameOrOID());
              invalidReason.append(message);
              return false;
            }
          }
        }
      }
    }
    // Optionally, make sure that the entry contains exactly one
    // structural objectclass.
    AcceptRejectWarn structuralPolicy =
opends/tests/unit-tests-testng/src/server/org/opends/server/core/ModifyOperationTestCase.java
@@ -867,6 +867,57 @@
  /**
   * Tests to ensure that a modify attempt fails if an attempt is made to add a
   * second value to a single-valued operational attribute.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Test()
  public void testFailAddToSingleValuedOperationalAttribute()
         throws Exception
  {
    TestCaseUtils.initializeTestBackend(true);
    Entry entry = TestCaseUtils.makeEntry(
         "dn: uid=test.user,o=test",
         "objectClass: top",
         "objectClass: person",
         "objectClass: organizationalPerson",
         "objectClass: inetOrgPerson",
         "uid: test.user",
         "givenName: Test",
         "sn: User",
         "cn: Test User",
         "displayName: Test User",
         "userPassword: password",
         "ds-pwp-account-disabled: true");
    InternalClientConnection conn =
         InternalClientConnection.getRootConnection();
    AddOperation addOperation =
         conn.processAdd(entry.getDN(), entry.getObjectClasses(),
                         entry.getUserAttributes(),
                         entry.getOperationalAttributes());
    assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS);
    ArrayList<ASN1OctetString> values = new ArrayList<ASN1OctetString>();
    values.add(new ASN1OctetString("false"));
    LDAPAttribute attr = new LDAPAttribute("ds-pwp-account-disabled", values);
    ArrayList<LDAPModification> mods = new ArrayList<LDAPModification>();
    mods.add(new LDAPModification(ModificationType.ADD, attr));
    ModifyOperation modifyOperation =
         conn.processModify(new ASN1OctetString("uid=test.user,o=test"), mods);
    assertFalse(modifyOperation.getResultCode() == ResultCode.SUCCESS);
    retrieveFailedOperationElements(modifyOperation);
  }
  /**
   * Tests to ensure that a modify attempt fails if an attempt is made to
   * replace a single-valued attribute with multiple values.
   *
@@ -918,6 +969,57 @@
  /**
   * Tests to ensure that a modify attempt fails if an attempt is made to
   * replace a single-valued operational attribute with multiple values.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Test()
  public void testFailReplaceSingleValuedOperationalAttrWithMultipleValues()
         throws Exception
  {
    TestCaseUtils.initializeTestBackend(true);
    Entry entry = TestCaseUtils.makeEntry(
         "dn: uid=test.user,o=test",
         "objectClass: top",
         "objectClass: person",
         "objectClass: organizationalPerson",
         "objectClass: inetOrgPerson",
         "uid: test.user",
         "givenName: Test",
         "sn: User",
         "cn: Test User",
         "displayName: Test User",
         "userPassword: password");
    InternalClientConnection conn =
         InternalClientConnection.getRootConnection();
    AddOperation addOperation =
         conn.processAdd(entry.getDN(), entry.getObjectClasses(),
                         entry.getUserAttributes(),
                         entry.getOperationalAttributes());
    assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS);
    ArrayList<ASN1OctetString> values = new ArrayList<ASN1OctetString>();
    values.add(new ASN1OctetString("true"));
    values.add(new ASN1OctetString("false"));
    LDAPAttribute attr = new LDAPAttribute("ds-pwp-account-disabled", values);
    ArrayList<LDAPModification> mods = new ArrayList<LDAPModification>();
    mods.add(new LDAPModification(ModificationType.REPLACE, attr));
    ModifyOperation modifyOperation =
         conn.processModify(new ASN1OctetString("uid=test.user,o=test"), mods);
    assertFalse(modifyOperation.getResultCode() == ResultCode.SUCCESS);
    retrieveFailedOperationElements(modifyOperation);
  }
  /**
   * Tests to ensure that a modify attempt fails if an attempt is made to add a
   * value that matches one that already exists.
   *