From e85d13fcc0c039637fa1be2ca911c1034128a4a4 Mon Sep 17 00:00:00 2001
From: Chris Ridd <chris.ridd@forgerock.com>
Date: Mon, 17 Aug 2015 10:13:35 +0000
Subject: [PATCH] CR-7933 OPENDJ-2240 Handle lack of spaces at end of attributeType values
---
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/AttributeTypeSyntaxImpl.java | 4 +-
opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/SchemaBuilderTestCase.java | 76 ++++++++++++++++++++++++++++++++++++++
opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/AttributeTypeSyntaxTest.java | 6 ++
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/SchemaBuilder.java | 2
4 files changed, 84 insertions(+), 4 deletions(-)
diff --git a/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/AttributeTypeSyntaxImpl.java b/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/AttributeTypeSyntaxImpl.java
index 5893ce3..450ca44 100644
--- a/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/AttributeTypeSyntaxImpl.java
+++ b/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/AttributeTypeSyntaxImpl.java
@@ -22,7 +22,7 @@
*
*
* Copyright 2009 Sun Microsystems, Inc.
- * Portions copyright 2011-2014 ForgeRock AS
+ * Portions copyright 2011-2015 ForgeRock AS
*/
package org.forgerock.opendj.ldap.schema;
@@ -175,7 +175,7 @@
reader.skipWhitespaces();
reader.mark();
- while (reader.read() != ' ') {
+ while (" )".indexOf(reader.read()) == -1) {
length++;
}
diff --git a/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/SchemaBuilder.java b/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/SchemaBuilder.java
index 95a7510..a4fc04d 100644
--- a/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/SchemaBuilder.java
+++ b/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/SchemaBuilder.java
@@ -351,7 +351,7 @@
reader.skipWhitespaces();
reader.mark();
- while (reader.read() != ' ') {
+ while (" )".indexOf(reader.read()) == -1) {
length++;
}
reader.reset();
diff --git a/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/AttributeTypeSyntaxTest.java b/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/AttributeTypeSyntaxTest.java
index 848f2ea..88da6be 100644
--- a/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/AttributeTypeSyntaxTest.java
+++ b/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/AttributeTypeSyntaxTest.java
@@ -22,7 +22,7 @@
*
*
* Copyright 2009 Sun Microsystems, Inc.
- * Portions copyright 2014 ForgeRock AS.
+ * Portions copyright 2014-2015 ForgeRock AS.
*/
package org.forgerock.opendj.ldap.schema;
@@ -69,6 +69,10 @@
+ " X-SCHEMA-FILE '33-test.ldif' )", true},
{
"(1.2.8.5 USAGE directoryOperation )", true },
+ {
+ "(1.2.8.5 USAGE directoryOperation)", true },
+ {
+ "(1.2.8.5 USAGE directoryOperation X-SCHEMA-FILE '99-test.ldif')", true },
// Collective can inherit from non-collective
{ "(1.2.8.5 NAME 'testtype' DESC 'full type' OBSOLETE SUP cn "
diff --git a/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/SchemaBuilderTestCase.java b/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/SchemaBuilderTestCase.java
index 1713437..26ef964 100644
--- a/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/SchemaBuilderTestCase.java
+++ b/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/SchemaBuilderTestCase.java
@@ -469,6 +469,82 @@
}
/**
+ * Adds an attribute to the schema, without a space between the usage and the
+ * right paren.
+ *
+ * @throws Exception
+ */
+ @Test
+ public final void testSchemaBuilderAttributeWithoutSpace() throws Exception {
+ // @formatter:off
+ final String[] strEntry = {
+ "dn: cn=schema",
+ "objectClass: top",
+ "objectClass: ldapSubentry",
+ "objectClass: subschema",
+ "cn: schema",
+ "attributeTypes: ( foo-oid NAME 'foo' SUP name DESC 'No trailing space' USAGE userApplications)"
+ };
+ // @formatter:on
+ final Entry e = new LinkedHashMapEntry(strEntry);
+ final SchemaBuilder builder = new SchemaBuilder();
+ builder.addSchema(Schema.getCoreSchema(), false);
+ builder.addSchema(e, true);
+
+ assertThat(e.getAttribute(Schema.ATTR_LDAP_SYNTAXES)).isNull();
+ assertThat(e.getAttribute(Schema.ATTR_ATTRIBUTE_TYPES)).isNotNull();
+ assertThat(e.getAttribute(Schema.ATTR_OBJECT_CLASSES)).isNull();
+ assertThat(e.getAttribute(Schema.ATTR_MATCHING_RULE_USE)).isNull();
+ assertThat(e.getAttribute(Schema.ATTR_MATCHING_RULES)).isNull();
+ assertThat(e.getAttribute(Schema.ATTR_DIT_CONTENT_RULES)).isNull();
+ assertThat(e.getAttribute(Schema.ATTR_DIT_STRUCTURE_RULES)).isNull();
+ assertThat(e.getAttribute(Schema.ATTR_NAME_FORMS)).isNull();
+
+ Schema schema = builder.toSchema();
+ // No warnings
+ assertThat(schema.getWarnings()).isEmpty();
+ assertThat(schema.getAttributeType("foo").getDescription()).isEqualTo("No trailing space");
+ }
+
+ /**
+ * Adds an attribute to the schema, without a space between an extension and the
+ * right paren.
+ *
+ * @throws Exception
+ */
+ @Test
+ public final void testSchemaBuilderAttributeExtensionWithoutSpace() throws Exception {
+ // @formatter:off
+ final String[] strEntry = {
+ "dn: cn=schema",
+ "objectClass: top",
+ "objectClass: ldapSubentry",
+ "objectClass: subschema",
+ "cn: schema",
+ "attributeTypes: ( foo-oid NAME 'foo' SUP name DESC 'No trailing space' X-SCHEMA-FILE '99-test.ldif')"
+ };
+ // @formatter:on
+ final Entry e = new LinkedHashMapEntry(strEntry);
+ final SchemaBuilder builder = new SchemaBuilder();
+ builder.addSchema(Schema.getCoreSchema(), false);
+ builder.addSchema(e, true);
+
+ assertThat(e.getAttribute(Schema.ATTR_LDAP_SYNTAXES)).isNull();
+ assertThat(e.getAttribute(Schema.ATTR_ATTRIBUTE_TYPES)).isNotNull();
+ assertThat(e.getAttribute(Schema.ATTR_OBJECT_CLASSES)).isNull();
+ assertThat(e.getAttribute(Schema.ATTR_MATCHING_RULE_USE)).isNull();
+ assertThat(e.getAttribute(Schema.ATTR_MATCHING_RULES)).isNull();
+ assertThat(e.getAttribute(Schema.ATTR_DIT_CONTENT_RULES)).isNull();
+ assertThat(e.getAttribute(Schema.ATTR_DIT_STRUCTURE_RULES)).isNull();
+ assertThat(e.getAttribute(Schema.ATTR_NAME_FORMS)).isNull();
+
+ Schema schema = builder.toSchema();
+ // No warnings
+ assertThat(schema.getWarnings()).isEmpty();
+ assertThat(schema.getAttributeType("foo").getDescription()).isEqualTo("No trailing space");
+ }
+
+ /**
* Adds a ldapsyntax to the schema. Ldapsyntaxes define allowable values can
* be used for an attribute.
*
--
Gitblit v1.10.0