directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1035690 - in /directory: apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/schema/ shared/trunk/ldap-schema/src/main/java/org/apache/directory/shared/ldap/schema/loader/ldif/ shared/trunk/ldap/src/main/java/org/apach...
Date Tue, 16 Nov 2010 16:49:27 GMT
Author: elecharny
Date: Tue Nov 16 16:49:26 2010
New Revision: 1035690

URL: http://svn.apache.org/viewvc?rev=1035690&view=rev
Log:
Fix for DIRSERVER-1581, and added tests to demonstrate the issue.

Modified:
    directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaAttributeTypeHandlerIT.java
    directory/shared/trunk/ldap-schema/src/main/java/org/apache/directory/shared/ldap/schema/loader/ldif/SchemaEntityFactory.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/DefaultEntryAttribute.java
    directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/schema/parser/OpenLdapSchemaParserTest.java

Modified: directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaAttributeTypeHandlerIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaAttributeTypeHandlerIT.java?rev=1035690&r1=1035689&r2=1035690&view=diff
==============================================================================
--- directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaAttributeTypeHandlerIT.java
(original)
+++ directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaAttributeTypeHandlerIT.java
Tue Nov 16 16:49:26 2010
@@ -204,6 +204,44 @@ public class MetaAttributeTypeHandlerIT 
     }
 
 
+    /**
+     * Test for DIRSERVER-1581.
+     * Add an AT with DESC containing an ending space
+     */
+    @Test
+    public void testAddAttributeTypeDescWithEndingSpace() throws Exception
+    {
+        Attributes attrs = LdifUtils.createAttributes(
+            "objectClass: top",
+            "objectClass: metaTop",
+            "objectClass: metaAttributeType",
+            "m-oid: 1.3.6.1.4.1.8104.1.1.37",
+            "m-name: versionNumber",
+            "m-description:: dmVyc2lvbk51bWJlciA=",
+            "m-equality: caseIgnoreMatch",
+            "m-substr: caseIgnoreSubstringsMatch",
+            "m-syntax: 1.3.6.1.4.1.1466.115.121.1.8",
+            "m-length: 0",
+            "m-singleValue: TRUE"
+         );
+
+        DN dn = getAttributeTypeContainer( "apachemeta" );
+        dn = dn.add( "m-oid=1.3.6.1.4.1.8104.1.1.37" );
+
+        // Pre-checks
+        assertFalse( isOnDisk( dn ) );
+        assertFalse( service.getSchemaManager().getAttributeTypeRegistry().contains( "1.3.6.1.4.1.8104.1.1.37"
) );
+
+        // Addition
+        getSchemaContext( service ).createSubcontext( JndiUtils.toName( dn ), attrs );
+
+        // Post-checks
+        assertTrue( service.getSchemaManager().getAttributeTypeRegistry().contains( "1.3.6.1.4.1.8104.1.1.37"
) );
+        assertEquals( service.getSchemaManager().getAttributeTypeRegistry().getSchemaName(
"1.3.6.1.4.1.8104.1.1.37" ), "apachemeta" );
+        assertTrue( isOnDisk( dn ) );
+    }
+
+
     // ----------------------------------------------------------------------
     // Test Delete operation
     // ----------------------------------------------------------------------

Modified: directory/shared/trunk/ldap-schema/src/main/java/org/apache/directory/shared/ldap/schema/loader/ldif/SchemaEntityFactory.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap-schema/src/main/java/org/apache/directory/shared/ldap/schema/loader/ldif/SchemaEntityFactory.java?rev=1035690&r1=1035689&r2=1035690&view=diff
==============================================================================
--- directory/shared/trunk/ldap-schema/src/main/java/org/apache/directory/shared/ldap/schema/loader/ldif/SchemaEntityFactory.java
(original)
+++ directory/shared/trunk/ldap-schema/src/main/java/org/apache/directory/shared/ldap/schema/loader/ldif/SchemaEntityFactory.java
Tue Nov 16 16:49:26 2010
@@ -530,6 +530,7 @@ public class SchemaEntityFactory impleme
         }
         catch ( Exception e )
         {
+            e.printStackTrace();
             throw new LdapUnwillingToPerformException( ResultCodeEnum.UNWILLING_TO_PERFORM,
e.getMessage() );
         }
     }
@@ -903,6 +904,7 @@ public class SchemaEntityFactory impleme
 
         if ( ( mSyntax != null ) && ( mSyntax.get() != null ) )
         {
+            mSyntax.setHR( true );
             attributeType.setSyntaxOid( mSyntax.getString() );
         }
 
@@ -911,6 +913,7 @@ public class SchemaEntityFactory impleme
 
         if ( mSyntaxLength != null )
         {
+            mSyntaxLength.setHR( true );
             attributeType.setSyntaxLength( Integer.parseInt( mSyntaxLength.getString() )
);
         }
 
@@ -919,6 +922,7 @@ public class SchemaEntityFactory impleme
 
         if ( mEquality != null )
         {
+            mEquality.setHR( true );
             attributeType.setEqualityOid( mEquality.getString() );
         }
 
@@ -927,6 +931,7 @@ public class SchemaEntityFactory impleme
 
         if ( mOrdering != null )
         {
+            mOrdering.setHR( true );
             attributeType.setOrderingOid( mOrdering.getString() );
         }
 
@@ -935,6 +940,7 @@ public class SchemaEntityFactory impleme
 
         if ( mSubstr != null )
         {
+            mSubstr.setHR( true );
             attributeType.setSubstringOid( mSubstr.getString() );
         }
 
@@ -943,6 +949,7 @@ public class SchemaEntityFactory impleme
         // Sup
         if ( mSupAttributeType != null )
         {
+            mSupAttributeType.setHR( true );
             attributeType.setSuperiorOid( mSupAttributeType.getString() );
         }
 
@@ -951,6 +958,7 @@ public class SchemaEntityFactory impleme
 
         if ( mCollective != null )
         {
+            mCollective.setHR( true );
             String val = mCollective.getString();
             attributeType.setCollective( val.equalsIgnoreCase( "TRUE" ) );
         }
@@ -960,6 +968,7 @@ public class SchemaEntityFactory impleme
 
         if ( mSingleValued != null )
         {
+            mSingleValued.setHR( true );
             String val = mSingleValued.getString();
             attributeType.setSingleValued( val.equalsIgnoreCase( "TRUE" ) );
         }
@@ -969,6 +978,7 @@ public class SchemaEntityFactory impleme
 
         if ( mNoUserModification != null )
         {
+            mNoUserModification.setHR( true );
             String val = mNoUserModification.getString();
             attributeType.setUserModifiable( !val.equalsIgnoreCase( "TRUE" ) );
         }
@@ -978,6 +988,7 @@ public class SchemaEntityFactory impleme
 
         if ( mUsage != null )
         {
+            mUsage.setHR( true );
             attributeType.setUsage( UsageEnum.getUsage( mUsage.getString() ) );
         }
 
@@ -1068,6 +1079,7 @@ public class SchemaEntityFactory impleme
 
         if ( mObsolete != null )
         {
+            mObsolete.setHR( true );
             String val = mObsolete.getString();
             schemaObject.setObsolete( val.equalsIgnoreCase( "TRUE" ) );
         }
@@ -1077,6 +1089,7 @@ public class SchemaEntityFactory impleme
 
         if ( mDescription != null )
         {
+            mDescription.setHR( true );
             schemaObject.setDescription( mDescription.getString() );
         }
 
@@ -1085,6 +1098,7 @@ public class SchemaEntityFactory impleme
 
         if ( names != null )
         {
+            names.setHR( true );
             List<String> values = new ArrayList<String>();
 
             for ( Value<?> name : names )
@@ -1102,6 +1116,7 @@ public class SchemaEntityFactory impleme
         // Otherwise, inherit it from the schema
         if ( mDisabled != null )
         {
+            mDisabled.setHR( true );
             String val = mDisabled.getString();
             schemaObject.setEnabled( !val.equalsIgnoreCase( "TRUE" ) );
         }
@@ -1115,6 +1130,7 @@ public class SchemaEntityFactory impleme
 
         if ( mIsReadOnly != null )
         {
+            mIsReadOnly.setHR( true );
             String val = mIsReadOnly.getString();
             schemaObject.setReadOnly( val.equalsIgnoreCase( "TRUE" ) );
         }

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/DefaultEntryAttribute.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/DefaultEntryAttribute.java?rev=1035690&r1=1035689&r2=1035690&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/DefaultEntryAttribute.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/DefaultEntryAttribute.java
Tue Nov 16 16:49:26 2010
@@ -26,11 +26,10 @@ import java.util.Iterator;
 import java.util.LinkedHashSet;
 import java.util.Set;
 
-import org.apache.directory.shared.ldap.exception.LdapException;
-import org.apache.directory.shared.ldap.exception.LdapInvalidAttributeValueException;
-
 import org.apache.directory.shared.asn1.primitives.OID;
 import org.apache.directory.shared.i18n.I18n;
+import org.apache.directory.shared.ldap.exception.LdapException;
+import org.apache.directory.shared.ldap.exception.LdapInvalidAttributeValueException;
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.schema.AttributeType;
 import org.apache.directory.shared.ldap.schema.SyntaxChecker;
@@ -495,6 +494,17 @@ public class DefaultEntryAttribute imple
         }
         else
         {
+            if ( isHR )
+            {
+                // Try to convert the value from a byte[] to a String
+                if ( value != null )
+                {
+                    String valueStr = StringTools.utf8ToString( (byte[])value.getReference()
);
+                
+                    return valueStr;
+                }
+            }
+            
             String message = I18n.err( I18n.ERR_04131 );
             LOG.error( message );
             throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX,
message );

Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/schema/parser/OpenLdapSchemaParserTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/schema/parser/OpenLdapSchemaParserTest.java?rev=1035690&r1=1035689&r2=1035690&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/schema/parser/OpenLdapSchemaParserTest.java
(original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/schema/parser/OpenLdapSchemaParserTest.java
Tue Nov 16 16:49:26 2010
@@ -105,8 +105,10 @@ public class OpenLdapSchemaParserTest
     @Test
     public void testSimpleAttributeTypeParse() throws Exception
     {
-        String attributeTypeData = "# adding a comment  \n" + "attributetype ( 2.5.4.2 NAME
'knowledgeInformation'\n"
-            + "        DESC 'RFC2256: knowledge information'\n" + "        EQUALITY caseIgnoreMatch\n"
+        String attributeTypeData = "# adding a comment  \n" 
+            + "attributetype ( 2.5.4.2 NAME 'knowledgeInformation'\n"
+            + "        DESC 'RFC2256: knowledge information'\n" 
+            + "        EQUALITY caseIgnoreMatch\n"
             + "        SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768} )";
         parser.parse( attributeTypeData );
         List<AttributeType> attributeTypeList = parser.getAttributeTypes();
@@ -125,8 +127,10 @@ public class OpenLdapSchemaParserTest
     @Test
     public void testAttributeTypeParseWithDescQuotes() throws Exception
     {
-        String attributeTypeData = "# adding a comment  \n" + "attributetype ( 2.5.4.2 NAME
'knowledgeInformation'\n"
-            + "        DESC 'RFC2256: \"knowledge\" information'\n" + "        EQUALITY caseIgnoreMatch\n"
+        String attributeTypeData = "# adding a comment  \n" 
+            + "attributetype ( 2.5.4.2 NAME 'knowledgeInformation'\n"
+            + "        DESC 'RFC2256: \"knowledge\" information'\n" 
+            + "        EQUALITY caseIgnoreMatch\n"
             + "        SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768} )";
         parser.parse( attributeTypeData );
         List<AttributeType> attributeTypeList = parser.getAttributeTypes();
@@ -147,7 +151,8 @@ public class OpenLdapSchemaParserTest
     {
         String attributeTypeData = "# adding a comment  \n"
             + "attributetype ( 2.5.4.2 NAME ( 'knowledgeInformation' 'asdf' ) \n"
-            + "        DESC 'RFC2256: knowledge information'\n" + "        EQUALITY caseIgnoreMatch\n"
+            + "        DESC 'RFC2256: knowledge information'\n" 
+            + "        EQUALITY caseIgnoreMatch\n"
             + "        SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768} )";
         parser.parse( attributeTypeData );
         List<AttributeType> attributeTypeList = parser.getAttributeTypes();
@@ -179,8 +184,10 @@ public class OpenLdapSchemaParserTest
     @Test
     public void testObjectClassParse() throws Exception
     {
-        String objectClassData = "objectclass ( 2.5.6.6 NAME 'person'\n" + "        DESC
'RFC2256: a person'\n"
-            + "        SUP top STRUCTURAL\n" + "        MUST ( sn $ cn )\n"
+        String objectClassData = "objectclass ( 2.5.6.6 NAME 'person'\n" 
+            + "        DESC 'RFC2256: a person'\n"
+            + "        SUP top STRUCTURAL\n" 
+            + "        MUST ( sn $ cn )\n"
             + "        MAY ( userPassword $ telephoneNumber $ seeAlso $ description ) )";
         parser.parse( objectClassData );
         List<ObjectClass> objectClassesList = parser.getObjectClassTypes();
@@ -403,4 +410,24 @@ public class OpenLdapSchemaParserTest
         }
     }
 
+
+    @Test
+    public void testDescWithSpaces() throws Exception
+    {
+        String attributeTypeData = "attributetype ( 1.3.6.1.4.1.8104.1.1.37 NAME 'versionNumber'\n"
+            + "        DESC 'versionNumber ' EQUALITY caseIgnoreMatch SUBSTR caseIgnoreSubstringsMatch\n"
+            + "        SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 SINGLE-VALUE)";
+
+        parser.parse( attributeTypeData );
+        List<AttributeType> attributeTypes = parser.getAttributeTypes();
+        Map<String, AttributeType> mapAttributeTypes = mapAttributeTypes( attributeTypes
);
+        AttributeType attributeType = mapAttributeTypes.get( "1.3.6.1.4.1.8104.1.1.37" );
+
+        assertNotNull( attributeType );
+        assertEquals( "1.3.6.1.4.1.8104.1.1.37", attributeType.getOid() );
+        assertEquals( "versionNumber", attributeType.getName() );
+        assertEquals( "versionNumber ", attributeType.getDescription() );
+        assertEquals( "1.3.6.1.4.1.1466.115.121.1.15", attributeType.getSyntaxOid() );
+        assertTrue( attributeType.isSingleValued() );
+    }
 }



Mime
View raw message