directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r369842 - in /directory/trunks/common/ldap/src: main/java/org/apache/ldap/common/codec/extended/ test/java/org/apache/ldap/common/codec/extended/
Date Tue, 17 Jan 2006 17:16:48 GMT
Author: elecharny
Date: Tue Jan 17 09:16:12 2006
New Revision: 369842

URL: http://svn.apache.org/viewcvs?rev=369842&view=rev
Log:
- Added some tests case
- Removed useless Assert prefix
- Modified logs
- Fixed a bug in OID conversion

Modified:
    directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/extended/ExtendedRequest.java
    directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/extended/ExtendedRequestGrammar.java
    directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/extended/ExtendedResponse.java
    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/ExtendedRequestTest.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/ExtendedRequest.java
URL: http://svn.apache.org/viewcvs/directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/extended/ExtendedRequest.java?rev=369842&r1=369841&r2=369842&view=diff
==============================================================================
--- directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/extended/ExtendedRequest.java
(original)
+++ directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/extended/ExtendedRequest.java
Tue Jan 17 09:16:12 2006
@@ -24,6 +24,7 @@
 import org.apache.asn1.ber.tlv.Length;
 import org.apache.ldap.common.codec.LdapConstants;
 import org.apache.ldap.common.codec.LdapMessage;
+import org.apache.ldap.common.util.StringTools;
 
 
 /**
@@ -46,6 +47,9 @@
 
     /** The extended request length */
     private transient int extendedRequestLength;
+    
+    /** The OID length */
+    private transient int oidLength;
 
     //~ Constructors -------------------------------------------------------------------------------
 
@@ -126,7 +130,8 @@
      */
     public int computeLength()
     {
-        extendedRequestLength = 1 + Length.getNbBytes( requestName.getOIDLength() ) + requestName.getOIDLength();
+        oidLength = requestName.toString().length();
+        extendedRequestLength = 1 + Length.getNbBytes( oidLength ) + oidLength;
 
         if ( requestValue != null)
         {
@@ -167,11 +172,11 @@
             }
 
             buffer.put( (byte)LdapConstants.EXTENDED_REQUEST_NAME_TAG );
-            buffer.put( Length.getBytes( requestName.getOIDLength() ) );
+            buffer.put( Length.getBytes( oidLength ) );
 
             if ( requestName.getOIDLength() != 0 )
             {
-                buffer.put( requestName.getOID() );
+                buffer.put( StringTools.getBytesUtf8( requestName.toString() ) );
             }
 
             // The requestValue, if any

Modified: directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/extended/ExtendedRequestGrammar.java
URL: http://svn.apache.org/viewcvs/directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/extended/ExtendedRequestGrammar.java?rev=369842&r1=369841&r2=369842&view=diff
==============================================================================
--- directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/extended/ExtendedRequestGrammar.java
(original)
+++ directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/extended/ExtendedRequestGrammar.java
Tue Jan 17 09:16:12 2006
@@ -28,6 +28,7 @@
 import org.apache.ldap.common.codec.LdapMessage;
 import org.apache.ldap.common.codec.LdapMessageContainer;
 import org.apache.ldap.common.codec.LdapStatesEnum;
+import org.apache.ldap.common.util.StringTools;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -130,7 +131,7 @@
                         }
                         else
                         {
-                            extendedRequest.setRequestName( new OID( tlv.getValue().getData()
) );
+                            extendedRequest.setRequestName( new OID( StringTools.utf8ToString(
tlv.getValue().getData() ) ) );
                         }
 
                         // We can have an END transition

Modified: directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/extended/ExtendedResponse.java
URL: http://svn.apache.org/viewcvs/directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/extended/ExtendedResponse.java?rev=369842&r1=369841&r2=369842&view=diff
==============================================================================
--- directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/extended/ExtendedResponse.java
(original)
+++ directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/extended/ExtendedResponse.java
Tue Jan 17 09:16:12 2006
@@ -49,6 +49,9 @@
     /** The extended response length */
     private transient int extendedResponseLength;
 
+    /** The OID length */
+    private transient int responseNameLength;
+
     //~ Constructors -------------------------------------------------------------------------------
 
     /**
@@ -131,13 +134,12 @@
     */
     public int computeLength()
     {
-
         extendedResponseLength = super.computeLength();
 
         if ( responseName != null )
         {
-            extendedResponseLength += 1 + Length.getNbBytes( responseName.getOIDLength()
) +
-            responseName.getOIDLength();
+            responseNameLength = responseName.toString().length();
+            extendedResponseLength += 1 + Length.getNbBytes( responseNameLength ) + responseNameLength;
 
             if ( response != null )
             {
@@ -188,11 +190,11 @@
             if ( responseName != null )
             {
                 buffer.put( (byte) LdapConstants.EXTENDED_RESPONSE_RESPONSE_NAME_TAG );
-                buffer.put( Length.getBytes( responseName.getOIDLength() ) );
+                buffer.put( Length.getBytes( responseNameLength ) );
 
                 if ( responseName.getOIDLength() != 0 )
                 {
-                    buffer.put( responseName.getOID() );
+                    buffer.put( StringTools.getBytesUtf8( responseName.toString() ) );
                 }
             }
 

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=369842&r1=369841&r2=369842&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
Tue Jan 17 09:16:12 2006
@@ -29,6 +29,7 @@
 import org.apache.ldap.common.codec.LdapMessage;
 import org.apache.ldap.common.codec.LdapMessageContainer;
 import org.apache.ldap.common.codec.LdapStatesEnum;
+import org.apache.ldap.common.util.StringTools;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -141,7 +142,7 @@
 			                }
 			                else
 			                {
-			                    extendedResponse.setResponseName( new OID( tlv.getValue().getData()
) );
+			                    extendedResponse.setResponseName( new OID( StringTools.utf8ToString(
tlv.getValue().getData() ) ) );
 			                }
                             
 	                        // We can have an END transition

Modified: directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/extended/ExtendedRequestTest.java
URL: http://svn.apache.org/viewcvs/directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/extended/ExtendedRequestTest.java?rev=369842&r1=369841&r2=369842&view=diff
==============================================================================
--- directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/extended/ExtendedRequestTest.java
(original)
+++ directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/extended/ExtendedRequestTest.java
Tue Jan 17 09:16:12 2006
@@ -45,19 +45,19 @@
     {
         Asn1Decoder ldapDecoder = new LdapDecoder();
 
-        ByteBuffer  stream      = ByteBuffer.allocate( 0x16 );
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x1D );
         
         stream.put(
             new byte[]
             {
-                0x30, 0x14, 		// LDAPMessage ::= SEQUENCE {
-				0x02, 0x01, 0x01, 	//     messageID MessageID
+                0x30, 0x1B, 		// LDAPMessage ::= SEQUENCE {
+				  0x02, 0x01, 0x01, //     messageID MessageID
 				            		//     CHOICE { ..., extendedReq     ExtendedRequest, ...
-				0x77, 0x0F,         // ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
+				  0x77, 0x16,       // ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
 				                    //     requestName      [0] LDAPOID,
-				(byte)0x80, 0x06, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x02,
+                    (byte)0x80, 0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5',
'.', '2',
 				                    //     requestValue     [1] OCTET STRING OPTIONAL }
-				(byte)0x81, 0x05, 'v', 'a', 'l', 'u', 'e'
+				    (byte)0x81, 0x05, 'v', 'a', 'l', 'u', 'e'
             } );
 
         String decodedPdu = StringTools.dumpBytes( stream.array() );
@@ -86,7 +86,7 @@
         assertEquals( "value", StringTools.utf8ToString( extendedRequest.getRequestValue()
) );
         
         // Check the length
-        assertEquals(0x16, message.computeLength());
+        assertEquals(0x1D, message.computeLength());
 
         // Check the encoding
         try
@@ -182,17 +182,17 @@
     {
         Asn1Decoder ldapDecoder = new LdapDecoder();
 
-        ByteBuffer  stream      = ByteBuffer.allocate( 0x0F );
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x16 );
         
         stream.put(
             new byte[]
             {
-                0x30, 0x0D, 		// LDAPMessage ::= SEQUENCE {
-				0x02, 0x01, 0x01, 	//     messageID MessageID
+                0x30, 0x14, 		// LDAPMessage ::= SEQUENCE {
+				  0x02, 0x01, 0x01, 	//     messageID MessageID
 				            		//     CHOICE { ..., extendedReq     ExtendedRequest, ...
-				0x77, 0x08,         // ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
+				  0x77, 0x0F,         // ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
 				                    //     requestName      [0] LDAPOID,
-				(byte)0x80, 0x06, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x02,
+				    (byte)0x80, 0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '2',

             } );
 
         String decodedPdu = StringTools.dumpBytes( stream.array() );
@@ -220,7 +220,7 @@
         assertEquals( "1.3.6.1.5.5.2", extendedRequest.getRequestName() );
         
         // Check the length
-        assertEquals(0x0F, message.computeLength());
+        assertEquals(0x16, message.computeLength());
 
         // Check the encoding
         try
@@ -245,17 +245,17 @@
     {
         Asn1Decoder ldapDecoder = new LdapDecoder();
 
-        ByteBuffer  stream      = ByteBuffer.allocate( 0x11 );
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x18 );
         
         stream.put(
             new byte[]
             {
-                0x30, 0x0F, 		// LDAPMessage ::= SEQUENCE {
-				  0x02, 0x01, 0x01, 	//     messageID MessageID
+                0x30, 0x16, 		// LDAPMessage ::= SEQUENCE {
+				  0x02, 0x01, 0x01, //     messageID MessageID
 				            		//     CHOICE { ..., extendedReq     ExtendedRequest, ...
-				  0x77, 0x0A,         // ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
+				  0x77, 0x11,       // ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
 				                    //     requestName      [0] LDAPOID,
-				    (byte)0x80, 0x06, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x02,
+                    (byte)0x80, 0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5',
'.', '2',
 				    (byte)0x81, 0x00
             } );
 
@@ -285,7 +285,7 @@
         assertEquals( "", StringTools.utf8ToString( extendedRequest.getRequestValue() ) );
         
         // Check the length
-        assertEquals(0x11, message.computeLength());
+        assertEquals(0x18, message.computeLength());
 
         // Check the encoding
         try

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=369842&r1=369841&r2=369842&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
Tue Jan 17 09:16:12 2006
@@ -30,7 +30,6 @@
 import org.apache.ldap.common.codec.extended.ExtendedResponse;
 import org.apache.ldap.common.util.StringTools;
 
-import junit.framework.Assert;
 import junit.framework.TestCase;
 
 /**
@@ -46,27 +45,27 @@
     {
         Asn1Decoder ldapDecoder = new LdapDecoder();
 
-        ByteBuffer  stream      = ByteBuffer.allocate( 0x1D );
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x24 );
         
         stream.put(
             new byte[]
             {
-                0x30, 0x1B, 		// LDAPMessage ::= SEQUENCE {
-				0x02, 0x01, 0x01, 	//     messageID MessageID
+                0x30, 0x22, 		// LDAPMessage ::= SEQUENCE {
+				  0x02, 0x01, 0x01, //     messageID MessageID
 				            		//     CHOICE { ..., extendedResp     ExtendedResponse, ...
-				0x78, 0x16,         // ExtendedResponse ::= [APPLICATION 23] SEQUENCE {
+				  0x78, 0x1D,       // ExtendedResponse ::= [APPLICATION 23] SEQUENCE {
 				                    //     COMPONENTS OF LDAPResult,
-				0x0A, 0x01, 0x00, 	//   LDAPResult ::= SEQUENCE {
+				    0x0A, 0x01, 0x00, 	//   LDAPResult ::= SEQUENCE {
 				                    //		resultCode ENUMERATED {
 				                    //			success (0), ...
 					                //      },
-				0x04, 0x00,			//		matchedDN    LDAPDN,
-				0x04, 0x00,  		//      errorMessage LDAPString,
-				                    //		referral     [3] Referral OPTIONAL }				                    //
    requestName      [0] LDAPOID,
+				    0x04, 0x00,		//		matchedDN    LDAPDN,
+				    0x04, 0x00,  	//      errorMessage LDAPString,
+				                    //		referral     [3] Referral OPTIONAL }				                    
 				                    //    responseName     [10] LDAPOID OPTIONAL,
-				(byte)0x8A, 0x06, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x02,
+				    (byte)0x8A, 0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '2',
 				                    //    response         [11] OCTET STRING OPTIONAL }
-				(byte)0x8B, 0x05, 'v', 'a', 'l', 'u', 'e'
+				    (byte)0x8B, 0x05, 'v', 'a', 'l', 'u', 'e'
             } );
 
         String decodedPdu = StringTools.dumpBytes( stream.array() );
@@ -83,22 +82,22 @@
         catch ( DecoderException de )
         {
             de.printStackTrace();
-            Assert.fail( de.getMessage() );
+            fail( de.getMessage() );
         }
     	
         // Check the decoded ExtendedResponse PDU
         LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
         ExtendedResponse extendedResponse      = message.getExtendedResponse();
 
-        Assert.assertEquals( 1, message.getMessageId() );
-        Assert.assertEquals( 0, extendedResponse.getLdapResult().getResultCode() );
-        Assert.assertEquals( "", extendedResponse.getLdapResult().getMatchedDN() );
-        Assert.assertEquals( "", extendedResponse.getLdapResult().getErrorMessage() );
-        Assert.assertEquals( "1.3.6.1.5.5.2", extendedResponse.getResponseName() );
-        Assert.assertEquals( "value", StringTools.utf8ToString( (byte[])extendedResponse.getResponse()
) );
+        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 length
-        Assert.assertEquals(0x1D, message.computeLength());
+        assertEquals(0x24, message.computeLength());
         
         // Check the encoding
         try
@@ -107,12 +106,12 @@
             
             String encodedPdu = StringTools.dumpBytes( bb.array() ); 
             
-            Assert.assertEquals(encodedPdu, decodedPdu );
+            assertEquals(encodedPdu, decodedPdu );
         }
         catch ( EncoderException ee )
         {
             ee.printStackTrace();
-            Assert.fail( ee.getMessage() );
+            fail( ee.getMessage() );
         }
     }
 
@@ -139,7 +138,8 @@
     					                //      },
     				0x04, 0x00,			//		matchedDN    LDAPDN,
     				0x04, 0x00  		//      errorMessage LDAPString,
-    				                    //		referral     [3] Referral OPTIONAL }				                
   //     requestName      [0] LDAPOID,
+    				                    //		referral     [3] Referral OPTIONAL }				                
   
+                                        //   responseName      [0] LDAPOID,
             } );
 
         String decodedPdu = StringTools.dumpBytes( stream.array() );
@@ -156,20 +156,296 @@
         catch ( DecoderException de )
         {
             de.printStackTrace();
-            Assert.fail( de.getMessage() );
+            fail( de.getMessage() );
         }
     	
         // Check the decoded ExtendedResponse PDU
         LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
         ExtendedResponse extendedResponse      = message.getExtendedResponse();
 
-        Assert.assertEquals( 1, message.getMessageId() );
-        Assert.assertEquals( 0, extendedResponse.getLdapResult().getResultCode() );
-        Assert.assertEquals( "", extendedResponse.getLdapResult().getMatchedDN() );
-        Assert.assertEquals( "", extendedResponse.getLdapResult().getErrorMessage() );
+        assertEquals( 1, message.getMessageId() );
+        assertEquals( 0, extendedResponse.getLdapResult().getResultCode() );
+        assertEquals( "", extendedResponse.getLdapResult().getMatchedDN() );
+        assertEquals( "", extendedResponse.getLdapResult().getErrorMessage() );
+
+        // Check the length
+        assertEquals(0x0E, 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
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x07 );
+        
+        stream.put(
+            new byte[]
+            {
+                    0x30, 0x05, 		// LDAPMessage ::= SEQUENCE {
+    				  0x02, 0x01, 0x01, //     messageID MessageID
+    				            		//     CHOICE { ..., extendedResp     Response, ...
+    				  0x78, 0x00        // ExtendedResponse ::= [APPLICATION 24] SEQUENCE {
+            } );
+
+        stream.flip();
+
+        // Allocate a LdapMessage Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        // Decode a DelRequest PDU
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+            fail("We should never reach this point !!!");
+        }
+        catch ( DecoderException de )
+        {
+            assertTrue( true );
+        }
+    }
+    
+    /**
+     * Test the decoding of an ExtendedResponse with an empty ResponseName
+     */
+    public void testDecodeExtendedResponseEmptyResponseName() throws NamingException
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x10 );
+        
+        stream.put(
+            new byte[]
+            {
+                    0x30, 0x0E, 		// LDAPMessage ::= SEQUENCE {
+    				  0x02, 0x01, 0x01, //     messageID MessageID
+    				            		//     CHOICE { ..., extendedResp     Response, ...
+    				  0x78, 0x09,       // 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, 0x00
+            } );
+
+        stream.flip();
+
+        // Allocate a LdapMessage Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        // Decode a DelRequest PDU
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+            fail("We should never reach this point !!!");
+        }
+        catch ( DecoderException de )
+        {
+            assertTrue( true );
+        }
+    }
+
+    /**
+     * Test the decoding of an ExtendedResponse with a bad responseName
+     */
+    public void testDecodeExtendedResponseBadOIDResponseName() throws NamingException
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x12 );
+        
+        stream.put(
+            new byte[]
+            {
+                    0x30, 0x10,         // LDAPMessage ::= SEQUENCE {
+                      0x02, 0x01, 0x01, //     messageID MessageID
+                                        //     CHOICE { ..., extendedResp     Response, ...
+                      0x78, 0x0B,       // 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, 0x02, 'a', 'b'
+            } );
+
+        stream.flip();
+
+        // Allocate a LdapMessage Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        // Decode a DelRequest PDU
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+            fail("We should never reach this point !!!");
+        }
+        catch ( DecoderException de )
+        {
+            assertTrue( true );
+        }
+    }
+
+    /**
+     * Test the decoding of an ExtendedResponse with no response
+     */
+    public void testDecodeExtendedResponseNoResponse() throws NamingException
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x1D );
+        
+        stream.put(
+            new byte[]
+            {
+                    0x30, 0x1B,         // 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',
+            } );
+
+        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 length
+        assertEquals(0x1D, 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
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x1F );
+        
+        stream.put(
+            new byte[]
+            {
+                    0x30, 0x1D,         // 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
+            } );
+
+        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 length
-        Assert.assertEquals(0x0E, message.computeLength());
+        assertEquals(0x1F, message.computeLength());
 
         // Check the encoding
         try
@@ -178,12 +454,12 @@
             
             String encodedPdu = StringTools.dumpBytes( bb.array() ); 
             
-            Assert.assertEquals(encodedPdu, decodedPdu );
+            assertEquals(encodedPdu, decodedPdu );
         }
         catch ( EncoderException ee )
         {
             ee.printStackTrace();
-            Assert.fail( ee.getMessage() );
+            fail( ee.getMessage() );
         }
     }
 }



Mime
View raw message