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

Matthew Swift
16.43.2011 5af30c2b6e071cc0c857d122f9cdb6821bb365ff
Partial fix for OPENDJ-198: RFC 4512 compliance for ldap-toolkit

Add schema compatibility option and disabled unit tests.
1 files added
1 files modified
205 ■■■■■ changed files
opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/schema/SchemaCompatOptions.java 62 ●●●●● patch | view | raw | blame | history
opendj3/opendj-ldap-sdk/src/test/java/org/forgerock/opendj/ldap/schema/SchemaCompatOptionsTest.java 143 ●●●●● patch | view | raw | blame | history
opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/schema/SchemaCompatOptions.java
@@ -67,6 +67,8 @@
  private boolean allowZeroLengthDirectoryStrings = false;
  private boolean allowMalformedNamesAndOptions = false;
  // Prevent direct instantiation.
@@ -78,6 +80,58 @@
  /**
   * Returns {@code true} if the schema should allow certain illegal characters
   * in OIDs and attribute options. When this compatibility option is set to
   * {@code true} the following illegal characters will be permitted:
   *
   * <pre>
   * USCORE  = %x5F ; underscore ("_")
   * DOT     = %x2E ; period (".")
   * </pre>
   *
   * By default this compatibility option is set to {@code false}.
   *
   * @return {@code true} if the schema should allow certain illegal characters
   *         in OIDs and attribute options.
   * @see <a href="http://tools.ietf.org/html/rfc4512">RFC 4512 - Lightweight
   *      Directory Access Protocol (LDAP): Directory Information Models </a>
   */
  public boolean allowMalformedNamesAndOptions()
  {
    return allowMalformedNamesAndOptions;
  }
  /**
   * Specifies whether or not the schema should allow certain illegal characters
   * in OIDs and attribute options. When this compatibility option is set to
   * {@code true} the following illegal characters will be permitted:
   *
   * <pre>
   * USCORE  = %x5F ; underscore ("_")
   * DOT     = %x2E ; period (".")
   * </pre>
   *
   * By default this compatibility option is set to {@code false}.
   *
   * @param allowMalformedNamesAndOptions
   *          {@code true} if the schema should allow certain illegal characters
   *          in OIDs and attribute options.
   * @return A reference to this {@code SchemaCompatOptions}.
   * @see <a href="http://tools.ietf.org/html/rfc4512">RFC 4512 - Lightweight
   *      Directory Access Protocol (LDAP): Directory Information Models </a>
   */
  public SchemaCompatOptions allowMalformedNamesAndOptions(
      final boolean allowMalformedNamesAndOptions)
  {
    this.allowMalformedNamesAndOptions = allowMalformedNamesAndOptions;
    return this;
  }
  /**
   * Returns {@code true} if the Telephone Number syntax should allow values
   * which do not conform to the E.123 international telephone number format.
   * <p>
@@ -160,10 +214,10 @@
  // Assigns the provided options to this set of options.
  SchemaCompatOptions assign(final SchemaCompatOptions options)
  {
    return allowNonStandardTelephoneNumbers(
        options.allowNonStandardTelephoneNumbers)
        .allowZeroLengthDirectoryStrings(
            options.allowNonStandardTelephoneNumbers);
    this.allowMalformedNamesAndOptions = options.allowMalformedNamesAndOptions;
    this.allowNonStandardTelephoneNumbers =options.allowNonStandardTelephoneNumbers;
    this.allowZeroLengthDirectoryStrings = options.allowZeroLengthDirectoryStrings;
    return this;
  }
}
opendj3/opendj-ldap-sdk/src/test/java/org/forgerock/opendj/ldap/schema/SchemaCompatOptionsTest.java
New file
@@ -0,0 +1,143 @@
/*
 * 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/opendj3/legal-notices/CDDLv1_0.txt
 * or http://forgerock.org/license/CDDLv1.0.html.
 * 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/opendj3/legal-notices/CDDLv1_0.txt.  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 2011 ForgeRock AS.
 */
package org.forgerock.opendj.ldap.schema;
import org.forgerock.i18n.LocalizedIllegalArgumentException;
import org.forgerock.opendj.ldap.AttributeDescription;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
/**
 * Test SchemaCompatOptions.
 */
public class SchemaCompatOptionsTest extends SchemaTestCase
{
  /**
   * Returns test data for valid attribute descriptions.
   *
   * @return The test data.
   */
  @DataProvider
  public Object[][] validAttributeDescriptions()
  {
    // @formatter:off
    return new Object[][] {
        // No options.
        { "cn", false },
        { "cn-xxx", false },
        { "cn", true },
        { "cn-xxx", true },
        { "cn_xxx", true },
        { "cn.xxx", true },
        // With options.
        { "cn;xxx", false },
        { "cn;xxx-yyy", false },
        { "cn;xxx", true },
        { "cn;xxx-yyy", true },
        { "cn;xxx_yyy", true },
        { "cn;xxx.yyy", true },
    };
    // @formatter:on
  }
  /**
   * Tests valid attribute description parsing behavior depends on compat
   * options.
   *
   * @param atd
   *          The attribute description to be parsed.
   * @param allowIllegalCharacters
   *          {@code true} if the attribute description requires the
   *          compatibility option to be set.
   */
  @Test(enabled = false, dataProvider = "validAttributeDescriptions")
  public void testValidAttributeDescriptions(String atd,
      boolean allowIllegalCharacters)
  {
    SchemaBuilder builder = new SchemaBuilder(Schema.getCoreSchema())
        .setSchemaCompatOptions(SchemaCompatOptions.defaultOptions()
            .allowMalformedNamesAndOptions(allowIllegalCharacters));
    Schema schema = builder.toSchema().nonStrict();
    AttributeDescription.valueOf(atd, schema);
  }
  /**
   * Returns test data for invalid attribute descriptions.
   *
   * @return The test data.
   */
  @DataProvider
  public Object[][] invalidAttributeDescriptions()
  {
    // @formatter:off
    return new Object[][] {
        // No options.
        { "cn+xxx", false }, // always invalid
        { "cn_xxx", false },
        { "cn.xxx", false },
        { "cn+xxx", true }, // always invalid
        // With options.
        { "cn;xxx+yyy", false }, // always invalid
        { "cn;xxx_yyy", false },
        { "cn;xxx.yyy", false },
        { "cn;xxx+yyy", true }, // always invalid
    };
    // @formatter:on
  }
  /**
   * Tests invalid attribute description parsing behavior depends on compat
   * options.
   *
   * @param atd
   *          The attribute description to be parsed.
   * @param allowIllegalCharacters
   *          {@code true} if the attribute description requires the
   *          compatibility option to be set.
   */
  @Test(enabled = false, dataProvider = "invalidAttributeDescriptions",
      expectedExceptions = LocalizedIllegalArgumentException.class)
  public void testinvalidAttributeDescriptions(String atd,
      boolean allowIllegalCharacters)
  {
    SchemaBuilder builder = new SchemaBuilder(Schema.getCoreSchema())
        .setSchemaCompatOptions(SchemaCompatOptions.defaultOptions()
            .allowMalformedNamesAndOptions(allowIllegalCharacters));
    Schema schema = builder.toSchema().nonStrict();
    AttributeDescription.valueOf(atd, schema);
  }
}