directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r939011 - in /directory: apacheds/trunk/core-entry/src/test/java/org/apache/directory/server/core/entry/ shared/trunk/i18n/src/main/java/org/apache/directory/shared/i18n/ shared/trunk/i18n/src/main/resources/org/apache/directory/shared/i18n...
Date Wed, 28 Apr 2010 17:14:48 GMT
Author: elecharny
Date: Wed Apr 28 17:14:48 2010
New Revision: 939011

URL: http://svn.apache.org/viewvc?rev=939011&view=rev
Log:
o Fixed the way binary values handle null values : the syntaxChecker is called if the Value
is schema aware
o Added some error messages

Modified:
    directory/apacheds/trunk/core-entry/src/test/java/org/apache/directory/server/core/entry/SchemaAwareEntryAttributeTest.java
    directory/apacheds/trunk/core-entry/src/test/java/org/apache/directory/server/core/entry/SchemaAwareEntryTest.java
    directory/shared/trunk/i18n/src/main/java/org/apache/directory/shared/i18n/I18n.java
    directory/shared/trunk/i18n/src/main/resources/org/apache/directory/shared/i18n/errors.properties
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/BinaryValue.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/DefaultEntry.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/entry/BinaryValueAttributeTypeTest.java

Modified: directory/apacheds/trunk/core-entry/src/test/java/org/apache/directory/server/core/entry/SchemaAwareEntryAttributeTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-entry/src/test/java/org/apache/directory/server/core/entry/SchemaAwareEntryAttributeTest.java?rev=939011&r1=939010&r2=939011&view=diff
==============================================================================
--- directory/apacheds/trunk/core-entry/src/test/java/org/apache/directory/server/core/entry/SchemaAwareEntryAttributeTest.java
(original)
+++ directory/apacheds/trunk/core-entry/src/test/java/org/apache/directory/server/core/entry/SchemaAwareEntryAttributeTest.java
Wed Apr 28 17:14:48 2010
@@ -775,7 +775,7 @@ public class SchemaAwareEntryAttributeTe
         EntryAttribute attr6 = new DefaultEntryAttribute( atPwd );
         
         nbAdded = attr6.add( "a", (String)null );
-        assertEquals( 1, nbAdded );
+        assertEquals( 2, nbAdded );
         assertFalse( attr6.isHR() );
     }
 
@@ -830,7 +830,7 @@ public class SchemaAwareEntryAttributeTe
         EntryAttribute attr6 = new DefaultEntryAttribute( atPwd );
         
         nbAdded = attr6.add( "ab", (String)null );
-        assertEquals( 1, nbAdded );
+        assertEquals( 2, nbAdded );
         assertFalse( attr6.isHR() );
     }
 
@@ -1264,7 +1264,7 @@ public class SchemaAwareEntryAttributeTe
         EntryAttribute attr6 = new DefaultEntryAttribute( atPwd );
         
         nbAdded = attr6.add( "a", (String)null );
-        assertEquals( 1, nbAdded );
+        assertEquals( 2, nbAdded );
         assertFalse( attr6.isHR() );
     }
 

Modified: directory/apacheds/trunk/core-entry/src/test/java/org/apache/directory/server/core/entry/SchemaAwareEntryTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-entry/src/test/java/org/apache/directory/server/core/entry/SchemaAwareEntryTest.java?rev=939011&r1=939010&r2=939011&view=diff
==============================================================================
--- directory/apacheds/trunk/core-entry/src/test/java/org/apache/directory/server/core/entry/SchemaAwareEntryTest.java
(original)
+++ directory/apacheds/trunk/core-entry/src/test/java/org/apache/directory/server/core/entry/SchemaAwareEntryTest.java
Wed Apr 28 17:14:48 2010
@@ -63,7 +63,6 @@ import org.apache.directory.shared.ldap.
 import org.junit.BeforeClass;
 import org.junit.Test;
 
-
 /**
  * Test the DefaultEntry class.
  *
@@ -287,9 +286,9 @@ public class SchemaAwareEntryTest
         
         entry.clear();
         
-        entry.add( "jpegPhoto", BYTES1, BYTES1, BYTES2 );
+        entry.add( "userPassword", BYTES1, BYTES1, BYTES2 );
         assertEquals( 1, entry.size() );
-        EntryAttribute attributeJPG = entry.get( "jpegPhoto" );
+        EntryAttribute attributeJPG = entry.get( "userPassword" );
         assertEquals( 2, attributeJPG.size() );
         assertNotNull( attributeJPG.get() );
         assertTrue( attributeJPG.contains( BYTES1 ) );
@@ -309,8 +308,8 @@ public class SchemaAwareEntryTest
          }
 
          // Cannot add String values into a binary attribute
-         entry.add( "jpegPhoto", "test", "test2" );
-         assertEquals( 0, entry.get( "jpegPhoto" ).size() );
+         entry.add( "userPassword", "test", "test2" );
+         assertEquals( 2, entry.get( "userPassword" ).size() );
     }
      
 
@@ -646,6 +645,17 @@ public class SchemaAwareEntryTest
         DN dn = new DN( "cn=test" );
         DefaultEntry entry = new DefaultEntry( schemaManager, dn );
         
+        // Test that we can't inject a null AT
+        try
+        {
+            entry.add( (AttributeType)null, "test" );
+            fail();
+        }
+        catch ( IllegalArgumentException iae )
+        {
+            // Expected
+        }
+        
         // Test a simple addition
         entry.add( atDC, "test1" );
         assertNotNull( entry.get( atDC ) );
@@ -696,11 +706,34 @@ public class SchemaAwareEntryTest
         DefaultEntry entry = new DefaultEntry( schemaManager, dn );
         
         AttributeType atPassword = schemaManager.lookupAttributeTypeRegistry( "userPassword"
);
+        AttributeType atJpegPhoto = schemaManager.lookupAttributeTypeRegistry( "jpegPhoto"
);
         
         byte[] test1 = StringTools.getBytesUtf8( "test1" );
         byte[] test2 = StringTools.getBytesUtf8( "test2" );
         byte[] test3 = StringTools.getBytesUtf8( "test3" );
         
+        // Test that we can't inject a null AT
+        try
+        {
+            entry.add( (AttributeType)null, test1 );
+            fail();
+        }
+        catch ( IllegalArgumentException iae )
+        {
+            // Expected
+        }
+        
+        // Test that we cannot inject a null value in an AT that does not allow it
+        try
+        {
+            entry.add( atJpegPhoto, (byte[])null );
+            fail();
+        }
+        catch ( IllegalArgumentException iae )
+        {
+            // Expected
+        }
+        
         // Test a simple addition
         entry.add( atPassword, test1 );
         assertNotNull( entry.get( atPassword ) );
@@ -766,6 +799,17 @@ public class SchemaAwareEntryTest
         Value<byte[]> testB2 = new BinaryValue( atPassword, b2 );
         Value<byte[]> testB3 = new BinaryValue( atPassword, b3 );
         
+        // Test that we can't inject a null AT
+        try
+        {
+            entry.add( (AttributeType)null, test1 );
+            fail();
+        }
+        catch ( IllegalArgumentException iae )
+        {
+            // Expected
+        }
+        
         // Test a simple addition in atDC
         entry.add( atDC, test1 );
         assertNotNull( entry.get( atDC ) );
@@ -2375,16 +2419,16 @@ public class SchemaAwareEntryTest
         assertNotNull( entry.get( "userPassword" ).get().get() );
         assertTrue( entry.get( "userPassword" ).contains( BYTES1 ) );
         
-        replaced = entry.put(  "jpegPhoto", BYTES1, BYTES2, BYTES1 );
-        assertNull( replaced );
-        assertEquals( 2, entry.size() );
-        assertNotNull( entry.get( "jpegPhoto" ) );
-        assertEquals( 2, entry.get( "JPEGPhoto" ).size() );
-        EntryAttribute attribute = entry.get( "jpegPhoto" );
+        replaced = entry.put(  "userPassword", BYTES1, BYTES2, BYTES1 );
+        assertNotNull( replaced );
+        assertEquals( 1, entry.size() );
+        assertNotNull( entry.get( "userPassword" ) );
+        assertEquals( 2, entry.get( "USERPassword" ).size() );
+        EntryAttribute attribute = entry.get( "userPassword" );
         assertTrue( attribute.contains( BYTES1 ) );
         assertTrue( attribute.contains( BYTES2 ) );
-        assertEquals( "jpegphoto", attribute.getId() );
-        assertEquals( "jpegPhoto", attribute.getUpId() );
+        assertEquals( "userpassword", attribute.getId() );
+        assertEquals( "userPassword", attribute.getUpId() );
     }
 
 

Modified: directory/shared/trunk/i18n/src/main/java/org/apache/directory/shared/i18n/I18n.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/i18n/src/main/java/org/apache/directory/shared/i18n/I18n.java?rev=939011&r1=939010&r2=939011&view=diff
==============================================================================
--- directory/shared/trunk/i18n/src/main/java/org/apache/directory/shared/i18n/I18n.java (original)
+++ directory/shared/trunk/i18n/src/main/java/org/apache/directory/shared/i18n/I18n.java Wed
Apr 28 17:14:48 2010
@@ -620,6 +620,8 @@ public class I18n
     public static final String ERR_04475 = "ERR_04475";
     public static final String ERR_04476 = "ERR_04476";
     public static final String ERR_04477_NO_VALID_AT_FOR_THIS_ID = "ERR_04477_NO_VALID_AT_FOR_THIS_ID";
+    public static final String ERR_04478_NO_VALUE_NOT_ALLOWED = "ERR_04478_NO_VALUE_NOT_ALLOWED";
+    public static final String ERR_04479_INVALID_SYNTAX_VALUE = "ERR_04479_INVALID_SYNTAX_VALUE";
 
 	// ldap-constants
 	public static final String ERR_05001 = "ERR_05001";

Modified: directory/shared/trunk/i18n/src/main/resources/org/apache/directory/shared/i18n/errors.properties
URL: http://svn.apache.org/viewvc/directory/shared/trunk/i18n/src/main/resources/org/apache/directory/shared/i18n/errors.properties?rev=939011&r1=939010&r2=939011&view=diff
==============================================================================
--- directory/shared/trunk/i18n/src/main/resources/org/apache/directory/shared/i18n/errors.properties
(original)
+++ directory/shared/trunk/i18n/src/main/resources/org/apache/directory/shared/i18n/errors.properties
Wed Apr 28 17:14:48 2010
@@ -579,6 +579,8 @@ ERR_04474=Expected string to normalize
 ERR_04475=Expected byte[] to normalize
 ERR_04476=Cannot set an AttributeType {0} when another one ({1}) is already present
 ERR_04477_NO_VALID_AT_FOR_THIS_ID=Cannot find a valid AttributeType for the ''{0}'' id
+ERR_04478_NO_VALUE_NOT_ALLOWED=Cannot create or add an Attribute with no value in it
+ERR_04479_INVALID_SYNTAX_VALUE= The value ''{0}'' does not respect the AttributeType ''{1}''
syntax
 
 # ldap-constants
 ERR_05001=Unknown AuthenticationLevel {0}

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/BinaryValue.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/BinaryValue.java?rev=939011&r1=939010&r2=939011&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/BinaryValue.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/BinaryValue.java
Wed Apr 28 17:14:48 2010
@@ -32,6 +32,7 @@ import org.apache.directory.shared.i18n.
 import org.apache.directory.shared.ldap.schema.AttributeType;
 import org.apache.directory.shared.ldap.schema.LdapComparator;
 import org.apache.directory.shared.ldap.schema.Normalizer;
+import org.apache.directory.shared.ldap.schema.SyntaxChecker;
 import org.apache.directory.shared.ldap.schema.comparators.ByteArrayComparator;
 import org.apache.directory.shared.ldap.util.StringTools;
 import org.slf4j.Logger;
@@ -133,7 +134,21 @@ public class BinaryValue extends Abstrac
     public BinaryValue( AttributeType attributeType, byte[] value )
     {
         this( attributeType );
-        this.wrappedValue = value;
+        SyntaxChecker syntaxChecker = attributeType.getSyntax().getSyntaxChecker();
+        
+        if ( syntaxChecker != null ) 
+        {
+            if ( syntaxChecker.isValidSyntax( value ) )
+            {
+                this.wrappedValue = value;
+            }
+            else
+            {
+                String msg = I18n.err( I18n.ERR_04479_INVALID_SYNTAX_VALUE, value, attributeType.getName()
);
+                LOG.info( msg );
+                throw new IllegalArgumentException( msg );
+            }
+        }
     }
 
 

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/DefaultEntry.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/DefaultEntry.java?rev=939011&r1=939010&r2=939011&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/DefaultEntry.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/DefaultEntry.java
Wed Apr 28 17:14:48 2010
@@ -587,6 +587,13 @@ public class DefaultEntry implements Ent
             throw new IllegalArgumentException( message );
         }
         
+        if ( ( values == null ) || ( values.length == 0 ) )
+        {
+            String message = I18n.err( I18n.ERR_04478_NO_VALUE_NOT_ALLOWED );
+            LOG.error( message );
+            throw new IllegalArgumentException( message );
+        }
+        
         // ObjectClass with binary values are not allowed
         if ( attributeType.equals( OBJECT_CLASS_AT ) )
         {

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=939011&r1=939010&r2=939011&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
Wed Apr 28 17:14:48 2010
@@ -26,8 +26,6 @@ import java.io.ObjectOutput;
 import java.util.Iterator;
 import java.util.LinkedHashSet;
 import java.util.Set;
-import java.util.SortedSet;
-import java.util.TreeSet;
 
 import org.apache.directory.shared.ldap.exception.LdapException;
 import org.apache.directory.shared.ldap.exception.LdapInvalidAttributeValueException;
@@ -37,7 +35,6 @@ import org.apache.directory.shared.i18n.
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.schema.AttributeType;
 import org.apache.directory.shared.ldap.schema.SyntaxChecker;
-import org.apache.directory.shared.ldap.util.ArrayUtils;
 import org.apache.directory.shared.ldap.util.StringTools;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -916,11 +913,19 @@ public class DefaultEntryAttribute imple
                 {
                     if ( val == null )
                     {
-                        Value<byte[]> nullSV = new BinaryValue( attributeType, (byte[])null
);
-                        
-                        if ( values.add( nullSV ) )
+                        if ( attributeType.getSyntax().getSyntaxChecker().isValidSyntax(
val ) )
                         {
-                            nbAdded++;
+                            Value<byte[]> nullSV = new BinaryValue( attributeType,
(byte[])null );
+                            
+                            if ( values.add( nullSV ) )
+                            {
+                                nbAdded++;
+                            }
+                        }
+                        else
+                        {
+                            String message = I18n.err( I18n.ERR_04452 );
+                            LOG.error( message );
                         }
                     }
                     else

Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/entry/BinaryValueAttributeTypeTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/entry/BinaryValueAttributeTypeTest.java?rev=939011&r1=939010&r2=939011&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/entry/BinaryValueAttributeTypeTest.java
(original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/entry/BinaryValueAttributeTypeTest.java
Wed Apr 28 17:14:48 2010
@@ -429,8 +429,15 @@ public class BinaryValueAttributeTypeTes
         value = new BinaryValue( attribute, new byte[]{0x01, 0x02} );
         assertTrue( value.isValid() );
 
-        value = new BinaryValue( attribute, new byte[]{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}
);
-        assertFalse( value.isValid() );
+        try
+        {
+            value = new BinaryValue( attribute, new byte[]{0x01, 0x02, 0x03, 0x04, 0x05,
0x06} );
+            fail();
+        }
+        catch ( IllegalArgumentException iae )
+        {
+            assertTrue( true );
+        }
     }
     
     



Mime
View raw message