directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r372687 - in /directory/trunks/common/ldap/src: main/java/org/apache/ldap/common/codec/ main/java/org/apache/ldap/common/codec/add/ test/java/org/apache/ldap/common/codec/add/
Date Fri, 27 Jan 2006 01:17:33 GMT
Author: elecharny
Date: Thu Jan 26 17:17:20 2006
New Revision: 372687

URL: http://svn.apache.org/viewcvs?rev=372687&view=rev
Log:
- Fixed a bad case when we had a control after a request which contains a bad PDU

Modified:
    directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/LdapResultGrammar.java
    directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/add/AddRequestGrammar.java
    directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/add/AddResponseGrammar.java
    directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/add/AddRequestTest.java
    directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/add/AddResponseTest.java

Modified: directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/LdapResultGrammar.java
URL: http://svn.apache.org/viewcvs/directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/LdapResultGrammar.java?rev=372687&r1=372686&r2=372687&view=diff
==============================================================================
--- directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/LdapResultGrammar.java
(original)
+++ directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/LdapResultGrammar.java
Thu Jan 26 17:17:20 2006
@@ -357,7 +357,7 @@
                             log.debug( "The error message is : " + ldapResult.getErrorMessage()
);
                         }
 
-                        // We cazn pop this grammar
+                        // We can pop this grammar
                         container.grammarPopAllowed( true );
                         
                         return;
@@ -487,7 +487,14 @@
         super.transitions[LdapStatesEnum.LDAP_RESULT_REFERRAL_LOOP_TAG][UniversalTag.OCTET_STRING_TAG]
=
             new GrammarTransition(
                 LdapStatesEnum.LDAP_RESULT_REFERRAL_LOOP_TAG,
-                LdapStatesEnum.LDAP_RESULT_REFERRAL_VALUE, null );
+                LdapStatesEnum.LDAP_RESULT_REFERRAL_VALUE, 
+                new GrammarAction( "Allows pop" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+                        container.grammarPopAllowed( true );
+                    }
+                });
 
     }
 

Modified: directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/add/AddRequestGrammar.java
URL: http://svn.apache.org/viewcvs/directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/add/AddRequestGrammar.java?rev=372687&r1=372686&r2=372687&view=diff
==============================================================================
--- directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/add/AddRequestGrammar.java
(original)
+++ directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/add/AddRequestGrammar.java
Thu Jan 26 17:17:20 2006
@@ -385,6 +385,9 @@
 
                         // We can have an END transition
                         ldapMessageContainer.grammarEndAllowed( true );
+
+                        // We can have an POP transition
+                        ldapMessageContainer.grammarPopAllowed( true );
                     }
                 } );
 

Modified: directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/add/AddResponseGrammar.java
URL: http://svn.apache.org/viewcvs/directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/add/AddResponseGrammar.java?rev=372687&r1=372686&r2=372687&view=diff
==============================================================================
--- directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/add/AddResponseGrammar.java
(original)
+++ directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/add/AddResponseGrammar.java
Thu Jan 26 17:17:20 2006
@@ -116,7 +116,15 @@
         // AddResponse ::= [APPLICATION 9] LDAPResult (Value)
         // Ok, we have a LDAPResult Tag (0x0A). So we have to switch the grammar.
         super.transitions[LdapStatesEnum.ADD_RESPONSE_LDAP_RESULT][UniversalTag.ENUMERATED_TAG]
= new GrammarTransition(
-                LdapStatesEnum.ADD_RESPONSE_LDAP_RESULT, LdapStatesEnum.LDAP_RESULT_GRAMMAR_SWITCH,
null );
+                LdapStatesEnum.ADD_RESPONSE_LDAP_RESULT, LdapStatesEnum.LDAP_RESULT_GRAMMAR_SWITCH,

+                new GrammarAction( "Store Ldap Result referral" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+                        container.grammarPopAllowed( true );
+                    }
+                    
+                });
     }
 
     //~ Methods ------------------------------------------------------------------------------------

Modified: directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/add/AddRequestTest.java
URL: http://svn.apache.org/viewcvs/directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/add/AddRequestTest.java?rev=372687&r1=372686&r2=372687&view=diff
==============================================================================
--- directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/add/AddRequestTest.java
(original)
+++ directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/add/AddRequestTest.java
Thu Jan 26 17:17:20 2006
@@ -19,6 +19,7 @@
 import java.nio.ByteBuffer;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.List;
 
 import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
@@ -29,6 +30,7 @@
 import org.apache.asn1.codec.EncoderException;
 import org.apache.asn1.ber.Asn1Decoder;
 import org.apache.asn1.ber.IAsn1Container;
+import org.apache.ldap.common.codec.Control;
 import org.apache.ldap.common.codec.LdapDecoder;
 import org.apache.ldap.common.codec.LdapMessage;
 import org.apache.ldap.common.codec.LdapMessageContainer;
@@ -180,12 +182,12 @@
     {
         Asn1Decoder ldapDecoder = new LdapDecoder();
 
-        ByteBuffer  stream      = ByteBuffer.allocate( 0x39 );
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x07 );
         
         stream.put(
             new byte[]
             {
-                0x30, 0x37, 		// LDAPMessage ::= SEQUENCE {
+                0x30, 0x05, 		// LDAPMessage ::= SEQUENCE {
 				  0x02, 0x01, 0x01, 	//     messageID MessageID
 				  0x68, 0x00 		//     CHOICE { ..., addRequest   AddRequest, ...
             } );
@@ -552,6 +554,107 @@
         // Check the length
         assertEquals(0x34, message.computeLength());
 	    
+        // Check the encoding
+        try
+        {
+            ByteBuffer bb = message.encode( null );
+            
+            String encodedPdu = StringTools.dumpBytes( bb.array() ); 
+            
+            assertEquals(encodedPdu, decodedPdu );
+        }
+        catch ( EncoderException ee )
+        {
+            ee.printStackTrace();
+            fail( ee.getMessage() );
+        }
+    }
+
+    /**
+     * Test the decoding of a AddRequest with a empty attributeList and a control
+     */
+    public void testDecodeAddRequestEmptyAttributeValueWithControl() throws NamingException
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x51 );
+        
+        stream.put(
+            new byte[]
+            {
+                0x30, 0x4F,                // LDAPMessage ::= SEQUENCE {
+                  0x02, 0x01, 0x01,        //     messageID MessageID
+                  0x68, 0x2D,              //     CHOICE { ..., addRequest   AddRequest,
...
+                                           // AddRequest ::= [APPLICATION 8] SEQUENCE {
+                                           //     entry           LDAPDN,
+                    0x04, 0x20, 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f',
'y', ',', 'o', 'u', '=', 'u', 's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't',
'e', 'm',
+                                           //     attributes      AttributeList }
+                    0x30, 0x09,            // AttributeList ::= SEQUENCE OF SEQUENCE {
+                      0x30, 0x07,          // attribute 1
+                        0x04, 0x01, 'l',   //     type    AttributeDescription,
+                        0x31, 0x02,
+                          0x04, 0x00,
+                  (byte)0xA0, 0x1B,     // A control 
+                    0x30, 0x19, 
+                      0x04, 0x17, 
+                        0x32, 0x2E, 0x31, 0x36, 0x2E, 0x38, 0x34, 0x30, 
+                        0x2E, 0x31, 0x2E, 0x31, 0x31, 0x33, 0x37, 0x33, 
+                        0x30, 0x2E, 0x33, 0x2E, 0x34, 0x2E, 0x32
+            } );
+
+        String decodedPdu = StringTools.dumpBytes( stream.array() );
+        stream.flip();
+
+        // Allocate a LdapMessage Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        // Decode a AddRequest message
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            fail( de.getMessage() );
+        }
+        
+        LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+        AddRequest addRequest      = message.getAddRequest();
+
+        // Check the decoded message
+        assertEquals( 1, message.getMessageId() );
+        assertEquals( "cn=testModify,ou=users,ou=system", addRequest.getEntry() );
+
+        Attributes attributes = addRequest.getAttributes();
+        
+        assertEquals( 1, attributes.size() );
+        
+        BasicAttribute attributeValue = (BasicAttribute)attributes.get( "l" );
+            
+        assertEquals( "l", attributeValue.getID().toLowerCase() );
+            
+        NamingEnumeration values = attributeValue.getAll();
+        
+        while ( values.hasMore() )
+        {
+            Object value = values.next();
+            
+            assertEquals( "", value.toString() );
+        }
+
+        // Check the length
+        assertEquals(0x51, message.computeLength());
+        
+        // Check the Control
+        List controls = message.getControls();
+        
+        assertEquals( 1, controls.size() );
+        
+        Control control = message.getControls( 0 );
+        assertEquals( "2.16.840.1.113730.3.4.2", control.getControlType() );
+        assertEquals( "", StringTools.dumpBytes( (byte[])control.getControlValue() ) );
+        
         // Check the encoding
         try
         {

Modified: directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/add/AddResponseTest.java
URL: http://svn.apache.org/viewcvs/directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/add/AddResponseTest.java?rev=372687&r1=372686&r2=372687&view=diff
==============================================================================
--- directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/add/AddResponseTest.java
(original)
+++ directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/add/AddResponseTest.java
Thu Jan 26 17:17:20 2006
@@ -17,11 +17,13 @@
 package org.apache.ldap.common.codec.add;
 
 import java.nio.ByteBuffer;
+import java.util.List;
 
 import org.apache.asn1.codec.DecoderException;
 import org.apache.asn1.codec.EncoderException;
 import org.apache.asn1.ber.Asn1Decoder;
 import org.apache.asn1.ber.IAsn1Container;
+import org.apache.ldap.common.codec.Control;
 import org.apache.ldap.common.codec.LdapDecoder;
 import org.apache.ldap.common.codec.LdapMessage;
 import org.apache.ldap.common.codec.LdapMessageContainer;
@@ -139,5 +141,90 @@
         }
     	
         fail( "We should not reach this point" );
+    }
+
+    /**
+     * Test the decoding of a AddResponse with a control
+     */
+    public void testDecodeAddResponseSuccessWithControl()
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x2B );
+        
+        stream.put(
+            new byte[]
+            {
+                0x30, 0x29,          // LDAPMessage ::=SEQUENCE {
+                  0x02, 0x01, 0x01,  //         messageID MessageID
+                  0x69, 0x07,        //        CHOICE { ..., addResponse AddResponse, ...
+                                     // AddResponse ::= [APPLICATION 9] LDAPResult
+                    0x0A, 0x01, 0x00,//   LDAPResult ::= SEQUENCE {
+                                     //      resultCode ENUMERATED {
+                                     //          success (0), ...
+                                     //      },
+                    0x04, 0x00,      //      matchedDN    LDAPDN,
+                    0x04, 0x00,      //      errorMessage LDAPString,
+                                     //      referral     [3] Referral OPTIONAL }
+                                     // }
+                  (byte)0xA0, 0x1B,  // A control 
+                    0x30, 0x19, 
+                      0x04, 0x17, 
+                        0x32, 0x2E, 0x31, 0x36, 0x2E, 0x38, 0x34, 0x30, 
+                        0x2E, 0x31, 0x2E, 0x31, 0x31, 0x33, 0x37, 0x33, 
+                        0x30, 0x2E, 0x33, 0x2E, 0x34, 0x2E, 0x32
+            } );
+
+        String decodedPdu = StringTools.dumpBytes( stream.array() );
+        stream.flip();
+
+        // Allocate a LdapMessage Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        // Decode the AddResponse PDU
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            fail( de.getMessage() );
+        }
+        
+        // Check the decoded AddResponse
+        LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+        AddResponse addResponse      = message.getAddResponse();
+        
+        assertEquals( 1, message.getMessageId() );
+        assertEquals( 0, addResponse.getLdapResult().getResultCode() );
+        assertEquals( "", addResponse.getLdapResult().getMatchedDN() );
+        assertEquals( "", addResponse.getLdapResult().getErrorMessage() );
+
+        // Check the length
+        assertEquals(0x2B, message.computeLength());
+        
+        // Check the Control
+        List controls = message.getControls();
+        
+        assertEquals( 1, controls.size() );
+        
+        Control control = message.getControls( 0 );
+        assertEquals( "2.16.840.1.113730.3.4.2", control.getControlType() );
+        assertEquals( "", StringTools.dumpBytes( (byte[])control.getControlValue() ) );
+
+        try
+        {
+            ByteBuffer bb = message.encode( null );
+            
+            String encodedPdu = StringTools.dumpBytes( bb.array() ); 
+            
+            assertEquals(encodedPdu, decodedPdu );
+        }
+        catch ( EncoderException ee )
+        {
+            ee.printStackTrace();
+            fail( ee.getMessage() );
+        }
     }
 }



Mime
View raw message