directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r373035 - in /directory/trunks/common/ldap/src: main/java/org/apache/ldap/common/codec/extended/ExtendedResponseGrammar.java test/java/org/apache/ldap/common/codec/extended/ExtendedResponseTest.java
Date Fri, 27 Jan 2006 23:50:24 GMT
Author: elecharny
Date: Fri Jan 27 15:50:15 2006
New Revision: 373035

URL: http://svn.apache.org/viewcvs?rev=373035&view=rev
Log:
- Added the missing pop transitions
- Added three tests

Modified:
    directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/extended/ExtendedResponseGrammar.java
    directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/extended/ExtendedResponseTest.java

Modified: directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/extended/ExtendedResponseGrammar.java
URL: http://svn.apache.org/viewcvs/directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/extended/ExtendedResponseGrammar.java?rev=373035&r1=373034&r2=373035&view=diff
==============================================================================
--- directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/extended/ExtendedResponseGrammar.java
(original)
+++ directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/extended/ExtendedResponseGrammar.java
Fri Jan 27 15:50:15 2006
@@ -100,7 +100,14 @@
         // The current state will be stored.
         super.transitions[LdapStatesEnum.EXTENDED_RESPONSE_LDAP_RESULT][UniversalTag.ENUMERATED_TAG]
= new GrammarTransition(
                 LdapStatesEnum.EXTENDED_RESPONSE_LDAP_RESULT,
-                LdapStatesEnum.LDAP_RESULT_GRAMMAR_SWITCH, null );
+                LdapStatesEnum.LDAP_RESULT_GRAMMAR_SWITCH, 
+                new GrammarAction( "Pop allowed" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+                        container.grammarPopAllowed( true );
+                    }
+                });
 
         // ExtendedResponse ::= [APPLICATION 24] SEQUENCE {
         //     ...
@@ -148,6 +155,9 @@
 	                        // We can have an END transition
 	                        ldapMessageContainer.grammarEndAllowed( true );
 
+                            // We can have a Pop transition
+                            ldapMessageContainer.grammarPopAllowed( true );
+
 	                        if ( log.isDebugEnabled() )
                             {
                                 log.debug( "OID read : {}", extendedResponse.getResponseName()
);
@@ -197,6 +207,9 @@
                         
                         // We can have an END transition
                         ldapMessageContainer.grammarEndAllowed( true );
+
+                        // We can have a Pop transition
+                        ldapMessageContainer.grammarPopAllowed( true );
 
                         if ( log.isDebugEnabled() )
                         {

Modified: directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/extended/ExtendedResponseTest.java
URL: http://svn.apache.org/viewcvs/directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/extended/ExtendedResponseTest.java?rev=373035&r1=373034&r2=373035&view=diff
==============================================================================
--- directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/extended/ExtendedResponseTest.java
(original)
+++ directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/extended/ExtendedResponseTest.java
Fri Jan 27 15:50:15 2006
@@ -17,6 +17,7 @@
 package org.apache.ldap.common.codec.extended;
 
 import java.nio.ByteBuffer;
+import java.util.List;
 
 import javax.naming.NamingException;
 
@@ -24,6 +25,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;
@@ -116,9 +118,101 @@
     }
 
     /**
-     * Test the decoding of a ExtendedRequest with only a name
+     * Test the decoding of a full ExtendedResponse with controls
      */
-    public void testDecodeExtendedRequestName() throws NamingException
+    public void testDecodeExtendedResponseSuccessWithControls() throws NamingException
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x41 );
+        
+        stream.put(
+            new byte[]
+            {
+                0x30, 0x3F,         // LDAPMessage ::= SEQUENCE {
+                  0x02, 0x01, 0x01, //     messageID MessageID
+                                    //     CHOICE { ..., extendedResp     ExtendedResponse,
...
+                  0x78, 0x1D,       // ExtendedResponse ::= [APPLICATION 23] SEQUENCE {
+                                    //     COMPONENTS OF LDAPResult,
+                    0x0A, 0x01, 0x00,   //   LDAPResult ::= SEQUENCE {
+                                    //      resultCode ENUMERATED {
+                                    //          success (0), ...
+                                    //      },
+                    0x04, 0x00,     //      matchedDN    LDAPDN,
+                    0x04, 0x00,     //      errorMessage LDAPString,
+                                    //      referral     [3] Referral OPTIONAL }        
                           
+                                    //    responseName     [10] LDAPOID OPTIONAL,
+                    (byte)0x8A, 0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5',
'.', '2',
+                                    //    response         [11] OCTET STRING OPTIONAL }
+                    (byte)0x8B, 0x05, 'v', 'a', 'l', 'u', 'e',
+                  (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 ExtendedResponse PDU
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            fail( de.getMessage() );
+        }
+        
+        // Check the decoded ExtendedResponse PDU
+        LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+        ExtendedResponse extendedResponse      = message.getExtendedResponse();
+
+        assertEquals( 1, message.getMessageId() );
+        assertEquals( 0, extendedResponse.getLdapResult().getResultCode() );
+        assertEquals( "", extendedResponse.getLdapResult().getMatchedDN() );
+        assertEquals( "", extendedResponse.getLdapResult().getErrorMessage() );
+        assertEquals( "1.3.6.1.5.5.2", extendedResponse.getResponseName() );
+        assertEquals( "value", StringTools.utf8ToString( (byte[])extendedResponse.getResponse()
) );
+        
+        // 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 length
+        assertEquals(0x41, 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 ExtendedRequest with no name
+     */
+    public void testDecodeExtendedRequestNoName() throws NamingException
     {
         Asn1Decoder ldapDecoder = new LdapDecoder();
 
@@ -188,6 +282,93 @@
     }
     
     /**
+     * Test the decoding of a ExtendedRequest with no name and a control
+     */
+    public void testDecodeExtendedRequestNoNameWithControls() throws NamingException
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x2B );
+        
+        stream.put(
+            new byte[]
+            {
+                    0x30, 0x29,           // LDAPMessage ::= SEQUENCE {
+                      0x02, 0x01, 0x01,   //     messageID MessageID
+                                          //     CHOICE { ..., extendedResp     Response,
...
+                      0x78, 0x07,         // ExtendedResponse ::= [APPLICATION 24] SEQUENCE
{
+                                          //     COMPONENTS OF LDAPResult,
+                        0x0A, 0x01, 0x00, //   LDAPResult ::= SEQUENCE {
+                                          //      resultCode ENUMERATED {
+                                          //          success (0), ...
+                                          //      },
+                        0x04, 0x00,       //      matchedDN    LDAPDN,
+                        0x04, 0x00,       //      errorMessage LDAPString,
+                                          //      referral     [3] Referral OPTIONAL }  
                                 
+                                          //   responseName      [0] LDAPOID,
+                      (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 ExtendedResponse PDU
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            fail( de.getMessage() );
+        }
+        
+        // Check the decoded ExtendedResponse PDU
+        LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+        ExtendedResponse extendedResponse      = message.getExtendedResponse();
+
+        assertEquals( 1, message.getMessageId() );
+        assertEquals( 0, extendedResponse.getLdapResult().getResultCode() );
+        assertEquals( "", extendedResponse.getLdapResult().getMatchedDN() );
+        assertEquals( "", extendedResponse.getLdapResult().getErrorMessage() );
+
+        // 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 length
+        assertEquals(0x2B, 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 an empty ExtendedResponse
      */
     public void testDecodeExtendedResponseEmpty() throws NamingException
@@ -388,6 +569,96 @@
     }
 
     /**
+     * Test the decoding of an ExtendedResponse with no response with controls
+     */
+    public void testDecodeExtendedResponseNoResponseWithControls() throws NamingException
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x3A );
+        
+        stream.put(
+            new byte[]
+            {
+                    0x30, 0x38,           // LDAPMessage ::= SEQUENCE {
+                      0x02, 0x01, 0x01,   //     messageID MessageID
+                                          //     CHOICE { ..., extendedResp     Response,
...
+                      0x78, 0x16,         // ExtendedResponse ::= [APPLICATION 24] SEQUENCE
{
+                                          //     COMPONENTS OF LDAPResult,
+                        0x0A, 0x01, 0x00, //   LDAPResult ::= SEQUENCE {
+                                          //      resultCode ENUMERATED {
+                                          //          success (0), ...
+                                          //      },
+                        0x04, 0x00,       //      matchedDN    LDAPDN,
+                        0x04, 0x00,       //      errorMessage LDAPString,
+                                          //      referral     [3] Referral OPTIONAL }  
                                 
+                                          //   responseName      [0] LDAPOID,
+                        (byte)0x8A, 0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.',
'5', '.', '2',
+                      (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 ExtendedResponse PDU
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            fail( de.getMessage() );
+        }
+        
+        // Check the decoded ExtendedResponse PDU
+        LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+        ExtendedResponse extendedResponse      = message.getExtendedResponse();
+
+        assertEquals( 1, message.getMessageId() );
+        assertEquals( 0, extendedResponse.getLdapResult().getResultCode() );
+        assertEquals( "", extendedResponse.getLdapResult().getMatchedDN() );
+        assertEquals( "", extendedResponse.getLdapResult().getErrorMessage() );
+        assertEquals( "1.3.6.1.5.5.2", extendedResponse.getResponseName() );
+        assertEquals( "", StringTools.utf8ToString( (byte[])extendedResponse.getResponse()
) );
+
+        // 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 length
+        assertEquals(0x3A, 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 an ExtendedResponse with an empty response
      */
     public void testDecodeExtendedResponseEmptyResponse() throws NamingException
@@ -446,6 +717,98 @@
 
         // Check the length
         assertEquals(0x1F, 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 an ExtendedResponse with an empty response
+     * with controls
+     */
+    public void testDecodeExtendedResponseEmptyResponseWithControls() throws NamingException
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x3C );
+        
+        stream.put(
+            new byte[]
+            {
+                    0x30, 0x3A,         // LDAPMessage ::= SEQUENCE {
+                      0x02, 0x01, 0x01, //     messageID MessageID
+                                        //     CHOICE { ..., extendedResp     Response, ...
+                      0x78, 0x18,       // ExtendedResponse ::= [APPLICATION 24] SEQUENCE
{
+                                        //     COMPONENTS OF LDAPResult,
+                        0x0A, 0x01, 0x00,   //   LDAPResult ::= SEQUENCE {
+                                        //      resultCode ENUMERATED {
+                                        //          success (0), ...
+                                        //      },
+                        0x04, 0x00,     //      matchedDN    LDAPDN,
+                        0x04, 0x00,     //      errorMessage LDAPString,
+                                        //      referral     [3] Referral OPTIONAL }    
                               
+                                        //   responseName      [0] LDAPOID,
+                        (byte)0x8A, 0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.',
'5', '.', '2',
+                        (byte)0x8B, 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 the ExtendedResponse PDU
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            fail( de.getMessage() );
+        }
+        
+        // Check the decoded ExtendedResponse PDU
+        LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+        ExtendedResponse extendedResponse      = message.getExtendedResponse();
+
+        assertEquals( 1, message.getMessageId() );
+        assertEquals( 0, extendedResponse.getLdapResult().getResultCode() );
+        assertEquals( "", extendedResponse.getLdapResult().getMatchedDN() );
+        assertEquals( "", extendedResponse.getLdapResult().getErrorMessage() );
+        assertEquals( "1.3.6.1.5.5.2", extendedResponse.getResponseName() );
+        assertEquals( "", StringTools.utf8ToString( (byte[])extendedResponse.getResponse()
) );
+
+        // 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 length
+        assertEquals(0x3C, message.computeLength());
 
         // Check the encoding
         try



Mime
View raw message