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

Chris Ridd
13.27.2012 79987f6aa07a0beaae43f0fb08e20fe21be23016
Fix OPENDJ-562 Country String syntax should validate ISO 3166 codes

Thanks to Manuel Gaupp for this contribution!
1 files added
9 files modified
87 ■■■■ changed files
opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/schema/CountryStringSyntaxImpl.java 15 ●●●● patch | view | raw | blame | history
opendj3/opendj-ldap-sdk/src/main/resources/org/forgerock/opendj/ldap/core.properties 5 ●●●●● patch | view | raw | blame | history
opendj3/opendj-ldap-sdk/src/main/resources/org/forgerock/opendj/ldap/core_de.properties 1 ●●●● patch | view | raw | blame | history
opendj3/opendj-ldap-sdk/src/main/resources/org/forgerock/opendj/ldap/core_es.properties 1 ●●●● patch | view | raw | blame | history
opendj3/opendj-ldap-sdk/src/main/resources/org/forgerock/opendj/ldap/core_fr.properties 1 ●●●● patch | view | raw | blame | history
opendj3/opendj-ldap-sdk/src/main/resources/org/forgerock/opendj/ldap/core_ja.properties 1 ●●●● patch | view | raw | blame | history
opendj3/opendj-ldap-sdk/src/main/resources/org/forgerock/opendj/ldap/core_ko.properties 1 ●●●● patch | view | raw | blame | history
opendj3/opendj-ldap-sdk/src/main/resources/org/forgerock/opendj/ldap/core_zh_CN.properties 1 ●●●● patch | view | raw | blame | history
opendj3/opendj-ldap-sdk/src/main/resources/org/forgerock/opendj/ldap/core_zh_TW.properties 1 ●●●● patch | view | raw | blame | history
opendj3/opendj-ldap-sdk/src/test/java/org/forgerock/opendj/ldap/schema/CountryStringSyntaxTest.java 60 ●●●●● patch | view | raw | blame | history
opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/schema/CountryStringSyntaxImpl.java
@@ -22,13 +22,13 @@
 *
 *
 *      Copyright 2009 Sun Microsystems, Inc.
 *      Portions Copyright 2012 Manuel Gaupp
 */
package org.forgerock.opendj.ldap.schema;
import static com.forgerock.opendj.util.StaticUtils.toLowerCase;
import static org.forgerock.opendj.ldap.CoreMessages.ERR_ATTR_SYNTAX_COUNTRY_STRING_INVALID_LENGTH;
import static org.forgerock.opendj.ldap.CoreMessages.ERR_ATTR_SYNTAX_COUNTRY_STRING_NOT_PRINTABLE;
import static org.forgerock.opendj.ldap.CoreMessages.ERR_ATTR_SYNTAX_COUNTRY_STRING_NO_VALID_ISO_CODE;
import static org.forgerock.opendj.ldap.schema.SchemaConstants.*;
import org.forgerock.i18n.LocalizableMessageBuilder;
@@ -37,7 +37,7 @@
/**
 * This class defines the country string attribute syntax, which should be a
 * two-character ISO 3166 country code. However, for maintainability, it will
 * accept any value consisting entirely of two printable characters. In most
 * accept any value consisting entirely of two upper-case characters. In most
 * ways, it will behave like the directory string attribute syntax.
 */
final class CountryStringSyntaxImpl extends AbstractSyntaxImpl {
@@ -86,15 +86,16 @@
     */
    public boolean valueIsAcceptable(final Schema schema, final ByteSequence value,
            final LocalizableMessageBuilder invalidReason) {
        final String stringValue = toLowerCase(value.toString());
        final String stringValue = value.toString();
        if (stringValue.length() != 2) {
            invalidReason.append(ERR_ATTR_SYNTAX_COUNTRY_STRING_INVALID_LENGTH.get(stringValue));
            return false;
        }
        if (!PrintableStringSyntaxImpl.isPrintableCharacter(stringValue.charAt(0))
                || !PrintableStringSyntaxImpl.isPrintableCharacter(stringValue.charAt(1))) {
            invalidReason.append(ERR_ATTR_SYNTAX_COUNTRY_STRING_NOT_PRINTABLE.get(stringValue));
        // Check for a string containing [A-Z][A-Z]
        if (stringValue.charAt(0) < 'A' || stringValue.charAt(0) > 'Z'
            || stringValue.charAt(1) < 'A' || stringValue.charAt(1) > 'Z') {
            invalidReason.append(ERR_ATTR_SYNTAX_COUNTRY_STRING_NO_VALID_ISO_CODE.get(stringValue));
            return false;
        }
opendj3/opendj-ldap-sdk/src/main/resources/org/forgerock/opendj/ldap/core.properties
@@ -53,9 +53,8 @@
 not a valid bit string because '%s' is not a valid binary digit
ERR_ATTR_SYNTAX_COUNTRY_STRING_INVALID_LENGTH=The provided value "%s" \
 is not a valid country string because the length is not exactly two characters
ERR_ATTR_SYNTAX_COUNTRY_STRING_NOT_PRINTABLE=The provided value "%s" \
 is not a valid country string because it contains one or more non-printable \
 characters
ERR_ATTR_SYNTAX_COUNTRY_STRING_NO_VALID_ISO_CODE=The provided value "%s" \
 is not a valid ISO 3166 country code
ERR_ATTR_SYNTAX_DELIVERY_METHOD_NO_ELEMENTS=The provided value "%s" is \
 not a valid delivery method value because it does not contain any elements
ERR_ATTR_SYNTAX_DELIVERY_METHOD_INVALID_ELEMENT=The provided value \
opendj3/opendj-ldap-sdk/src/main/resources/org/forgerock/opendj/ldap/core_de.properties
@@ -23,7 +23,6 @@
#
ERR_ATTR_SYNTAX_COUNTRY_STRING_INVALID_LENGTH_9=Der angegebene Wert "%s" ist keine g\u00fcltige L\u00e4nderzeichenkette, da die L\u00e4nge nicht exakt zwei Zeichen betr\u00e4gt
ERR_ATTR_SYNTAX_COUNTRY_STRING_NOT_PRINTABLE_10=Der angegebene Wert "%s" ist keine g\u00fcltige L\u00e4nderzeichenkette, da er ein oder mehrere nicht druckbare Zeichen enth\u00e4lt
ERR_ATTR_SYNTAX_DELIVERY_METHOD_NO_ELEMENTS_11=Der angegebene Wert "%s" ist keine g\u00fcltige Liefermethode, da er keine Elemente enth\u00e4lt
ERR_ATTR_SYNTAX_DELIVERY_METHOD_INVALID_ELEMENT_12=Der angegebene Wert "%s" ist keine g\u00fcltige Liefermethode, da "%s" keine g\u00fcltige Methode ist
ERR_ATTR_SYNTAX_DN_ATTR_ILLEGAL_CHAR_28=Der angegebene Wert "%s" kann nicht als g\u00fcltiger Distinguished Name (DN) geparst werden, da das Zeichen '%c' an Position '%d' in einem Attributnamen unzul\u00e4ssig ist
opendj3/opendj-ldap-sdk/src/main/resources/org/forgerock/opendj/ldap/core_es.properties
@@ -22,7 +22,6 @@
#      Copyright 2009 Sun Microsystems, Inc.
#
ERR_ATTR_SYNTAX_COUNTRY_STRING_INVALID_LENGTH_9=El valor proporcionado "%s" no es una cadena de pa\u00edses v\u00e1lida porque no tiene una longitud de dos caracteres. 
ERR_ATTR_SYNTAX_COUNTRY_STRING_NOT_PRINTABLE_10=El valor proporcionado "%s" no es una cadena de pa\u00edses v\u00e1lida porque contiene uno o m\u00e1s caracteres no imprimibles.
ERR_ATTR_SYNTAX_DELIVERY_METHOD_NO_ELEMENTS_11=El valor proporcionado "%s" no es un valor de m\u00e9todo de entrega v\u00e1lido porque no contiene elementos
ERR_ATTR_SYNTAX_DELIVERY_METHOD_INVALID_ELEMENT_12=El valor proporcionado "%s" no es un valor de m\u00e9todo de entrega v\u00e1lido porque "%s" no es un m\u00e9todo v\u00e1lido
ERR_ATTR_SYNTAX_DN_ATTR_ILLEGAL_CHAR_28=No se pudo analizar el valor proporcionado "%s" como nombre \u00fanico v\u00e1lido porque no se permite el car\u00e1cter '%c'  en la posici\u00f3n %d en un nombre de atributo
opendj3/opendj-ldap-sdk/src/main/resources/org/forgerock/opendj/ldap/core_fr.properties
@@ -22,7 +22,6 @@
#      Copyright 2009 Sun Microsystems, Inc.
#
ERR_ATTR_SYNTAX_COUNTRY_STRING_INVALID_LENGTH_9=La valeur indiqu\u00e9e "%s" n'est pas une cha\u00eene de pays valide car elle n'a pas une longueur de deux caract\u00e8res exactement
ERR_ATTR_SYNTAX_COUNTRY_STRING_NOT_PRINTABLE_10=La valeur indiqu\u00e9e "%s" n'est pas une cha\u00eene de pays valide car elle contient au moins un caract\u00e8re non imprimable
ERR_ATTR_SYNTAX_DELIVERY_METHOD_NO_ELEMENTS_11=La valeur indiqu\u00e9e "%s" n'est pas une m\u00e9thode de distribution valide car elle ne contient aucun \u00e9l\u00e9ment
ERR_ATTR_SYNTAX_DELIVERY_METHOD_INVALID_ELEMENT_12=La valeur indiqu\u00e9e "%s" n'est pas une m\u00e9thode de distribution valide car "%s" n'est pas une m\u00e9thode valide
ERR_ATTR_SYNTAX_DN_ATTR_ILLEGAL_CHAR_28=Impossible d'analyser la valeur indiqu\u00e9e "%s" en tant que nom distinctif valide car le caract\u00e8re '%c' \u00e0 la position %d n'est pas autoris\u00e9 dans un nom d'attribut
opendj3/opendj-ldap-sdk/src/main/resources/org/forgerock/opendj/ldap/core_ja.properties
@@ -22,7 +22,6 @@
#      Copyright 2009 Sun Microsystems, Inc.
#
ERR_ATTR_SYNTAX_COUNTRY_STRING_INVALID_LENGTH_9=\u6307\u5b9a\u3055\u308c\u305f\u5024 "%s" \u306f\u3001\u9577\u3055\u304c\u6b63\u78ba\u306b 2 \u6587\u5b57\u3067\u306f\u306a\u3044\u305f\u3081\u3001\u6709\u52b9\u306a\u56fd\u6587\u5b57\u5217\u3067\u306f\u3042\u308a\u307e\u305b\u3093
ERR_ATTR_SYNTAX_COUNTRY_STRING_NOT_PRINTABLE_10=\u6307\u5b9a\u3055\u308c\u305f\u5024 "%s" \u306f\u3001\u30d7\u30ea\u30f3\u30c8\u4e0d\u53ef\u80fd\u306a\u6587\u5b57\u304c 1 \u3064\u4ee5\u4e0a\u542b\u307e\u308c\u308b\u305f\u3081\u3001\u6709\u52b9\u306a\u56fd\u6587\u5b57\u5217\u3067\u306f\u3042\u308a\u307e\u305b\u3093
ERR_ATTR_SYNTAX_DELIVERY_METHOD_NO_ELEMENTS_11=\u6307\u5b9a\u3055\u308c\u305f\u5024 "%s" \u306f\u3001\u8981\u7d20\u304c\u4e00\u5207\u542b\u307e\u308c\u3066\u3044\u306a\u3044\u305f\u3081\u3001\u6709\u52b9\u306a\u5b9f\u65bd\u30e1\u30bd\u30c3\u30c9\u5024\u3067\u306f\u3042\u308a\u307e\u305b\u3093
ERR_ATTR_SYNTAX_DELIVERY_METHOD_INVALID_ELEMENT_12="%2$s" \u306f\u6709\u52b9\u306a\u30e1\u30bd\u30c3\u30c9\u3067\u306f\u306a\u3044\u305f\u3081\u3001\u6307\u5b9a\u3055\u308c\u305f\u5024 "%1$s" \u306f\u6709\u52b9\u306a\u5b9f\u65bd\u30e1\u30bd\u30c3\u30c9\u5024\u3067\u306f\u3042\u308a\u307e\u305b\u3093
ERR_ATTR_SYNTAX_DN_ATTR_ILLEGAL_CHAR_28=\u6307\u5b9a\u3055\u308c\u305f\u5024 "%1$s" \u3092\u6709\u52b9\u306a\u8b58\u5225\u540d\u3068\u3057\u3066\u89e3\u6790\u3067\u304d\u307e\u305b\u3093\u3067\u3057\u305f\u3002\u4f4d\u7f6e %3$d \u306e\u6587\u5b57 '%2$c' \u3092\u5c5e\u6027\u540d\u306b\u4f7f\u7528\u3059\u308b\u3053\u3068\u306f\u3067\u304d\u307e\u305b\u3093
opendj3/opendj-ldap-sdk/src/main/resources/org/forgerock/opendj/ldap/core_ko.properties
@@ -22,7 +22,6 @@
#      Copyright 2009 Sun Microsystems, Inc.
#
ERR_ATTR_SYNTAX_COUNTRY_STRING_INVALID_LENGTH_9=\uae38\uc774\uac00 \uc815\ud655\ud788 \ub450 \ubb38\uc790\uac00 \uc544\ub2c8\uae30 \ub54c\ubb38\uc5d0 \uc81c\uacf5\ub41c \uac12 \"%s\"\uc740(\ub294) \uc720\ud6a8\ud55c \uad6d\uac00 \ubb38\uc790\uc5f4\uc774 \uc544\ub2d9\ub2c8\ub2e4.
ERR_ATTR_SYNTAX_COUNTRY_STRING_NOT_PRINTABLE_10=\ud558\ub098 \uc774\uc0c1\uc758 \uc778\uc1c4\ud560 \uc218 \uc5c6\ub294 \ubb38\uc790\uac00 \ud3ec\ud568\ub418\uc5b4 \uc788\uae30 \ub54c\ubb38\uc5d0 \uc81c\uacf5\ub41c \uac12 \"%s\"\uc740(\ub294) \uc720\ud6a8\ud55c \uad6d\uac00 \ubb38\uc790\uc5f4\uc774 \uc544\ub2d9\ub2c8\ub2e4.
ERR_ATTR_SYNTAX_DELIVERY_METHOD_NO_ELEMENTS_11=\uc694\uc18c\uac00 \ud3ec\ud568\ub418\uc5b4 \uc788\uc9c0 \uc54a\uae30 \ub54c\ubb38\uc5d0 \uc81c\uacf5\ub41c \uac12 \"%s\"\uc740(\ub294) \uc720\ud6a8\ud55c \uc804\ub2ec \ubc29\ubc95\uc774 \uc544\ub2d9\ub2c8\ub2e4.
ERR_ATTR_SYNTAX_DELIVERY_METHOD_INVALID_ELEMENT_12=\"%2$s\"\uc774(\uac00) \uc720\ud6a8\ud55c \ubc29\ubc95\uc774 \uc544\ub2c8\uae30 \ub54c\ubb38\uc5d0 \uc81c\uacf5\ub41c \uac12 \"%1$s\"\uc740(\ub294) \uc720\ud6a8\ud55c \uc804\ub2ec \ubc29\ubc95\uc774 \uc544\ub2d9\ub2c8\ub2e4.
ERR_ATTR_SYNTAX_DN_ATTR_ILLEGAL_CHAR_28=\uc704\uce58 %3$d\uc5d0 \uc788\ub294 \ubb38\uc790 '%2$c'\uc774(\uac00) \uc18d\uc131 \uc774\ub984\uc5d0 \ud5c8\uc6a9\ub418\uc9c0 \uc54a\uae30 \ub54c\ubb38\uc5d0 \uc81c\uacf5\ub41c \uac12 \"%1$s\"\uc744(\ub97c) \uc720\ud6a8\ud55c \uace0\uc720 \uc774\ub984\uc73c\ub85c \uad6c\ubb38 \ubd84\uc11d\ud558\uc9c0 \ubabb\ud588\uc2b5\ub2c8\ub2e4.
opendj3/opendj-ldap-sdk/src/main/resources/org/forgerock/opendj/ldap/core_zh_CN.properties
@@ -22,7 +22,6 @@
#      Copyright 2009 Sun Microsystems, Inc.
#
ERR_ATTR_SYNTAX_COUNTRY_STRING_INVALID_LENGTH_9=\u63d0\u4f9b\u7684\u503c "%s" \u4e0d\u662f\u6709\u6548\u7684\u56fd\u5bb6/\u5730\u533a\u5b57\u7b26\u4e32\uff0c\u56e0\u4e3a\u957f\u5ea6\u5e76\u975e\u6070\u597d\u4e3a\u4e24\u4e2a\u5b57\u7b26
ERR_ATTR_SYNTAX_COUNTRY_STRING_NOT_PRINTABLE_10=\u63d0\u4f9b\u7684\u503c "%s" \u4e0d\u662f\u6709\u6548\u7684\u56fd\u5bb6/\u5730\u533a\u5b57\u7b26\u4e32\uff0c\u56e0\u4e3a\u5b83\u5305\u542b\u4e00\u4e2a\u6216\u591a\u4e2a\u4e0d\u53ef\u6253\u5370\u7684\u5b57\u7b26
ERR_ATTR_SYNTAX_DELIVERY_METHOD_NO_ELEMENTS_11=\u63d0\u4f9b\u7684\u503c "%s" \u4e0d\u662f\u6709\u6548\u7684\u4f20\u9001\u65b9\u6cd5\u503c\uff0c\u56e0\u4e3a\u5b83\u4e0d\u5305\u542b\u4efb\u4f55\u5143\u7d20
ERR_ATTR_SYNTAX_DELIVERY_METHOD_INVALID_ELEMENT_12=\u63d0\u4f9b\u7684\u503c "%s" \u4e0d\u662f\u6709\u6548\u7684\u4f20\u9001\u65b9\u6cd5\u503c\uff0c\u56e0\u4e3a "%s" \u4e0d\u662f\u6709\u6548\u7684\u65b9\u6cd5
ERR_ATTR_SYNTAX_DN_ATTR_ILLEGAL_CHAR_28=\u65e0\u6cd5\u5c06\u63d0\u4f9b\u7684\u503c "%1$s" \u89e3\u6790\u4e3a\u6709\u6548\u7684\u6807\u8bc6\u540d\uff0c\u56e0\u4e3a\u5c5e\u6027\u540d\u79f0\u4e2d\u4e0d\u5141\u8bb8\u4f7f\u7528\u4f4d\u7f6e %3$d \u5904\u7684\u5b57\u7b26 '%2$c'
opendj3/opendj-ldap-sdk/src/main/resources/org/forgerock/opendj/ldap/core_zh_TW.properties
@@ -22,7 +22,6 @@
#      Copyright 2009 Sun Microsystems, Inc.
#
ERR_ATTR_SYNTAX_COUNTRY_STRING_INVALID_LENGTH_9=\u63d0\u4f9b\u7684\u503c\u300c%s\u300d\u4e0d\u662f\u6709\u6548\u7684\u570b\u5bb6/\u5730\u5340\u5b57\u4e32\uff0c\u56e0\u70ba\u5176\u9577\u5ea6\u4e0d\u662f\u6b63\u597d\u5169\u500b\u5b57\u5143
ERR_ATTR_SYNTAX_COUNTRY_STRING_NOT_PRINTABLE_10=\u63d0\u4f9b\u7684\u503c\u300c%s\u300d\u4e0d\u662f\u6709\u6548\u7684\u570b\u5bb6/\u5730\u5340\u5b57\u4e32\uff0c\u56e0\u70ba\u5176\u4e2d\u5305\u542b\u4e00\u6216\u591a\u500b\u4e0d\u53ef\u5217\u5370\u7684\u5b57\u5143
ERR_ATTR_SYNTAX_DELIVERY_METHOD_NO_ELEMENTS_11=\u63d0\u4f9b\u7684\u503c\u300c%s\u300d\u4e0d\u662f\u6709\u6548\u7684\u50b3\u9001\u65b9\u6cd5\u503c\uff0c\u56e0\u70ba\u5176\u4e2d\u4e0d\u5305\u542b\u4efb\u4f55\u5143\u7d20
ERR_ATTR_SYNTAX_DELIVERY_METHOD_INVALID_ELEMENT_12=\u63d0\u4f9b\u7684\u503c\u300c%s\u300d\u4e0d\u662f\u6709\u6548\u7684\u50b3\u9001\u65b9\u6cd5\u503c\uff0c\u56e0\u70ba\u300c%s\u300d\u4e0d\u662f\u6709\u6548\u7684\u65b9\u6cd5
ERR_ATTR_SYNTAX_DN_ATTR_ILLEGAL_CHAR_28=\u63d0\u4f9b\u7684\u503c\u300c%1$s\u300d\u7121\u6cd5\u5256\u6790\u70ba\u6709\u6548\u7684\u8fa8\u5225\u540d\u7a31\uff0c\u56e0\u70ba\u5c6c\u6027\u540d\u7a31\u4e2d\u4e0d\u5f97\u6709\u4f4d\u7f6e %3$d \u7684\u5b57\u5143\u300c%2$c\u300d
opendj3/opendj-ldap-sdk/src/test/java/org/forgerock/opendj/ldap/schema/CountryStringSyntaxTest.java
New file
@@ -0,0 +1,60 @@
/*
 * 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 2012 Manuel Gaupp
 *
 */
package org.forgerock.opendj.ldap.schema;
import static org.forgerock.opendj.ldap.schema.SchemaConstants.SYNTAX_COUNTRY_STRING_OID;
import org.testng.annotations.DataProvider;
/**
 * Country String syntax tests.
 */
public class CountryStringSyntaxTest extends SyntaxTestCase {
    @Override
    @DataProvider(name = "acceptableValues")
    public Object[][] createAcceptableValues() {
        return new Object[][] {
            // tests for the Country String syntax.
            { "DE", true },
            { "de", false },
            { "SX", true },
            { "12", false },
            { "UK", true },
            { "Xf", false },
            { "ÖÄ", false },
        };
    }
    /**
     * {@inheritDoc}
     */
    @Override
    protected Syntax getRule() {
        return Schema.getCoreSchema().getSyntax(SYNTAX_COUNTRY_STRING_OID);
    }
}