From 52a86894ee297d4906ffc4498a2de0e6e2dd8694 Mon Sep 17 00:00:00 2001
From: Nicolas Capponi <nicolas.capponi@forgerock.com>
Date: Fri, 22 May 2015 09:47:49 +0000
Subject: [PATCH] OPENDJ-1631 CR-6864 Fix LDAPSyntaxDescriptionSyntax bug and improve syntaxes tests
---
opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/TelephoneNumberSyntaxTest.java | 64 ++++++++
opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/TelexSyntaxTest.java | 8
opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/AbstractSyntaxTestCase.java | 11 -
opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/CountryStringSyntaxTest.java | 4
opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/OtherMailboxSyntaxTest.java | 2
opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/CertificateSyntaxTest.java | 11 -
opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/AttributeTypeSyntaxTest.java | 39 ++++
opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/JPEGSyntaxTest.java | 132 ++++++++++++++++
opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/MatchingRuleUseSyntaxTest.java | 2
opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/UUIDSyntaxTest.java | 2
opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/LDAPSyntaxTest.java | 15 +
opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/BitStringSyntaxTest.java | 11 +
opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/SchemaBuilderTestCase.java | 16 ++
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/LDAPSyntaxDescriptionSyntaxImpl.java | 2
opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/IntegerSyntaxTest.java | 62 +++++++
opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/MatchingRuleSyntaxTest.java | 2
opendj-core/src/test/java/org/forgerock/opendj/ldap/GeneralizedTimeTest.java | 76 +++++++++
17 files changed, 420 insertions(+), 39 deletions(-)
diff --git a/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/LDAPSyntaxDescriptionSyntaxImpl.java b/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/LDAPSyntaxDescriptionSyntaxImpl.java
index ee6d62a..8cd3023 100644
--- a/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/LDAPSyntaxDescriptionSyntaxImpl.java
+++ b/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/LDAPSyntaxDescriptionSyntaxImpl.java
@@ -143,7 +143,7 @@
if (values.hasNext()) {
final String pattern = values.next();
try {
- Pattern.compile(values.next());
+ Pattern.compile(pattern);
} catch (final Exception e) {
throwDecodeException(logger,
WARN_ATTR_SYNTAX_LDAPSYNTAX_REGEX_INVALID_PATTERN.get(oid, pattern));
diff --git a/opendj-core/src/test/java/org/forgerock/opendj/ldap/GeneralizedTimeTest.java b/opendj-core/src/test/java/org/forgerock/opendj/ldap/GeneralizedTimeTest.java
index a08aeef..4a429ee 100644
--- a/opendj-core/src/test/java/org/forgerock/opendj/ldap/GeneralizedTimeTest.java
+++ b/opendj-core/src/test/java/org/forgerock/opendj/ldap/GeneralizedTimeTest.java
@@ -26,7 +26,7 @@
*/
package org.forgerock.opendj.ldap;
-import static org.fest.assertions.Assertions.assertThat;
+import static org.fest.assertions.Assertions.*;
import java.util.Calendar;
import java.util.Date;
@@ -71,7 +71,7 @@
@DataProvider
public Object[][] invalidStrings() {
- return new Object[][] { { "20060906135030+3359" }, { "20060906135030+2389" },
+ return new Object[][] { {"20060906135030+3359" }, { "20060906135030+2389" },
{ "20060906135030+2361" }, { "20060906135030+" }, { "20060906135030+0" },
{ "20060906135030+010" }, { "20061200235959Z" }, { "2006121a235959Z" },
{ "2006122a235959Z" }, { "20060031235959Z" }, { "20061331235959Z" },
@@ -158,4 +158,76 @@
{ "20061231235959Z" }, { "20060906135030+0101" }, { "20060906135030+2359" }, };
}
+ /**
+ * Create data for toString test.
+ *
+ * @return Returns test data.
+ */
+ @DataProvider()
+ public Object[][] createToStringData()
+ {
+ return new Object [][] {
+ // Note that Calendar months run from 0-11,
+ // and that there was no such year as year 0 (1 BC -> 1 AD).
+ { 1, 0, 1, 0, 0, 0, 0, "00010101000000Z"},
+ { 9, 0, 1, 0, 0, 0, 0, "00090101000000Z"},
+ { 10, 0, 1, 0, 0, 0, 0, "00100101000000Z"},
+ { 99, 0, 1, 0, 0, 0, 0, "00990101000000Z"},
+ { 100, 0, 1, 0, 0, 0, 0, "01000101000000Z"},
+ { 999, 0, 1, 0, 0, 0, 0, "09990101000000Z"},
+ {1000, 0, 1, 0, 0, 0, 0, "10000101000000Z"},
+ {2000, 0, 1, 0, 0, 0, 0, "20000101000000Z"},
+ {2099, 0, 1, 0, 0, 0, 0, "20990101000000Z"},
+ {2000, 8, 1, 0, 0, 0, 0, "20000901000000Z"},
+ {2000, 9, 1, 0, 0, 0, 0, "20001001000000Z"},
+ {2000, 10, 1, 0, 0, 0, 0, "20001101000000Z"},
+ {2000, 11, 1, 0, 0, 0, 0, "20001201000000Z"},
+ {2000, 0, 9, 0, 0, 0, 0, "20000109000000Z"},
+ {2000, 0, 10, 0, 0, 0, 0, "20000110000000Z"},
+ {2000, 0, 19, 0, 0, 0, 0, "20000119000000Z"},
+ {2000, 0, 20, 0, 0, 0, 0, "20000120000000Z"},
+ {2000, 0, 29, 0, 0, 0, 0, "20000129000000Z"},
+ {2000, 0, 30, 0, 0, 0, 0, "20000130000000Z"},
+ {2000, 0, 31, 0, 0, 0, 0, "20000131000000Z"},
+ {2000, 0, 1, 9, 0, 0, 0, "20000101090000Z"},
+ {2000, 0, 1, 10, 0, 0, 0, "20000101100000Z"},
+ {2000, 0, 1, 19, 0, 0, 0, "20000101190000Z"},
+ {2000, 0, 1, 20, 0, 0, 0, "20000101200000Z"},
+ {2000, 0, 1, 23, 0, 0, 0, "20000101230000Z"},
+ {2000, 0, 1, 0, 9, 0, 0, "20000101000900Z"},
+ {2000, 0, 1, 0, 10, 0, 0, "20000101001000Z"},
+ {2000, 0, 1, 0, 59, 0, 0, "20000101005900Z"},
+ {2000, 0, 1, 0, 0, 9, 0, "20000101000009Z"},
+ {2000, 0, 1, 0, 0, 10, 0, "20000101000010Z"},
+ {2000, 0, 1, 0, 0, 59, 0, "20000101000059Z"},
+ {2000, 0, 1, 0, 0, 0, 9, "20000101000000.009Z"},
+ {2000, 0, 1, 0, 0, 0, 10, "20000101000000.010Z"},
+ {2000, 0, 1, 0, 0, 0, 99, "20000101000000.099Z"},
+ {2000, 0, 1, 0, 0, 0, 100, "20000101000000.100Z"},
+ {2000, 0, 1, 0, 0, 0, 999, "20000101000000.999Z"},
+ };
+ }
+
+ private static final String TIME_ZONE_UTC = "UTC";
+
+
+ @Test(dataProvider="createToStringData")
+ public void testToString(int yyyy, int MM, int dd, int HH, int mm, int ss, int SSS, String expected)
+ throws Exception
+ {
+ Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone(TIME_ZONE_UTC));
+ calendar.set(yyyy, MM, dd, HH, mm, ss);
+ calendar.set(Calendar.MILLISECOND, SSS);
+
+ long time = calendar.getTimeInMillis();
+ // test creation with long only if it is positive because negative values will be rejected
+ if (time > 0)
+ {
+ assertThat(GeneralizedTime.valueOf(time).toString()).isEqualTo(expected);
+ }
+
+ Date date = new Date(time);
+ assertThat(GeneralizedTime.valueOf(date).toString()).isEqualTo(expected);
+ }
+
}
diff --git a/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/AbstractSyntaxTestCase.java b/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/AbstractSyntaxTestCase.java
index f77cbe8..41215d3 100644
--- a/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/AbstractSyntaxTestCase.java
+++ b/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/AbstractSyntaxTestCase.java
@@ -64,17 +64,6 @@
if (!liveResult.equals(result)) {
fail(syntax + ".valueIsAcceptable gave bad result for " + value + "reason : " + reason);
}
-
- // call the getters
- syntax.getApproximateMatchingRule();
- syntax.getDescription();
- syntax.getEqualityMatchingRule();
- syntax.getOID();
- syntax.getOrderingMatchingRule();
- syntax.getSubstringMatchingRule();
- syntax.hashCode();
- syntax.isHumanReadable();
- syntax.toString();
}
/**
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 f61728e..834d4ba 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
@@ -29,10 +29,12 @@
import static org.forgerock.opendj.ldap.schema.SchemaConstants.SYNTAX_ATTRIBUTE_TYPE_OID;
import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
/**
* Attribute type syntax tests.
*/
+@Test
public class AttributeTypeSyntaxTest extends AbstractSyntaxTestCase {
/** {@inheritDoc} */
@Override
@@ -52,8 +54,38 @@
+ " X-APPROX 'equalLengthApproximateMatch'"
+ " SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 SINGLE-VALUE"
+ " COLLECTIVE USAGE userApplications )", true },
- { "(1.2.8.5 NAME 'testtype' DESC 'full type')", true },
- { "(1.2.8.5 USAGE directoryOperation )", true },
+ {
+ "(1.2.8.5 NAME 'testtype' DESC 'full type')", true },
+ {
+ "(1.2.8.5 NAME 'testType' DESC 'full type' EQUALITY caseIgnoreMatch "
+ + " SYNTAX 1.3.6.1.4.1.1466.115.121.1.15)", true},
+ {
+ "(1.2.8.5 NAME 'testType' DESC 'full type' EQUALITY caseIgnoreMatch "
+ + " SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 X-ORIGIN 'test' )", true},
+ { "(1.2.8.5 NAME 'testType' DESC 'full type' EQUALITY caseIgnoreMatch "
+ + " SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 X-ORIGIN 'test' "
+ + " X-SCHEMA-FILE '33-test.ldif' )", true},
+ {
+ "(1.2.8.5 USAGE directoryOperation )", true },
+
+ // Collective can inherit from non-collective
+ { "(1.2.8.5 NAME 'testtype' DESC 'full type' OBSOLETE SUP cn "
+ + " EQUALITY caseIgnoreMatch ORDERING caseIgnoreOrderingMatch"
+ + " SUBSTR caseIgnoreSubstringsMatch"
+ + " SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 SINGLE-VALUE"
+ + " COLLECTIVE USAGE userApplications )", true},
+ // Collective can be operational
+ { "(1.2.8.5 NAME 'testtype' DESC 'full type' OBSOLETE "
+ + " EQUALITY caseIgnoreMatch ORDERING caseIgnoreOrderingMatch"
+ + " SUBSTR caseIgnoreSubstringsMatch"
+ + " SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 SINGLE-VALUE"
+ + " COLLECTIVE USAGE directoryOperation )", true},
+
+ // X-NAME is invalid extension (no value)
+ { "(1.2.8.5 NAME 'testType' DESC 'full type' EQUALITY caseIgnoreMatch "
+ + " SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 X-ORIGIN 'test' "
+ + " X-SCHEMA-FILE '33-test.ldif' X-NAME )", false},
+
{
"(1.2.8.5 NAME 'testtype' DESC 'full type' OBSOLETE SUP cn "
+ " EQUALITY caseIgnoreMatch ORDERING caseIgnoreOrderingMatch"
@@ -72,6 +104,8 @@
+ " SUBSTR caseIgnoreSubstringsMatch"
+ " SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 SINGLE-VALUE"
+ " BADTOKEN USAGE directoryOperation )", false },
+
+ // NO-USER-MODIFICATION can't have non-operational usage
{
"1.2.8.5 NAME 'testtype' DESC 'full type' OBSOLETE "
+ " EQUALITY caseIgnoreMatch ORDERING caseIgnoreOrderingMatch"
@@ -85,4 +119,5 @@
protected Syntax getRule() {
return Schema.getCoreSchema().getSyntax(SYNTAX_ATTRIBUTE_TYPE_OID);
}
+
}
diff --git a/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/BitStringSyntaxTest.java b/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/BitStringSyntaxTest.java
index ef31632..c78ce52 100644
--- a/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/BitStringSyntaxTest.java
+++ b/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/BitStringSyntaxTest.java
@@ -29,17 +29,24 @@
import static org.forgerock.opendj.ldap.schema.SchemaConstants.SYNTAX_BIT_STRING_OID;
import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
/**
* Bit string syntax tests.
*/
+@Test
public class BitStringSyntaxTest extends AbstractSyntaxTestCase {
/** {@inheritDoc} */
@Override
@DataProvider(name = "acceptableValues")
public Object[][] createAcceptableValues() {
- return new Object[][] { { "'0101'B", true }, { "'1'B", true }, { "'0'B", true },
- { "invalid", false }, { "1", false }, { "'010100000111111010101000'B", true }, };
+ return new Object[][] {
+ { "'0101'B", true },
+ { "'1'B", true },
+ { "'0'B", true },
+ { "invalid", false },
+ { "1", false },
+ { "'010100000111111010101000'B", true }, };
}
/** {@inheritDoc} */
diff --git a/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/CertificateSyntaxTest.java b/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/CertificateSyntaxTest.java
index eb65273..60008fa 100644
--- a/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/CertificateSyntaxTest.java
+++ b/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/CertificateSyntaxTest.java
@@ -117,16 +117,6 @@
assertEquals(liveResult, result,
syntax + ".valueIsAcceptable gave bad result for " + value + "reason : " + reason);
- // call the getters
- syntax.getApproximateMatchingRule();
- syntax.getDescription();
- syntax.getEqualityMatchingRule();
- syntax.getOID();
- syntax.getOrderingMatchingRule();
- syntax.getSubstringMatchingRule();
- syntax.hashCode();
- syntax.isHumanReadable();
- syntax.toString();
}
/**
@@ -139,7 +129,6 @@
*/
@Test(dataProvider = "acceptableValues")
public void testAllowMalformedCertificates(ByteString value, Boolean result) {
- // Make sure that the specified class can be instantiated as a task.
SchemaBuilder builder = new SchemaBuilder(getCoreSchema()).setOption(ALLOW_MALFORMED_CERTIFICATES, true);
final Syntax syntax = builder.toSchema().getSyntax(SYNTAX_CERTIFICATE_OID);
diff --git a/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/CountryStringSyntaxTest.java b/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/CountryStringSyntaxTest.java
index 9df00f7..0a009d1 100644
--- a/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/CountryStringSyntaxTest.java
+++ b/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/CountryStringSyntaxTest.java
@@ -31,10 +31,12 @@
import static org.forgerock.opendj.ldap.schema.SchemaConstants.SYNTAX_COUNTRY_STRING_OID;
import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
/**
* Country String syntax tests.
*/
+@Test
public class CountryStringSyntaxTest extends AbstractSyntaxTestCase {
@Override
@DataProvider(name = "acceptableValues")
@@ -47,7 +49,7 @@
{ "12", false },
{ "UK", true },
{ "Xf", false },
- { "ÖÄ", false },
+ { "ÖÄ", false }, // "\u00D6\u00C4"
};
}
diff --git a/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/IntegerSyntaxTest.java b/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/IntegerSyntaxTest.java
new file mode 100644
index 0000000..b3f347f
--- /dev/null
+++ b/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/IntegerSyntaxTest.java
@@ -0,0 +1,62 @@
+/*
+ * 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 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 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 2009 Sun Microsystems, Inc.
+ * Portions copyright 2014 ForgeRock AS.
+ */
+package org.forgerock.opendj.ldap.schema;
+
+import static org.forgerock.opendj.ldap.schema.SchemaConstants.SYNTAX_INTEGER_OID;
+
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+/**
+ * Integer syntax tests.
+ */
+@Test
+public class IntegerSyntaxTest extends AbstractSyntaxTestCase {
+ /** {@inheritDoc} */
+ @Override
+ @DataProvider(name = "acceptableValues")
+ public Object[][] createAcceptableValues() {
+ return new Object [][] {
+ {"123", true},
+ {"987654321", true},
+ {"-1", true},
+ {"10001", true},
+ {"001", false},
+ {"-01", false},
+ {"12345678\u2163", false},
+ {" 123", false},
+ {"123 ", false}
+ };
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ protected Syntax getRule() {
+ return Schema.getCoreSchema().getSyntax(SYNTAX_INTEGER_OID);
+ }
+
+}
diff --git a/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/JPEGSyntaxTest.java b/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/JPEGSyntaxTest.java
new file mode 100644
index 0000000..ab3579f
--- /dev/null
+++ b/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/JPEGSyntaxTest.java
@@ -0,0 +1,132 @@
+/*
+ * 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 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 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 2009 Sun Microsystems, Inc.
+ * Portions copyright 2014-2015 ForgeRock AS.
+ */
+package org.forgerock.opendj.ldap.schema;
+
+import static org.forgerock.opendj.ldap.schema.Schema.*;
+import static org.forgerock.opendj.ldap.schema.SchemaConstants.*;
+import static org.forgerock.opendj.ldap.schema.SchemaOptions.*;
+import static org.testng.Assert.*;
+
+import org.forgerock.i18n.LocalizableMessageBuilder;
+import org.forgerock.opendj.ldap.ByteString;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+/**
+ * JPEG syntax tests.
+ */
+@SuppressWarnings("javadoc")
+@Test
+public class JPEGSyntaxTest extends AbstractSchemaTestCase {
+
+ @DataProvider(name = "acceptableValues")
+ public Object[][] createAcceptableValues() {
+ String non_image =
+ "AAECAwQFBgcICQ==";
+ String jfif_image =
+ "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDACMYGh4aFiMeHB4nJSMpNFc4NDAwNGpM" +
+ "UD9Xfm+EgnxveneLnMipi5S9lnd6ru2wvc7V4OLgh6f1//PZ/8jb4Nf/2wBDASUn" +
+ "JzQuNGY4OGbXj3qP19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX" +
+ "19fX19fX19fX19fX19f/wAARCAABAAEDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEA" +
+ "AAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIh" +
+ "MUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6" +
+ "Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZ" +
+ "mqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx" +
+ "8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREA" +
+ "AgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAV" +
+ "YnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hp" +
+ "anN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPE" +
+ "xcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwCC" +
+ "iiiuM9g//9k=";
+ String exif_image =
+ "/9j/4QD2RXhpZgAATU0AKgAAAAgACQESAAMAAAABAAEAAAEaAAUAAAABAAAAegEb" +
+ "AAUAAAABAAAAggEoAAMAAAABAAIAAAExAAIAAAAQAAAAigEyAAIAAAAUAAAAmgE8" +
+ "AAIAAAAOAAAArgITAAMAAAABAAEAAIdpAAQAAAABAAAAvAAAAAAASAAAAAEAAABI" +
+ "AAAAAQAAUXVpY2tUaW1lIDcuNy4xADIwMTI6MDg6MjAgMTI6MTE6MTIATWFjIE9T" +
+ "IFggMTAuOAAAApAAAAcAAAAEMDIyMJADAAIAAAAUAAAA2gAAAAAyMDEyOjA4OjIw" +
+ "IDEyOjEwOjA2AP/+AAxBcHBsZU1hcmsK/9sAQwAjGBoeGhYjHhweJyUjKTRXODQw" +
+ "MDRqTFA/V35vhIJ8b3p3i5zIqYuUvZZ3eq7tsL3O1eDi4Ien9f/z2f/I2+DX/9sA" +
+ "QwElJyc0LjRmODhm1496j9fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX" +
+ "19fX19fX19fX19fX19fX19fX/8AAEQgAAQABAwEiAAIRAQMRAf/EAB8AAAEFAQEB" +
+ "AQEBAAAAAAAAAAABAgMEBQYHCAkKC//EALUQAAIBAwMCBAMFBQQEAAABfQECAwAE" +
+ "EQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJChYXGBkaJSYnKCkqNDU2" +
+ "Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6g4SFhoeIiYqSk5SV" +
+ "lpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2drh4uPk5ebn" +
+ "6Onq8fLz9PX29/j5+v/EAB8BAAMBAQEBAQEBAQEAAAAAAAABAgMEBQYHCAkKC//E" +
+ "ALURAAIBAgQEAwQHBQQEAAECdwABAgMRBAUhMQYSQVEHYXETIjKBCBRCkaGxwQkj" +
+ "M1LwFWJy0QoWJDThJfEXGBkaJicoKSo1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2Rl" +
+ "ZmdoaWpzdHV2d3h5eoKDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5" +
+ "usLDxMXGx8jJytLT1NXW19jZ2uLj5OXm5+jp6vLz9PX29/j5+v/aAAwDAQACEQMR" +
+ "AD8AgooorjPYP//Z";
+ String png_image =
+ "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAMAAAAoyzS7AAAABlBMVEX/JgAAAAAP" +
+ "IsinAAAACklEQVQImWNgAAAAAgAB9HFkpgAAAABJRU5ErkJggg==";
+
+ try
+ {
+ return new Object[][] {
+ { ByteString.valueOfBase64(non_image), false },
+ { ByteString.valueOfBase64(jfif_image), true },
+ { ByteString.valueOfBase64(exif_image), true },
+ { ByteString.valueOfBase64(png_image), false } };
+ }
+ catch (Exception e)
+ {
+ return new Object[][] {};
+ }
+ }
+
+ /** Test acceptable values for this syntax when not allowing malformed JPEG photos. */
+ @Test(dataProvider = "acceptableValues")
+ public void testAcceptableValues(ByteString value, boolean expectedResult) {
+ final Syntax syntax = getSyntax(false);
+ final LocalizableMessageBuilder reason = new LocalizableMessageBuilder();
+
+ final boolean result = syntax.valueIsAcceptable(value, reason);
+ assertEquals(result, expectedResult,
+ syntax + ".valueIsAcceptable gave bad result for " + value + "reason : " + reason);
+
+ }
+
+ /** Test acceptable values for this syntax when allowing malformed JPEG photos. */
+ @Test(dataProvider = "acceptableValues")
+ public void testAcceptableValuesWhenAllowingMalformedJPEG(ByteString value, boolean notUsedForThisTest) {
+ final Syntax syntax = getSyntax(true);
+ final LocalizableMessageBuilder reason = new LocalizableMessageBuilder();
+
+ final boolean liveResult = syntax.valueIsAcceptable(value, reason);
+ // should always be true
+ assertTrue(liveResult, syntax + ".valueIsAcceptable gave bad result for " + value + "reason : " + reason);
+ }
+
+ private Syntax getSyntax(boolean allowMalformedJpegPhotos) {
+ SchemaBuilder builder =
+ new SchemaBuilder(getCoreSchema()).setOption(ALLOW_MALFORMED_JPEG_PHOTOS, allowMalformedJpegPhotos);
+ return builder.toSchema().getSyntax(SYNTAX_JPEG_OID);
+ }
+
+}
diff --git a/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/LDAPSyntaxTest.java b/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/LDAPSyntaxTest.java
index e5050ba..d80d1fe 100644
--- a/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/LDAPSyntaxTest.java
+++ b/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/LDAPSyntaxTest.java
@@ -29,18 +29,19 @@
import static org.forgerock.opendj.ldap.schema.SchemaConstants.SYNTAX_LDAP_SYNTAX_OID;
import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
/**
* LDAP syntax tests.
*/
+@Test
public class LDAPSyntaxTest extends AbstractSyntaxTestCase {
/** {@inheritDoc} */
@Override
@DataProvider(name = "acceptableValues")
public Object[][] createAcceptableValues() {
return new Object[][] {
- { "( 2.5.4.3 DESC 'full syntax description' " + "X-9EN ('this' 'is' 'a' 'test'))",
- false },
+ { "( 2.5.4.3 DESC 'full syntax description' " + "X-9EN ('this' 'is' 'a' 'test'))", false },
{ "( 2.5.4.3 DESC 'full syntax description' " + "(X-name 'this", false },
{ "( 2.5.4.3 DESC 'full syntax description' " + "(X-name 'this'", false },
{ "( 2.5.4.3 DESC 'full syntax description' " + "Y-name 'this')", false },
@@ -66,10 +67,8 @@
+ "X-name ('this' 'is' 'a' 'test') X-name-a 'X-name-b' ('this'))))", false },
{
"( 2.5.4.3 DESC 'full syntax description' "
- + "X-name ('this' 'is' 'a' 'test') X-name-a 'this' X-name-b ('this'))",
- true },
- { "( 2.5.4.3 DESC 'full syntax description' " + "X-a-_eN_- ('this' 'is' 'a' 'test'))",
- true },
+ + "X-name ('this' 'is' 'a' 'test') X-name-a 'this' X-name-b ('this'))", true },
+ { "( 2.5.4.3 DESC 'full syntax description' " + "X-a-_eN_- ('this' 'is' 'a' 'test'))", true },
{ "( 2.5.4.3 DESC 'full syntax description' " + "X-name ('this'))", true },
{ "( 2.5.4.3 DESC 'full syntax description' " + "X-name 'this')", true },
{ "( 2.5.4.3 DESC 'full syntax description' " + "X-name 'this' X-name-a 'test')", true },
@@ -79,7 +78,9 @@
{ "($%^*&!@ DESC 'syntax description' )", false },
{ "(temp-oid DESC 'syntax description' )", true },
{ "2.5.4.3 DESC 'syntax description' )", false },
- { "(2.5.4.3 DESC 'syntax description' ", false }, };
+ { "(2.5.4.3 DESC 'syntax description' ", false },
+ { "( 1.1.1 DESC 'Host and Port in the format of HOST:PORT' X-PATTERN '^[a-z-A-Z]+:[0-9.]+\\d$' )", true },
+ };
}
/** {@inheritDoc} */
diff --git a/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/MatchingRuleSyntaxTest.java b/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/MatchingRuleSyntaxTest.java
index 74d0356..18dc614 100644
--- a/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/MatchingRuleSyntaxTest.java
+++ b/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/MatchingRuleSyntaxTest.java
@@ -29,10 +29,12 @@
import static org.forgerock.opendj.ldap.schema.SchemaConstants.SYNTAX_MATCHING_RULE_OID;
import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
/**
* Matching rule syntax tests.
*/
+@Test
public class MatchingRuleSyntaxTest extends AbstractSyntaxTestCase {
/** {@inheritDoc} */
@Override
diff --git a/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/MatchingRuleUseSyntaxTest.java b/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/MatchingRuleUseSyntaxTest.java
index d9838dc..3941554 100644
--- a/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/MatchingRuleUseSyntaxTest.java
+++ b/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/MatchingRuleUseSyntaxTest.java
@@ -29,10 +29,12 @@
import static org.forgerock.opendj.ldap.schema.SchemaConstants.SYNTAX_MATCHING_RULE_USE_OID;
import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
/**
* Matching rule use syntax tests.
*/
+@Test
public class MatchingRuleUseSyntaxTest extends AbstractSyntaxTestCase {
/** {@inheritDoc} */
@Override
diff --git a/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/OtherMailboxSyntaxTest.java b/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/OtherMailboxSyntaxTest.java
index 9d2b659..dffd714 100644
--- a/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/OtherMailboxSyntaxTest.java
+++ b/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/OtherMailboxSyntaxTest.java
@@ -29,10 +29,12 @@
import static org.forgerock.opendj.ldap.schema.SchemaConstants.SYNTAX_OTHER_MAILBOX_OID;
import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
/**
* Other mailbox syntax tests.
*/
+@Test
public class OtherMailboxSyntaxTest extends AbstractSyntaxTestCase {
/** {@inheritDoc} */
@Override
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 0ea5e44..2e9cf55 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
@@ -1194,6 +1194,22 @@
false);
}
+ @Test
+ public final void testSchemaBuilderWithAttributeUsageDifferentFromSuperior() {
+ final SchemaBuilder scBuild = new SchemaBuilder();
+
+ // directoryOperation can't inherit from userApplications
+ scBuild.addAttributeType("(1.2.8.5 NAME 'testtype' DESC 'full type' OBSOLETE SUP cn "
+ + " EQUALITY caseIgnoreMatch ORDERING caseIgnoreOrderingMatch"
+ + " SUBSTR caseIgnoreSubstringsMatch"
+ + " SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 SINGLE-VALUE"
+ + " NO-USER-MODIFICATION USAGE directoryOperation )", true);
+ scBuild.addSchema(Schema.getCoreSchema(), false);
+ Schema schema = scBuild.toSchema();
+ assertThat(schema.getWarnings()).hasSize(1);
+ assertThat(schema.getWarnings().toString()).contains("attribute usage directoryOperation is not the same");
+ }
+
/**
* The builder allows to have twin or more attributes if it can overwrite
* them. Only the last is kept. Attributes may have same OID and name.
diff --git a/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/TelephoneNumberSyntaxTest.java b/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/TelephoneNumberSyntaxTest.java
new file mode 100644
index 0000000..6eedd09
--- /dev/null
+++ b/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/TelephoneNumberSyntaxTest.java
@@ -0,0 +1,64 @@
+/*
+ * 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 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 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 2015 ForgeRock AS.
+ */
+package org.forgerock.opendj.ldap.schema;
+
+import static org.forgerock.opendj.ldap.schema.Schema.*;
+import static org.forgerock.opendj.ldap.schema.SchemaConstants.*;
+import static org.forgerock.opendj.ldap.schema.SchemaOptions.*;
+
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+/**
+ * Telephone number syntax tests.
+ */
+@Test
+public class TelephoneNumberSyntaxTest extends AbstractSyntaxTestCase {
+ /** {@inheritDoc} */
+ @Override
+ @DataProvider(name = "acceptableValues")
+ public Object[][] createAcceptableValues() {
+ return new Object[][] {
+ { "+61 3 9896 7830", true},
+ { "+1 512 315 0280", true},
+ { "+1-512-315-0280", true},
+ { "3 9896 7830", false},
+ { "+1+512 315 0280", false},
+ { "+1x512x315x0280", false},
+ { " ", false},
+ { "", false}
+ };
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ protected Syntax getRule()
+ {
+ SchemaBuilder builder = new SchemaBuilder(getCoreSchema()).setOption(ALLOW_NON_STANDARD_TELEPHONE_NUMBERS, false);
+ return builder.toSchema().getSyntax(SYNTAX_TELEPHONE_OID);
+ }
+
+}
diff --git a/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/TelexSyntaxTest.java b/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/TelexSyntaxTest.java
index fa35935..51f3e4c 100644
--- a/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/TelexSyntaxTest.java
+++ b/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/TelexSyntaxTest.java
@@ -29,17 +29,21 @@
import static org.forgerock.opendj.ldap.schema.SchemaConstants.SYNTAX_TELEX_OID;
import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
/**
* Telex syntax tests.
*/
+@Test
public class TelexSyntaxTest extends AbstractSyntaxTestCase {
/** {@inheritDoc} */
@Override
@DataProvider(name = "acceptableValues")
public Object[][] createAcceptableValues() {
- return new Object[][] { { "123$france$456", true },
- { "abcdefghijk$lmnopqr$stuvwxyz", true }, { "12345$67890$()+,-./:? ", true }, };
+ return new Object[][] {
+ { "123$france$456", true },
+ { "abcdefghijk$lmnopqr$stuvwxyz", true },
+ { "12345$67890$()+,-./:? ", true }, };
}
/** {@inheritDoc} */
diff --git a/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/UUIDSyntaxTest.java b/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/UUIDSyntaxTest.java
index 8fb10a1..fe8e476 100644
--- a/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/UUIDSyntaxTest.java
+++ b/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/UUIDSyntaxTest.java
@@ -29,10 +29,12 @@
import static org.forgerock.opendj.ldap.schema.SchemaConstants.SYNTAX_UUID_OID;
import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
/**
* UUID syntax tests.
*/
+@Test
public class UUIDSyntaxTest extends AbstractSyntaxTestCase {
/** {@inheritDoc} */
@Override
--
Gitblit v1.10.0