directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r438859 [3/4] - in /directory/trunks/shared/ldap: ./ src/main/java/org/apache/directory/shared/ldap/codec/ src/main/java/org/apache/directory/shared/ldap/codec/abandon/ src/main/java/org/apache/directory/shared/ldap/codec/add/ src/main/java...
Date Thu, 31 Aug 2006 10:33:48 GMT
Modified: directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/codec/modify/ModifyRequestTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/codec/modify/ModifyRequestTest.java?rev=438859&r1=438858&r2=438859&view=diff
==============================================================================
--- directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/codec/modify/ModifyRequestTest.java (original)
+++ directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/codec/modify/ModifyRequestTest.java Thu Aug 31 03:33:43 2006
@@ -36,7 +36,11 @@
 import org.apache.directory.shared.ldap.codec.LdapDecoder;
 import org.apache.directory.shared.ldap.codec.LdapMessage;
 import org.apache.directory.shared.ldap.codec.LdapMessageContainer;
+import org.apache.directory.shared.ldap.codec.ResponseCarryingException;
 import org.apache.directory.shared.ldap.codec.modify.ModifyRequest;
+import org.apache.directory.shared.ldap.message.Message;
+import org.apache.directory.shared.ldap.message.ModifyResponseImpl;
+import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.util.StringTools;
 
 import junit.framework.TestCase;
@@ -60,39 +64,38 @@
 
         stream.put( new byte[]
             {
-
-            0x30, 0x52, // LDAPMessage ::= SEQUENCE {
-                0x02, 0x01, 0x01, // messageID MessageID
-                0x66, 0x4d, // CHOICE { ..., modifyRequest ModifyRequest, ...
-                // ModifyRequest ::= [APPLICATION 6] SEQUENCE {
-                // object 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', 0x30, 0x29, // modification
-                                                                                                    // SEQUENCE
-                                                                                                    // OF
-                                                                                                    // SEQUENCE
-                                                                                                    // {
-                0x30, 0x11, 0x0A, 0x01, 0x02, // operation ENUMERATED {
-                // add (0),
-                // delete (1),
-                // replace (2) },
-                // modification AttributeTypeAndValues } }
-                0x30, 0x0c, // AttributeTypeAndValues ::= SEQUENCE {
-                0x04, 0x01, 'l', // type AttributeDescription,
-                0x31, 0x07, // vals SET OF AttributeValue }
-                0x04, 0x05, 'P', 'a', 'r', 'i', 's',
-
-                0x30, 0x14, // modification SEQUENCE OF *SEQUENCE* {
-                0x0A, 0x01, 0x00, // operation ENUMERATED {
-                // add (0),
-                // delete (1),
-                // replace (2) },
-                // modification AttributeTypeAndValues } }
-                0x30, 0x0f, // AttributeTypeAndValues ::= SEQUENCE {
-                0x04, 0x05, 'a', 't', 't', 'r', 's', // type
-                                                        // AttributeDescription,
-                0x31, 0x06, // vals SET OF AttributeValue }
-                0x04, 0x04, 't', 'e', 's', 't' } );
+            0x30, 0x52,                 // LDAPMessage ::= SEQUENCE {
+              0x02, 0x01, 0x01,         // messageID MessageID
+              0x66, 0x4d,               // CHOICE { ..., modifyRequest ModifyRequest, ...
+                                        // ModifyRequest ::= [APPLICATION 6] SEQUENCE {
+                                        // object 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', 0x30, 0x29, 
+                                        // modification SEQUENCE OF SEQUENCE {
+                0x30, 0x11, 
+                  0x0A, 0x01, 0x02,     // operation ENUMERATED {
+                                        // add (0),
+                                        // delete (1),
+                                        // replace (2) },
+                                        // modification AttributeTypeAndValues } }
+                  0x30, 0x0c,           // AttributeTypeAndValues ::= SEQUENCE {
+                    0x04, 0x01, 'l',    // type AttributeDescription,
+                    0x31, 0x07,         // vals SET OF AttributeValue }
+                      0x04, 0x05, 'P', 'a', 'r', 'i', 's',
+
+                0x30, 0x14,             // modification SEQUENCE OF *SEQUENCE* {
+                  0x0A, 0x01, 0x00,     // operation ENUMERATED {
+                                        // add (0),
+                                        // delete (1),
+                                        // replace (2) },
+                                        // modification AttributeTypeAndValues } }
+                  0x30, 0x0f,           // AttributeTypeAndValues ::= SEQUENCE {
+                                        // type AttributeDescription,
+                    0x04, 0x05, 'a', 't', 't', 'r', 's', 
+                    0x31, 0x06,         // vals SET OF AttributeValue }
+                      0x04, 0x04, 't', 'e', 's', 't' 
+            } );
 
         String decodedPdu = StringTools.dumpBytes( stream.array() );
         stream.flip();
@@ -157,6 +160,76 @@
         }
     }
 
+    /**
+     * Test the decoding of a ModifyRequest
+     */
+    public void testDecodeModifyRequestBadDN() throws NamingException
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x54 );
+
+        stream.put( new byte[]
+            {
+            0x30, 0x52,                 // LDAPMessage ::= SEQUENCE {
+              0x02, 0x01, 0x01,         // messageID MessageID
+              0x66, 0x4d,               // CHOICE { ..., modifyRequest ModifyRequest, ...
+                                        // ModifyRequest ::= [APPLICATION 6] SEQUENCE {
+                                        // object 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', 0x30, 0x29, 
+                                        // modification SEQUENCE OF SEQUENCE {
+                0x30, 0x11, 
+                  0x0A, 0x01, 0x02,     // operation ENUMERATED {
+                                        // add (0),
+                                        // delete (1),
+                                        // replace (2) },
+                                        // modification AttributeTypeAndValues } }
+                  0x30, 0x0c,           // AttributeTypeAndValues ::= SEQUENCE {
+                    0x04, 0x01, 'l',    // type AttributeDescription,
+                    0x31, 0x07,         // vals SET OF AttributeValue }
+                      0x04, 0x05, 'P', 'a', 'r', 'i', 's',
+
+                0x30, 0x14,             // modification SEQUENCE OF *SEQUENCE* {
+                  0x0A, 0x01, 0x00,     // operation ENUMERATED {
+                                        // add (0),
+                                        // delete (1),
+                                        // replace (2) },
+                                        // modification AttributeTypeAndValues } }
+                  0x30, 0x0f,           // AttributeTypeAndValues ::= SEQUENCE {
+                                        // type AttributeDescription,
+                    0x04, 0x05, 'a', 't', 't', 'r', 's', 
+                    0x31, 0x06,         // vals SET OF AttributeValue }
+                      0x04, 0x04, 't', 'e', 's', 't' 
+            } );
+
+        stream.flip();
+
+        // Allocate a LdapMessage Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        // Decode a ModifyRequest PDU
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            assertTrue( de instanceof ResponseCarryingException );
+            Message response = ((ResponseCarryingException)de).getResponse();
+            assertTrue( response instanceof ModifyResponseImpl );
+            assertEquals( ResultCodeEnum.INVALIDDNSYNTAX, ((ModifyResponseImpl)response).getLdapResult().getResultCode() );
+            return;
+        }
+        catch ( NamingException ne )
+        {
+            ne.printStackTrace();
+            fail( ne.getMessage() );
+        }
+
+        fail( "We should not reach this point" );
+    }
 
     /**
      * Test the decoding of a ModifyRequest, with different operations
@@ -168,27 +241,35 @@
         ByteBuffer stream = ByteBuffer.allocate( 0x18C );
 
         stream.put( new byte[]
-            { 0x30, ( byte ) 0x81, ( byte ) 0x89, 0x02, 0x01, 0x15, 0x66, 0x67, // ModifyRequest
-                0x04, 0x2B, // object : cn=Tori
-                            // Amos,ou=playground,dc=apache,dc=org
-                0x63, 0x6E, 0x3D, 0x54, 0x6F, 0x72, 0x69, 0x20, 0x41, 0x6D, 0x6F, 0x73, 0x2C, 0x6F, 0x75, 0x3D, 0x70,
-                0x6C, 0x61, 0x79, 0x67, 0x72, 0x6F, 0x75, 0x6E, 0x64, 0x2C, 0x64, 0x63, 0x3D, 0x61, 0x70, 0x61, 0x63,
-                0x68, 0x65, 0x2C, 0x64, 0x63, 0x3D, 0x6F, 0x72, 0x67, 0x30, 0x38, // Modifications
-                0x30, 0x24, // Modification
-                0x0A, 0x01, 0x00, // Operation = ADD
-                0x30, 0x1F, // type : telephoneNumber
-                0x04, 0x0F, 0x74, 0x65, 0x6C, 0x65, 0x70, 0x68, 0x6F, 0x6E, 0x65, 0x4E, 0x75, 0x6D, 0x62, 0x65, 0x72,
-                0x31, 0x0C, // vals : 1234567890
-                0x04, 0x0A, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, // 1234567890
-                0x39, 0x30, 0x30, 0x10, // Modification
-                0x0A, 0x01, 0x02, // Operation = REPLACE
-                0x30, 0x0B, // type : cn
-                0x04, 0x02, 0x63, 0x6E, 0x31, 0x05, // vals : XXX
-                0x04, 0x03, 0x58, 0x58, 0x58, ( byte ) 0xA0, 0x1B, // Controls
-                                                                    // :
-                                                                    // 2.16.840.1.113730.3.4.2
-                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 } );
+            { 
+            0x30, ( byte ) 0x81, ( byte ) 0x89, 
+              0x02, 0x01, 0x15, 
+              0x66, 0x67,               
+                0x04, 0x2B,             // ModifyRequest object : cn=Tori Amos,ou=playground,dc=apache,dc=org
+                  'c', 'n', '=', 'T', 'o', 'r', 'i', ' ', 'A', 'm', 'o', 's', ',', 'o', 'u', 
+                  '=', 'p', 'l', 'a', 'y', 'g', 'r', 'o', 'u', 'n', 'd', ',', 'd', 'c', '=',
+                  'a', 'p', 'a', 'c', 'h', 'e', ',', 'd', 'c', '=', 'o', 'r', 'g',
+                0x30, 0x38,             // Modifications
+                  0x30, 0x24,           // Modification
+                    0x0A, 0x01, 0x00,   // Operation = ADD
+                    0x30, 0x1F,         // type : telephoneNumber
+                      0x04, 0x0F,
+                        't', 'e', 'l', 'e', 'p', 'h', 'o', 'n', 'e', 'N', 'u', 'm', 'b', 'e', 'r',
+                      0x31, 0x0C,         // vals : 1234567890
+                        0x04, 0x0A, 
+                          '1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
+                  0x30, 0x10,           // Modification
+                    0x0A, 0x01, 0x02,   // Operation = REPLACE
+                    0x30, 0x0B,         // type : cn
+                      0x04, 0x02, 'c', 'n', 
+                      0x31, 0x05,       // vals : XXX
+                        0x04, 0x03, 'X', 'X', 'X', 
+              ( byte ) 0xA0, 0x1B,      // Control : 2.16.840.1.113730.3.4.2
+                0x30, 0x19, 
+                  0x04, 0x17,
+                    '2', '.', '1', '6', '.', '8', '4', '0', '.', '1', '.', 
+                    '1', '1', '3', '7', '3', '0', '.', '3', '.', '4', '.', '2'
+            } );
 
         stream.flip();
 
@@ -277,35 +358,41 @@
         ByteBuffer stream = ByteBuffer.allocate( 0x18C );
 
         stream.put( new byte[]
-            { 0x30, ( byte ) 0x81, ( byte ) 0xB6, // LdapMessage
-                0x02, 0x01, 0x31, // Message ID : 49
-                0x66, ( byte ) 0x81, ( byte ) 0x93, // ModifyRequest
-                0x04, 0x2B, // object : cn=Tori
-                            // Amos,ou=playground,dc=apache,dc=org
-                0x63, 0x6E, 0x3D, 0x54, 0x6F, 0x72, 0x69, 0x20, 0x41, 0x6D, 0x6F, 0x73, 0x2C, 0x6F, 0x75, 0x3D, 0x70,
-                0x6C, 0x61, 0x79, 0x67, 0x72, 0x6F, 0x75, 0x6E, 0x64, 0x2C, 0x64, 0x63, 0x3D, 0x61, 0x70, 0x61, 0x63,
-                0x68, 0x65, 0x2C, 0x64, 0x63, 0x3D, 0x6F, 0x72, 0x67, 0x30, 0x64, // Modifications
-                0x30, 0x14, // Modification
-                0x0A, 0x01, 0x01, // Operation : Delete
-                0x30, 0x0F, // type : description
-                0x04, 0x0B, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6F, 0x6E, 0x31, 0x00, // Vals
-                                                                                                            // =
-                                                                                                            // null
-                0x30, 0x25, // Modification
-                0x0A, 0x01, 0x00, // Operation : Add
-                0x30, 0x20, // type : telephoneNumber
-                0x04, 0x0F, 0x74, 0x65, 0x6C, 0x65, 0x70, 0x68, 0x6F, 0x6E, 0x65, 0x4E, 0x75, 0x6D, 0x62, 0x65, 0x72,
-                0x31, 0x0D, // Vals : 01234567890
-                0x04, 0x0B, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0x30, 0x25, // Modification
-                0x0A, 0x01, 0x00, // Operation : Add
-                0x30, 0x20, // type : telephoneNumber
-                0x04, 0x0F, 0x74, 0x65, 0x6C, 0x65, 0x70, 0x68, 0x6F, 0x6E, 0x65, 0x4E, 0x75, 0x6D, 0x62, 0x65, 0x72,
-                0x31, 0x0D, // Vals : 01234567890
-                0x04, 0x0B, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, ( byte ) 0xA0, 0x1B, // Controls
-                                                                                                                    // :
-                                                                                                                    // 2.16.840.1.113730.3.4.2
-                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 } );
+            { 
+            0x30, ( byte ) 0x81, ( byte ) 0xB6,     // LdapMessage
+              0x02, 0x01, 0x31,                     // Message ID : 49
+              0x66, ( byte ) 0x81, ( byte ) 0x93,   // ModifyRequest
+                0x04, 0x2B,                         // object : cn=Tori Amos,ou=playground,dc=apache,dc=org
+                  'c', 'n', '=', 'T', 'o', 'r', 'i', ' ', 'A', 'm', 'o', 's', ',', 'o', 'u', 
+                  '=', 'p', 'l', 'a', 'y', 'g', 'r', 'o', 'u', 'n', 'd', ',', 'd', 'c', '=',
+                  'a', 'p', 'a', 'c', 'h', 'e', ',', 'd', 'c', '=', 'o', 'r', 'g',
+                0x30, 0x64,                         // Modifications
+                  0x30, 0x14,                       // Modification
+                    0x0A, 0x01, 0x01,               // Operation : Delete
+                    0x30, 0x0F,                     // type : description
+                      0x04, 0x0B, 
+                        0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6F, 0x6E, 
+                      0x31, 0x00,                   // Vals = null
+                  0x30, 0x25,                       // Modification
+                    0x0A, 0x01, 0x00,               // Operation : Add
+                    0x30, 0x20,                     // type : telephoneNumber
+                      0x04, 0x0F, 
+                        't', 'e', 'l', 'e', 'p', 'h', 'o', 'n', 'e', 'N', 'u', 'm', 'b', 'e', 'r',
+                      0x31, 0x0D,                   // Vals : 01234567890
+                        0x04, 0x0B, '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
+                  0x30, 0x25,                       // Modification
+                    0x0A, 0x01, 0x00,               // Operation : Add
+                    0x30, 0x20,                     // type : telephoneNumber
+                      0x04, 0x0F, 
+                      't', 'e', 'l', 'e', 'p', 'h', 'o', 'n', 'e', 'N', 'u', 'm', 'b', 'e', 'r',
+                      0x31, 0x0D,                   // Vals : 01234567890
+                        0x04, 0x0B, '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 
+              ( byte ) 0xA0, 0x1B,                  // Controls : 2.16.840.1.113730.3.4.2
+                0x30, 0x19, 
+                  0x04, 0x17,
+                    '2', '.', '1', '6', '.', '8', '4', '0', '.', '1', '.', 
+                    '1', '1', '3', '7', '3', '0', '.', '3', '.', '4', '.', '2'
+            } );
 
         stream.flip();
 
@@ -404,41 +491,38 @@
 
         stream.put( new byte[]
             {
-
-            0x30, 0x5A, // LDAPMessage ::= SEQUENCE {
-                0x02, 0x01, 0x01, // messageID MessageID
-                0x66, 0x55, // CHOICE { ..., modifyRequest ModifyRequest, ...
-                // ModifyRequest ::= [APPLICATION 6] SEQUENCE {
-                // object 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', 0x30, 0x31, // modification
-                                                                                                    // SEQUENCE
-                                                                                                    // OF
-                                                                                                    // SEQUENCE
-                                                                                                    // {
-                0x30, 0x19, 0x0A, 0x01, 0x02, // operation ENUMERATED {
-                // add (0),
-                // delete (1),
-                // replace (2) },
-                // modification AttributeTypeAndValues } }
-                0x30, 0x14, // AttributeTypeAndValues ::= SEQUENCE {
-                0x04, 0x01, 'l', // type AttributeDescription,
-                0x31, 0x0F, // vals SET OF AttributeValue }
-                0x04, 0x05, 'P', 'a', 'r', 'i', 's', 0x04, 0x06, 'L', 'o', 'n', 'd', 'o', 'n', 0x30, 0x14, // modification
-                                                                                                            // SEQUENCE
-                                                                                                            // OF
-                                                                                                            // *SEQUENCE*
-                                                                                                            // {
-                0x0A, 0x01, 0x00, // operation ENUMERATED {
-                // add (0),
-                // delete (1),
-                // replace (2) },
-                // modification AttributeTypeAndValues } }
-                0x30, 0x0f, // AttributeTypeAndValues ::= SEQUENCE {
-                0x04, 0x05, 'a', 't', 't', 'r', 's', // type
-                                                        // AttributeDescription,
-                0x31, 0x06, // vals SET OF AttributeValue }
-                0x04, 0x04, 't', 'e', 's', 't' } );
+            0x30, 0x5A,                 // LDAPMessage ::= SEQUENCE {
+              0x02, 0x01, 0x01,         // messageID MessageID
+              0x66, 0x55,               // CHOICE { ..., modifyRequest ModifyRequest, ...
+                                        // ModifyRequest ::= [APPLICATION 6] SEQUENCE {
+                                        // object 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', 
+                0x30, 0x31,             // modification SEQUENCE OF SEQUENCE {
+                  0x30, 0x19, 
+                    0x0A, 0x01, 0x02,   // operation ENUMERATED {
+                                        // add (0),
+                                        // delete (1),
+                                        // replace (2) },
+                                        // modification AttributeTypeAndValues } }
+                    0x30, 0x14,         // AttributeTypeAndValues ::= SEQUENCE {
+                      0x04, 0x01, 'l',  // type AttributeDescription,
+                      0x31, 0x0F,       // vals SET OF AttributeValue }
+                        0x04, 0x05, 'P', 'a', 'r', 'i', 's', 
+                        0x04, 0x06, 'L', 'o', 'n', 'd', 'o', 'n', 
+                  0x30, 0x14,           // modification SEQUENCE OF *SEQUENCE*  {
+                    0x0A, 0x01, 0x00,   // operation ENUMERATED {
+                                        // add (0),
+                                        // delete (1),
+                                        // replace (2) },
+                                        // modification AttributeTypeAndValues } }
+                    0x30, 0x0f,         // AttributeTypeAndValues ::= SEQUENCE {
+                                        // type AttributeDescription,
+                      0x04, 0x05, 'a', 't', 't', 'r', 's', 
+                      0x31, 0x06,       // vals SET OF AttributeValue }
+                        0x04, 0x04, 't', 'e', 's', 't' 
+            } );
 
         String decodedPdu = StringTools.dumpBytes( stream.array() );
         stream.flip();
@@ -519,9 +603,10 @@
         ByteBuffer stream = ByteBuffer.allocate( 0x07 );
 
         stream.put( new byte[]
-            { 0x30, 0x05, // LdapMessage
-                0x02, 0x01, 0x31, // Message ID : 49
-                0x66, 0x00 // ModifyRequest
+            { 
+            0x30, 0x05,                 // LdapMessage
+              0x02, 0x01, 0x31,         // Message ID : 49
+              0x66, 0x00                // ModifyRequest
             } );
 
         stream.flip();
@@ -552,10 +637,12 @@
         ByteBuffer stream = ByteBuffer.allocate( 0x09 );
 
         stream.put( new byte[]
-            { 0x30, 0x07, // LdapMessage
-                0x02, 0x01, 0x31, // Message ID : 49
-                0x66, 0x02, // ModifyRequest
-                0x04, 0x00 } );
+            { 
+            0x30, 0x07,                 // LdapMessage
+              0x02, 0x01, 0x31,         // Message ID : 49
+              0x66, 0x02,               // ModifyRequest
+                0x04, 0x00 
+            } );
 
         stream.flip();
 
@@ -585,11 +672,14 @@
         ByteBuffer stream = ByteBuffer.allocate( 0x29 );
 
         stream.put( new byte[]
-            { 0x30, 0x27, // LdapMessage
-                0x02, 0x01, 0x31, // Message ID : 49
-                0x66, 0x22, // ModifyRequest
-                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' } );
+            { 
+            0x30, 0x27,                 // LdapMessage
+              0x02, 0x01, 0x31,         // Message ID : 49
+              0x66, 0x22,               // ModifyRequest
+                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' 
+            } );
 
         stream.flip();
 
@@ -619,11 +709,15 @@
         ByteBuffer stream = ByteBuffer.allocate( 0x2B );
 
         stream.put( new byte[]
-            { 0x30, 0x29, // LdapMessage
-                0x02, 0x01, 0x31, // Message ID : 49
-                0x66, 0x24, // ModifyRequest
-                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', 0x30, 0x00 } );
+            { 
+            0x30, 0x29,                 // LdapMessage
+              0x02, 0x01, 0x31,         // Message ID : 49
+              0x66, 0x24,               // ModifyRequest
+                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', 
+                0x30, 0x00 
+            } );
 
         stream.flip();
 
@@ -653,11 +747,16 @@
         ByteBuffer stream = ByteBuffer.allocate( 0x2D );
 
         stream.put( new byte[]
-            { 0x30, 0x2B, // LdapMessage
-                0x02, 0x01, 0x31, // Message ID : 49
-                0x66, 0x26, // ModifyRequest
-                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', 0x30, 0x02, 0x30, 0x00 } );
+            { 
+            0x30, 0x2B,                 // LdapMessage
+              0x02, 0x01, 0x31,         // Message ID : 49
+              0x66, 0x26,               // ModifyRequest
+                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', 
+                0x30, 0x02, 
+                  0x30, 0x00 
+            } );
 
         stream.flip();
 
@@ -687,12 +786,17 @@
         ByteBuffer stream = ByteBuffer.allocate( 0x2F );
 
         stream.put( new byte[]
-            { 0x30, 0x2D, // LdapMessage
-                0x02, 0x01, 0x31, // Message ID : 49
-                0x66, 0x28, // ModifyRequest
-                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', 0x30, 0x04, 0x30, 0x02, 0x0A,
-                0x00 } );
+            { 
+            0x30, 0x2D,                 // LdapMessage
+              0x02, 0x01, 0x31,         // Message ID : 49
+              0x66, 0x28,               // ModifyRequest
+                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', 
+                0x30, 0x04, 
+                  0x30, 0x02, 
+                    0x0A, 0x00 
+            } );
 
         stream.flip();
 
@@ -722,12 +826,17 @@
         ByteBuffer stream = ByteBuffer.allocate( 0x30 );
 
         stream.put( new byte[]
-            { 0x30, 0x2E, // LdapMessage
-                0x02, 0x01, 0x31, // Message ID : 49
-                0x66, 0x29, // ModifyRequest
-                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', 0x30, 0x05, 0x30, 0x03, 0x0A,
-                0x01, 0x04 } );
+            { 
+            0x30, 0x2E,                 // LdapMessage
+              0x02, 0x01, 0x31,         // Message ID : 49
+              0x66, 0x29,               // ModifyRequest
+                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', 
+                0x30, 0x05, 
+                  0x30, 0x03, 
+                    0x0A, 0x01, 0x04 
+            } );
 
         stream.flip();
 
@@ -758,12 +867,17 @@
         ByteBuffer stream = ByteBuffer.allocate( 0x30 );
 
         stream.put( new byte[]
-            { 0x30, 0x2E, // LdapMessage
-                0x02, 0x01, 0x31, // Message ID : 49
-                0x66, 0x29, // ModifyRequest
-                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', 0x30, 0x05, 0x30, 0x03, 0x0A,
-                0x01, 0x00 } );
+            { 
+            0x30, 0x2E,                 // LdapMessage
+              0x02, 0x01, 0x31,         // Message ID : 49
+              0x66, 0x29,               // ModifyRequest
+                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', 
+                0x30, 0x05, 
+                  0x30, 0x03, 
+                    0x0A, 0x01, 0x00 
+            } );
 
         stream.flip();
 
@@ -794,12 +908,18 @@
         ByteBuffer stream = ByteBuffer.allocate( 0x32 );
 
         stream.put( new byte[]
-            { 0x30, 0x30, // LdapMessage
-                0x02, 0x01, 0x31, // Message ID : 49
-                0x66, 0x2B, // ModifyRequest
-                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', 0x30, 0x07, 0x30, 0x05, 0x0A,
-                0x01, 0x00, 0x30, 0x00 } );
+            { 
+            0x30, 0x30,                 // LdapMessage
+              0x02, 0x01, 0x31,         // Message ID : 49
+              0x66, 0x2B,               // ModifyRequest
+                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', 
+                0x30, 0x07, 
+                  0x30, 0x05, 
+                    0x0A, 0x01, 0x00, 
+                  0x30, 0x00 
+            } );
 
         stream.flip();
 
@@ -830,12 +950,19 @@
         ByteBuffer stream = ByteBuffer.allocate( 0x34 );
 
         stream.put( new byte[]
-            { 0x30, 0x32, // LdapMessage
-                0x02, 0x01, 0x31, // Message ID : 49
-                0x66, 0x2D, // ModifyRequest
-                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', 0x30, 0x09, 0x30, 0x07, 0x0A,
-                0x01, 0x00, 0x30, 0x02, 0x04, 0x00 } );
+            { 
+            0x30, 0x32,                 // LdapMessage
+              0x02, 0x01, 0x31,         // Message ID : 49
+              0x66, 0x2D,               // ModifyRequest
+                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', 
+                0x30, 0x09, 
+                  0x30, 0x07, 
+                    0x0A, 0x01, 0x00, 
+                    0x30, 0x02, 
+                      0x04, 0x00 
+            } );
 
         stream.flip();
 
@@ -850,7 +977,16 @@
         }
         catch ( DecoderException de )
         {
-            assertTrue( true );
+            assertTrue( de instanceof ResponseCarryingException );
+            Message response = ((ResponseCarryingException)de).getResponse();
+            assertTrue( response instanceof ModifyResponseImpl );
+            assertEquals( ResultCodeEnum.INVALIDATTRIBUTESYNTAX, ((ModifyResponseImpl)response).getLdapResult().getResultCode() );
+            return;
+        }
+        catch ( NamingException ne )
+        {
+            ne.printStackTrace();
+            fail( ne.getMessage() );
         }
     }
 
@@ -866,12 +1002,19 @@
         ByteBuffer stream = ByteBuffer.allocate( 0x35 );
 
         stream.put( new byte[]
-            { 0x30, 0x33, // LdapMessage
-                0x02, 0x01, 0x31, // Message ID : 49
-                0x66, 0x2E, // ModifyRequest
-                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', 0x30, 0x0A, 0x30, 0x08, 0x0A,
-                0x01, 0x00, 0x30, 0x03, 0x04, 0x01, 'l', } );
+            { 
+            0x30, 0x33,                 // LdapMessage
+              0x02, 0x01, 0x31,         // Message ID : 49
+              0x66, 0x2E,               // ModifyRequest
+                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', 
+                0x30, 0x0A, 
+                  0x30, 0x08, 
+                    0x0A, 0x01, 0x00, 
+                    0x30, 0x03, 
+                    0x04, 0x01, 'l' 
+            } );
 
         stream.flip();
 
@@ -902,12 +1045,20 @@
         ByteBuffer stream = ByteBuffer.allocate( 0x37 );
 
         stream.put( new byte[]
-            { 0x30, 0x35, // LdapMessage
-                0x02, 0x01, 0x31, // Message ID : 49
-                0x66, 0x30, // ModifyRequest
-                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', 0x30, 0x0C, 0x30, 0x0A, 0x0A,
-                0x01, 0x00, 0x30, 0x05, 0x04, 0x01, 'l', 0x31, 0x00 } );
+            { 
+            0x30, 0x35,                 // LdapMessage
+              0x02, 0x01, 0x31,         // Message ID : 49
+              0x66, 0x30,               // ModifyRequest
+                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', 
+                0x30, 0x0C, 
+                  0x30, 0x0A, 
+                    0x0A, 0x01, 0x00, 
+                    0x30, 0x05, 
+                      0x04, 0x01, 'l', 
+                      0x31, 0x00 
+            } );
 
         String decodedPdu = StringTools.dumpBytes( stream.array() );
         stream.flip();
@@ -974,15 +1125,23 @@
         ByteBuffer stream = ByteBuffer.allocate( 0x54 );
 
         stream.put( new byte[]
-            { 0x30, 0x52, // LdapMessage
-                0x02, 0x01, 0x31, // Message ID : 49
-                0x66, 0x30, // ModifyRequest
-                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', 0x30, 0x0C, 0x30, 0x0A, 0x0A,
-                0x01, 0x00, 0x30, 0x05, 0x04, 0x01, 'l', 0x31, 0x00, ( byte ) 0xA0, 0x1B, // A
-                                                                                            // control
+            { 
+            0x30, 0x52,                 // LdapMessage
+              0x02, 0x01, 0x31,         // Message ID : 49
+              0x66, 0x30,               // ModifyRequest
+                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', 
+                0x30, 0x0C, 
+                  0x30, 0x0A, 
+                    0x0A, 0x01, 0x00, 
+                    0x30, 0x05, 
+                      0x04, 0x01, 'l', 
+                      0x31, 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 } );
+                0x33, 0x37, 0x33, 0x30, 0x2E, 0x33, 0x2E, 0x34, 0x2E, 0x32 
+            } );
 
         String decodedPdu = StringTools.dumpBytes( stream.array() );
         stream.flip();
@@ -1058,12 +1217,22 @@
         ByteBuffer stream = ByteBuffer.allocate( 0x3D );
 
         stream.put( new byte[]
-            { 0x30, 0x3B, // LdapMessage
-                0x02, 0x01, 0x31, // Message ID : 49
-                0x66, 0x36, // ModifyRequest
-                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', 0x30, 0x12, 0x30, 0x10, 0x0A,
-                0x01, 0x00, 0x30, 0x0B, 0x04, 0x01, 'l', 0x31, 0x06, 0x04, 0x01, 'a', 0x04, 0x01, 'b' } );
+            { 
+            0x30, 0x3B,                 // LdapMessage
+              0x02, 0x01, 0x31,         // Message ID : 49
+              0x66, 0x36,               // ModifyRequest
+                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', 
+                0x30, 0x12, 
+                  0x30, 0x10, 
+                    0x0A, 0x01, 0x00, 
+                    0x30, 0x0B, 
+                      0x04, 0x01, 'l', 
+                      0x31, 0x06, 
+                        0x04, 0x01, 'a', 
+                        0x04, 0x01, 'b' 
+            } );
 
         String decodedPdu = StringTools.dumpBytes( stream.array() );
         stream.flip();

Modified: directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/codec/modifyDn/ModifyDNRequestTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/codec/modifyDn/ModifyDNRequestTest.java?rev=438859&r1=438858&r2=438859&view=diff
==============================================================================
--- directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/codec/modifyDn/ModifyDNRequestTest.java (original)
+++ directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/codec/modifyDn/ModifyDNRequestTest.java Thu Aug 31 03:33:43 2006
@@ -33,7 +33,11 @@
 import org.apache.directory.shared.ldap.codec.LdapDecoder;
 import org.apache.directory.shared.ldap.codec.LdapMessage;
 import org.apache.directory.shared.ldap.codec.LdapMessageContainer;
+import org.apache.directory.shared.ldap.codec.ResponseCarryingException;
 import org.apache.directory.shared.ldap.codec.modifyDn.ModifyDNRequest;
+import org.apache.directory.shared.ldap.message.Message;
+import org.apache.directory.shared.ldap.message.ModifyDnResponseImpl;
+import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.util.StringTools;
 
 import junit.framework.TestCase;
@@ -57,20 +61,23 @@
 
         stream.put( new byte[]
             {
-
-            0x30, 0x46, // LDAPMessage ::= SEQUENCE {
-                0x02, 0x01, 0x01, // messageID MessageID
-                0x6C, 0x41, // CHOICE { ..., modifyDNRequest ModifyDNRequest,
-                            // ...
-                // ModifyDNRequest ::= [APPLICATION 12] 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',
-                // newrdn RelativeLDAPDN,
-                0x04, 0x0F, 'c', 'n', '=', 't', 'e', 's', 't', 'D', 'N', 'M', 'o', 'd', 'i', 'f', 'y', 0x01, 0x01,
-                0x00, // deleteoldrdn BOOLEAN,
-                // newSuperior [0] LDAPDN OPTIONAL }
-                ( byte ) 0x80, 0x09, 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm' } );
+            0x30, 0x46,                 // LDAPMessage ::= SEQUENCE {
+              0x02, 0x01, 0x01,         // messageID MessageID
+              0x6C, 0x41,               // CHOICE { ..., modifyDNRequest ModifyDNRequest,
+                                        // ...
+                                        // ModifyDNRequest ::= [APPLICATION 12] 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',
+                                        // newrdn RelativeLDAPDN,
+                0x04, 0x0F, 
+                  'c', 'n', '=', 't', 'e', 's', 't', 'D', 'N', 'M', 'o', 'd', 'i', 'f', 'y', 
+                0x01, 0x01, 0x00, // deleteoldrdn BOOLEAN,
+                                        // newSuperior [0] LDAPDN OPTIONAL }
+                ( byte ) 0x80, 0x09, 
+                  'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm' 
+            } );
 
         String decodedPdu = StringTools.dumpBytes( stream.array() );
         stream.flip();
@@ -116,8 +123,172 @@
         }
     }
 
+    /**
+     * Test the decoding of a bad DN ModifyDNRequest
+     */
+    public void testDecodeModifyDNRequestBadDN() throws NamingException
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x48 );
+
+        stream.put( new byte[]
+            {
+            0x30, 0x46,                 // LDAPMessage ::= SEQUENCE {
+              0x02, 0x01, 0x01,         // messageID MessageID
+              0x6C, 0x41,               // CHOICE { ..., modifyDNRequest ModifyDNRequest,
+                                        // ...
+                                        // ModifyDNRequest ::= [APPLICATION 12] 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',
+                                        // newrdn RelativeLDAPDN,
+                0x04, 0x0F, 
+                  'c', 'n', '=', 't', 'e', 's', 't', 'D', 'N', 'M', 'o', 'd', 'i', 'f', 'y', 
+                0x01, 0x01, 0x00, // deleteoldrdn BOOLEAN,
+                                        // newSuperior [0] LDAPDN OPTIONAL }
+                ( byte ) 0x80, 0x09, 
+                  'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm' 
+            } );
+
+        stream.flip();
+
+        // Allocate a ModifyRequest Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            assertTrue( de instanceof ResponseCarryingException );
+            Message response = ((ResponseCarryingException)de).getResponse();
+            assertTrue( response instanceof ModifyDnResponseImpl );
+            assertEquals( ResultCodeEnum.INVALIDDNSYNTAX, ((ModifyDnResponseImpl)response).getLdapResult().getResultCode() );
+            return;
+        }
+        catch ( NamingException ne )
+        {
+            ne.printStackTrace();
+            fail( ne.getMessage() );
+        }
+
+        fail( "We should not reach this point" );
+    }
 
     /**
+     * Test the decoding of a bad RDN ModifyDNRequest
+     */
+    public void testDecodeModifyDNRequestBadRDN() throws NamingException
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x48 );
+
+        stream.put( new byte[]
+            {
+            0x30, 0x46,                 // LDAPMessage ::= SEQUENCE {
+              0x02, 0x01, 0x01,         // messageID MessageID
+              0x6C, 0x41,               // CHOICE { ..., modifyDNRequest ModifyDNRequest,
+                                        // ...
+                                        // ModifyDNRequest ::= [APPLICATION 12] 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',
+                                        // newrdn RelativeLDAPDN,
+                0x04, 0x0F, 
+                  'c', 'n', ':', 't', 'e', 's', 't', 'D', 'N', 'M', 'o', 'd', 'i', 'f', 'y', 
+                0x01, 0x01, 0x00,       // deleteoldrdn BOOLEAN,
+                                        // newSuperior [0] LDAPDN OPTIONAL }
+                ( byte ) 0x80, 0x09, 
+                  'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm' 
+            } );
+
+        stream.flip();
+
+        // Allocate a ModifyRequest Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            assertTrue( de instanceof ResponseCarryingException );
+            Message response = ((ResponseCarryingException)de).getResponse();
+            assertTrue( response instanceof ModifyDnResponseImpl );
+            assertEquals( ResultCodeEnum.INVALIDDNSYNTAX, ((ModifyDnResponseImpl)response).getLdapResult().getResultCode() );
+            return;
+        }
+        catch ( NamingException ne )
+        {
+            ne.printStackTrace();
+            fail( ne.getMessage() );
+        }
+
+        fail( "We should not reach this point" );
+    }
+
+    /**
+     * Test the decoding of a bad RDN ModifyDNRequest
+     */
+    public void testDecodeModifyDNRequestBadNewSuperior() throws NamingException
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x48 );
+
+        stream.put( new byte[]
+            {
+            0x30, 0x46,                 // LDAPMessage ::= SEQUENCE {
+              0x02, 0x01, 0x01,         // messageID MessageID
+              0x6C, 0x41,               // CHOICE { ..., modifyDNRequest ModifyDNRequest,
+                                        // ...
+                                        // ModifyDNRequest ::= [APPLICATION 12] 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',
+                                        // newrdn RelativeLDAPDN,
+                0x04, 0x0F, 
+                  'c', 'n', '=', 't', 'e', 's', 't', 'D', 'N', 'M', 'o', 'd', 'i', 'f', 'y', 
+                0x01, 0x01, 0x00,       // deleteoldrdn BOOLEAN,
+                                        // newSuperior [0] LDAPDN OPTIONAL }
+                ( byte ) 0x80, 0x09, 
+                  'o', 'u', ':', 's', 'y', 's', 't', 'e', 'm' 
+            } );
+
+        stream.flip();
+
+        // Allocate a ModifyRequest Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            assertTrue( de instanceof ResponseCarryingException );
+            Message response = ((ResponseCarryingException)de).getResponse();
+            assertTrue( response instanceof ModifyDnResponseImpl );
+            assertEquals( ResultCodeEnum.INVALIDDNSYNTAX, ((ModifyDnResponseImpl)response).getLdapResult().getResultCode() );
+            return;
+        }
+        catch ( NamingException ne )
+        {
+            ne.printStackTrace();
+            fail( ne.getMessage() );
+        }
+
+        fail( "We should not reach this point" );
+    }
+    
+    /**
      * Test the decoding of a full ModifyDNRequest with controls
      */
     public void testDecodeModifyDNRequestSuccessWithControls() throws NamingException
@@ -128,23 +299,26 @@
 
         stream.put( new byte[]
             {
-
-            0x30, 0x63, // LDAPMessage ::= SEQUENCE {
-                0x02, 0x01, 0x01, // messageID MessageID
-                0x6C, 0x41, // CHOICE { ..., modifyDNRequest ModifyDNRequest,
-                            // ...
-                // ModifyDNRequest ::= [APPLICATION 12] 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',
-                // newrdn RelativeLDAPDN,
-                0x04, 0x0F, 'c', 'n', '=', 't', 'e', 's', 't', 'D', 'N', 'M', 'o', 'd', 'i', 'f', 'y', 0x01, 0x01,
-                0x00, // deleteoldrdn BOOLEAN,
-                // newSuperior [0] LDAPDN OPTIONAL }
-                ( byte ) 0x80, 0x09, 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm', ( byte ) 0xA0, 0x1B, // A
-                                                                                                        // control
+            0x30, 0x63,                 // LDAPMessage ::= SEQUENCE {
+              0x02, 0x01, 0x01,         // messageID MessageID
+              0x6C, 0x41,               // CHOICE { ..., modifyDNRequest ModifyDNRequest,
+                                        // ...
+                                        // ModifyDNRequest ::= [APPLICATION 12] 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',
+                                        // newrdn RelativeLDAPDN,
+                0x04, 0x0F, 
+                  'c', 'n', '=', 't', 'e', 's', 't', 'D', 'N', 'M', 'o', 'd', 'i', 'f', 'y', 
+                0x01, 0x01, 0x00,       // deleteoldrdn BOOLEAN,
+                                        // newSuperior [0] LDAPDN OPTIONAL }
+                ( byte ) 0x80, 0x09, 
+                  'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm', 
+              ( 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 } );
+                0x33, 0x37, 0x33, 0x30, 0x2E, 0x33, 0x2E, 0x34, 0x2E, 0x32 
+            } );
 
         String decodedPdu = StringTools.dumpBytes( stream.array() );
         stream.flip();
@@ -211,19 +385,20 @@
 
         stream.put( new byte[]
             {
-
-            0x30, 0x3B, // LDAPMessage ::= SEQUENCE {
-                0x02, 0x01, 0x01, // messageID MessageID
-                0x6C, 0x36, // CHOICE { ..., modifyDNRequest ModifyDNRequest,
-                            // ...
-                // ModifyDNRequest ::= [APPLICATION 12] 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',
-                // newrdn RelativeLDAPDN,
-                0x04, 0x0F, 'c', 'n', '=', 't', 'e', 's', 't', 'D', 'N', 'M', 'o', 'd', 'i', 'f', 'y', 0x01, 0x01, 0x00 // deleteoldrdn
-                                                                                                                        // BOOLEAN,
-            // newSuperior [0] LDAPDN OPTIONAL }
+            0x30, 0x3B,                 // LDAPMessage ::= SEQUENCE {
+              0x02, 0x01, 0x01,         // messageID MessageID
+              0x6C, 0x36,               // CHOICE { ..., modifyDNRequest ModifyDNRequest,
+                                        // ...
+                                        // ModifyDNRequest ::= [APPLICATION 12] 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',
+                                        // newrdn RelativeLDAPDN,
+                0x04, 0x0F, 
+                  'c', 'n', '=', 't', 'e', 's', 't', 'D', 'N', 'M', 'o', 'd', 'i', 'f', 'y', 
+                0x01, 0x01, 0x00        // deleteoldrdn BOOLEAN,
+                                        // newSuperior [0] LDAPDN OPTIONAL }
             } );
 
         String decodedPdu = StringTools.dumpBytes( stream.array() );
@@ -281,22 +456,24 @@
 
         stream.put( new byte[]
             {
-
-            0x30, 0x58, // LDAPMessage ::= SEQUENCE {
-                0x02, 0x01, 0x01, // messageID MessageID
-                0x6C, 0x36, // CHOICE { ..., modifyDNRequest ModifyDNRequest,
-                            // ...
-                // ModifyDNRequest ::= [APPLICATION 12] 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',
-                // newrdn RelativeLDAPDN,
-                0x04, 0x0F, 'c', 'n', '=', 't', 'e', 's', 't', 'D', 'N', 'M', 'o', 'd', 'i', 'f', 'y', 0x01, 0x01,
-                0x00, // deleteoldrdn BOOLEAN,
-                // newSuperior [0] LDAPDN OPTIONAL }
-                ( byte ) 0xA0, 0x1B, // A control
+            0x30, 0x58,                 // LDAPMessage ::= SEQUENCE {
+              0x02, 0x01, 0x01,         // messageID MessageID
+              0x6C, 0x36,               // CHOICE { ..., modifyDNRequest ModifyDNRequest,
+                                        // ...
+                                        // ModifyDNRequest ::= [APPLICATION 12] 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',
+                                        // newrdn RelativeLDAPDN,
+                0x04, 0x0F, 
+                  'c', 'n', '=', 't', 'e', 's', 't', 'D', 'N', 'M', 'o', 'd', 'i', 'f', 'y', 
+                0x01, 0x01, 0x00,       // deleteoldrdn BOOLEAN,
+                                        // newSuperior [0] LDAPDN 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 } );
+                0x33, 0x37, 0x33, 0x30, 0x2E, 0x33, 0x2E, 0x34, 0x2E, 0x32 
+            } );
 
         String decodedPdu = StringTools.dumpBytes( stream.array() );
         stream.flip();
@@ -363,10 +540,11 @@
         ByteBuffer stream = ByteBuffer.allocate( 0x07 );
 
         stream.put( new byte[]
-            { 0x30, 0x05, // LDAPMessage ::= SEQUENCE {
-                0x02, 0x01, 0x01, // messageID MessageID
-                0x6C, 0x00 // CHOICE { ..., modifyDNRequest ModifyDNRequest,
-                            // ...
+            { 
+            0x30, 0x05,                 // LDAPMessage ::= SEQUENCE {
+              0x02, 0x01, 0x01,         // messageID MessageID
+              0x6C, 0x00                // CHOICE { ..., modifyDNRequest ModifyDNRequest,
+                                        // ...
             } );
 
         stream.flip();
@@ -397,10 +575,11 @@
         ByteBuffer stream = ByteBuffer.allocate( 0x09 );
 
         stream.put( new byte[]
-            { 0x30, 0x07, // LDAPMessage ::= SEQUENCE {
-                0x02, 0x01, 0x01, // messageID MessageID
-                0x6C, 0x02, // CHOICE { ..., modifyDNRequest ModifyDNRequest,
-                            // ...
+            { 
+            0x30, 0x07,                 // LDAPMessage ::= SEQUENCE {
+              0x02, 0x01, 0x01,         // messageID MessageID
+              0x6C, 0x02,               // CHOICE { ..., modifyDNRequest ModifyDNRequest,
+                                        // ...
                 0x04, 0x00 } );
 
         stream.flip();
@@ -431,12 +610,16 @@
         ByteBuffer stream = ByteBuffer.allocate( 0x2D );
 
         stream.put( new byte[]
-            { 0x30, 0x2B, // LDAPMessage ::= SEQUENCE {
-                0x02, 0x01, 0x01, // messageID MessageID
-                0x6C, 0x26, // CHOICE { ..., modifyDNRequest ModifyDNRequest,
+            { 
+            0x30, 0x2B,                 // LDAPMessage ::= SEQUENCE {
+              0x02, 0x01, 0x01,         // messageID MessageID
+              0x6C, 0x26,               // CHOICE { ..., modifyDNRequest ModifyDNRequest,
                             // ...
-                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', 0x04, 0x00 } );
+                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', 
+                0x04, 0x00 
+            } );
 
         stream.flip();
 
@@ -466,14 +649,17 @@
         ByteBuffer stream = ByteBuffer.allocate( 0x3C );
 
         stream.put( new byte[]
-            { 0x30, 0x3A, // LDAPMessage ::= SEQUENCE {
-                0x02, 0x01, 0x01, // messageID MessageID
-                0x6C, 0x35, // CHOICE { ..., modifyDNRequest ModifyDNRequest,
-                            // ...
-                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', 0x04, 0x0F, 'c', 'n', '=', 't',
-                'e', 's', 't', 'D', 'N', 'M', 'o', 'd', 'i', 'f', 'y', 0x01, 0x00 // deleteoldrdn
-                                                                                    // BOOLEAN,
+            { 
+            0x30, 0x3A,                 // LDAPMessage ::= SEQUENCE {
+              0x02, 0x01, 0x01,         // messageID MessageID
+              0x6C, 0x35,               // CHOICE { ..., modifyDNRequest ModifyDNRequest,
+                                        // ...
+                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', 
+                0x04, 0x0F, 
+                  'c', 'n', '=', 't', 'e', 's', 't', 'D', 'N', 'M', 'o', 'd', 'i', 'f', 'y', 
+                0x01, 0x00              // deleteoldrdn BOOLEAN
             } );
 
         stream.flip();

Modified: directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/codec/search/SearchRequestMatchingRuleAssertionTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/codec/search/SearchRequestMatchingRuleAssertionTest.java?rev=438859&r1=438858&r2=438859&view=diff
==============================================================================
--- directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/codec/search/SearchRequestMatchingRuleAssertionTest.java (original)
+++ directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/codec/search/SearchRequestMatchingRuleAssertionTest.java Thu Aug 31 03:33:43 2006
@@ -77,15 +77,40 @@
 
         ByteBuffer stream = ByteBuffer.allocate( 0x63 );
         stream.put( new byte[]
-            { 0x30, 0x61, 0x02, 0x01, 0x01, 0x63, 0x5C, // "dc=example,dc=com"
-                0x04, 0x11, 0x64, 0x63, 0x3D, 0x65, 0x78, 0x61, 0x6D, 0x70, 0x6C, 0x65, 0x2C, 0x64, 0x63, 0x3D, 0x63,
-                0x6F, 0x6D, 0x0A, 0x01, 0x00, 0x0A, 0x01, 0x02, 0x02, 0x01, 0x02, 0x02, 0x01, 0x03, 0x01, 0x01,
-                ( byte ) 0xFF, ( byte ) 0xA9, 0x21, ( byte ) 0x81, 0x02, 'c', 'n', ( byte ) 0x82, 0x13, '1', '.', '2',
-                '.', '8', '4', '0', '.', '4', '8', '0', '1', '8', '.', '1', '.', '2', '.', '2', ( byte ) 0x83, 0x03,
-                'a', 'o', 'k', ( byte ) 0x84, 0x01, ( byte ) 0xFF, 0x30, 0x15, // Attributes
-                0x04, 0x05, 0x61, 0x74, 0x74, 0x72, 0x30, // attr0
-                0x04, 0x05, 0x61, 0x74, 0x74, 0x72, 0x31, // attr1
-                0x04, 0x05, 0x61, 0x74, 0x74, 0x72, 0x32 // attr2
+            { 
+            0x30, 0x61,                     // LDAPMessage ::= SEQUENCE {
+              0x02, 0x01, 0x01,             //   messageID       MessageID,
+              0x63, 0x5C,                   //   protocolOp      CHOICE {
+                                            //     searchRequest   SearchRequest,
+                                            //
+                                            // SearchRequest ::= [APPLICATION 3] SEQUENCE {
+                0x04, 0x11,                 //   baseObject      LDAPDN, (dc=example,dc=com)
+                  'd', 'c', '=', 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm',
+                                            //   scope           ENUMERATED {
+                0x0A, 0x01, 0x00,           //      baseObject              (0), ...
+                                            //   derefAliases    ENUMERATED {
+                0x0A, 0x01, 0x02,           //     derefFindingBaseObj     (2),...
+                0x02, 0x01, 0x02,           //   sizeLimit       INTEGER (0 .. maxInt), (2)
+                0x02, 0x01, 0x03,           //   timeLimit       INTEGER (0 .. maxInt), (3)
+                0x01, 0x01, ( byte ) 0xFF,  //   typesOnly       BOOLEAN, (true)
+                ( byte ) 0xA9, 0x21,        //   filter          Filter,
+                                            //
+                                            // Filter ::= CHOICE {
+                                            //   extensibleMatch [9] MatchingRuleAssertion }
+                                            //
+                                            // MatchingRuleAssertion ::= SEQUENCE {
+                  ( byte ) 0x81, 0x02,      //   matchingRule    [1] MatchingRuleId OPTIONAL,
+                    'c', 'n', 
+                  ( byte ) 0x82, 0x13,      //    type            [2] AttributeDescription OPTIONAL,
+                    '1', '.', '2', '.', '8', '4', '0', '.', '4', '8', '0', '1', '8', '.', '1', '.', '2', '.', '2', 
+                  ( byte ) 0x83, 0x03,      //    matchValue      [3] AssertionValue,
+                    'a', 'o', 'k', 
+                                            //    dnAttributes    [4] BOOLEAN DEFAULT FALSE  }
+                  ( byte ) 0x84, 0x01, ( byte ) 0xFF, 
+                0x30, 0x15,                 // attributes      AttributeDescriptionList }
+                  0x04, 0x05, 'a', 't', 't', 'r', '0',
+                  0x04, 0x05, 'a', 't', 't', 'r', '1',
+                  0x04, 0x05, 'a', 't', 't', 'r', '2'
             } );
 
         String decodedPdu = StringTools.dumpBytes( stream.array() );
@@ -156,16 +181,22 @@
     public void testDecodeSearchRequestEmptyExtensibleMatch()
     {
         byte[] asn1BER = new byte[]
-            { 0x30, 0x3B, 0x02, 0x01, 0x04, // messageID
-                0x63, 0x36, 0x04, 0x1F, // baseObject LDAPDN,
-                'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=', 'e', 'x', 'a',
-                'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm', 0x0A, 0x01, 0x01, 0x0A, 0x01, 0x03, 0x02, 0x01,
-                0x00, 0x02, 0x01, 0x00, 0x01, 0x01, ( byte ) 0xFF, ( byte ) 0xA9, 0x00, 0x30, 0x02, // AttributeDescriptionList
-                                                                                                    // ::=
-                                                                                                    // SEQUENCE
-                                                                                                    // OF
-                                                                                                    // AttributeDescription
-                0x04, 0x00 };
+            { 
+            0x30, 0x3B, 
+              0x02, 0x01, 0x04,                 // messageID
+                0x63, 0x36,                     // baseObject LDAPDN,
+                  0x04, 0x1F, 
+                    'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=', 'e', 'x', 'a',
+                    'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm', 
+                  0x0A, 0x01, 0x01, 
+                  0x0A, 0x01, 0x03, 
+                  0x02, 0x01, 0x00, 
+                  0x02, 0x01, 0x00, 
+                  0x01, 0x01, ( byte ) 0xFF, 
+                  ( byte ) 0xA9, 0x00,             
+                  0x30, 0x02, // AttributeDescriptionList ::= SEQUENCE OF AttributeDescription
+                0x04, 0x00 
+            };
 
         Asn1Decoder ldapDecoder = new LdapDecoder();
 
@@ -203,14 +234,23 @@
     public void testDecodeSearchRequestExtensibleMatchEmptyMatchingRule()
     {
         byte[] asn1BER = new byte[]
-            { 0x30, 0x3D, 0x02, 0x01, 0x04, // messageID
-                0x63, 0x38, 0x04, 0x1F, // baseObject LDAPDN,
-                'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=', 'e', 'x', 'a',
-                'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm', 0x0A, 0x01, 0x01, 0x0A, 0x01, 0x03, 0x02, 0x01,
-                0x00, 0x02, 0x01, 0x00, 0x01, 0x01, ( byte ) 0xFF, ( byte ) 0xA9, 0x02, ( byte ) 0x81, 0x00, 0x30,
-                0x02, // AttributeDescriptionList ::= SEQUENCE OF
-                        // AttributeDescription
-                0x04, 0x00 };
+            { 
+            0x30, 0x3D, 
+              0x02, 0x01, 0x04,                 // messageID
+              0x63, 0x38, 
+                0x04, 0x1F,                     // baseObject LDAPDN,
+                  'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=', 'e', 'x', 'a',
+                  'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm', 
+                0x0A, 0x01, 0x01, 
+                0x0A, 0x01, 0x03, 
+                0x02, 0x01, 0x00, 
+                0x02, 0x01, 0x00, 
+                0x01, 0x01, ( byte ) 0xFF, 
+                ( byte ) 0xA9, 0x02, 
+                  ( byte ) 0x81, 0x00,          // matchingRule    [1] MatchingRuleId OPTIONAL,
+                0x30, 0x02,                     // AttributeDescriptionList ::= SEQUENCE OF AttributeDescription
+                  0x04, 0x00 
+            };
 
         Asn1Decoder ldapDecoder = new LdapDecoder();
 
@@ -248,14 +288,23 @@
     public void testDecodeSearchRequestExtensibleMatchEmptyType()
     {
         byte[] asn1BER = new byte[]
-            { 0x30, 0x3D, 0x02, 0x01, 0x04, // messageID
-                0x63, 0x38, 0x04, 0x1F, // baseObject LDAPDN,
-                'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=', 'e', 'x', 'a',
-                'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm', 0x0A, 0x01, 0x01, 0x0A, 0x01, 0x03, 0x02, 0x01,
-                0x00, 0x02, 0x01, 0x00, 0x01, 0x01, ( byte ) 0xFF, ( byte ) 0xA9, 0x02, ( byte ) 0x82, 0x00, 0x30,
-                0x02, // AttributeDescriptionList ::= SEQUENCE OF
-                        // AttributeDescription
-                0x04, 0x00 };
+            { 
+            0x30, 0x3D, 
+              0x02, 0x01, 0x04,                 // messageID
+              0x63, 0x38, 
+                0x04, 0x1F,                     // baseObject LDAPDN,
+                  'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=', 'e', 'x', 'a',
+                  'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm', 
+                0x0A, 0x01, 0x01, 
+                0x0A, 0x01, 0x03, 
+                0x02, 0x01, 0x00, 
+                0x02, 0x01, 0x00, 
+                0x01, 0x01, ( byte ) 0xFF, 
+                ( byte ) 0xA9, 0x02, 
+                  ( byte ) 0x82, 0x00,          //    type            [2] AttributeDescription OPTIONAL
+                0x30, 0x02,                     // AttributeDescriptionList ::= SEQUENCE OF AttributeDescription
+                  0x04, 0x00 
+            };
 
         Asn1Decoder ldapDecoder = new LdapDecoder();
 
@@ -293,15 +342,24 @@
     public void testDecodeSearchRequestExtensibleMatchEmptyMatchValue()
     {
         byte[] asn1BER = new byte[]
-            { 0x30, 0x43, 0x02, 0x01, 0x04, // messageID
-                0x63, 0x3E, 0x04, 0x1F, // baseObject LDAPDN,
-                'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=', 'e', 'x', 'a',
-                'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm', 0x0A, 0x01, 0x01, 0x0A, 0x01, 0x03, 0x02, 0x01,
-                0x00, 0x02, 0x01, 0x00, 0x01, 0x01, ( byte ) 0xFF, ( byte ) 0xA9, 0x08, ( byte ) 0x81, 0x04, 't', 'e',
-                's', 't', ( byte ) 0x83, 0x00, 0x30, 0x02, // AttributeDescriptionList
-                                                            // ::= SEQUENCE OF
-                                                            // AttributeDescription
-                0x04, 0x00 };
+            { 
+            0x30, 0x43, 
+              0x02, 0x01, 0x04,                 // messageID
+              0x63, 0x3E, 
+                0x04, 0x1F,                     // baseObject LDAPDN,
+                  'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=', 'e', 'x', 'a',
+                  'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm', 
+                  0x0A, 0x01, 0x01, 
+                  0x0A, 0x01, 0x03, 
+                  0x02, 0x01, 0x00, 
+                  0x02, 0x01, 0x00, 
+                  0x01, 0x01, ( byte ) 0xFF, 
+                  ( byte ) 0xA9, 0x08, 
+                    ( byte ) 0x81, 0x04, 't', 'e', 's', 't', 
+                    ( byte ) 0x83, 0x00,        //    matchValue      [3] AssertionValue,
+                0x30, 0x02,                     // AttributeDescriptionList ::= SEQUENCE OF AttributeDescription
+                  0x04, 0x00 
+            };
 
         Asn1Decoder ldapDecoder = new LdapDecoder();
 
@@ -366,15 +424,95 @@
     public void testDecodeSearchRequestExtensibleMatchMatchingRuleEmptyType()
     {
         byte[] asn1BER = new byte[]
-            { 0x30, 0x43, 0x02, 0x01, 0x04, // messageID
-                0x63, 0x3E, 0x04, 0x1F, // baseObject LDAPDN,
-                'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=', 'e', 'x', 'a',
-                'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm', 0x0A, 0x01, 0x01, 0x0A, 0x01, 0x03, 0x02, 0x01,
-                0x00, 0x02, 0x01, 0x00, 0x01, 0x01, ( byte ) 0xFF, ( byte ) 0xA9, 0x08, ( byte ) 0x81, 0x04, 't', 'e',
-                's', 't', ( byte ) 0x82, 0x00, 0x30, 0x02, // AttributeDescriptionList
-                                                            // ::= SEQUENCE OF
-                                                            // AttributeDescription
-                0x04, 0x00 };
+            { 
+            0x30, 0x43, 
+              0x02, 0x01, 0x04,                 // messageID
+              0x63, 0x3E, 
+                0x04, 0x1F,                     // baseObject LDAPDN,
+                  'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=', 'e', 'x', 'a',
+                  'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm', 
+                0x0A, 0x01, 0x01, 
+                0x0A, 0x01, 0x03, 
+                0x02, 0x01, 0x00, 
+                0x02, 0x01, 0x00, 
+                0x01, 0x01, ( byte ) 0xFF, 
+                ( byte ) 0xA9, 0x08, 
+                  ( byte ) 0x81, 0x04, 't', 'e', 's', 't', 
+                  ( byte ) 0x82, 0x00,          //    type            [2] AttributeDescription OPTIONAL,
+                0x30, 0x02,                     // AttributeDescriptionList ::= SEQUENCE OF AttributeDescription
+                0x04, 0x00 
+            };
+
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( asn1BER.length );
+        stream.put( asn1BER );
+        stream.flip();
+
+        // Allocate a LdapMessage Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        // Decode a SearchRequest message
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            assertTrue( true );
+            return;
+        }
+        catch ( NamingException ne )
+        {
+            ne.printStackTrace();
+            fail( ne.getMessage() );
+        }
+
+        fail( "We should not reach this point" );
+    }
+
+    /**
+     * Test the decoding of a SearchRequest with an extensible match and an
+     * matching rule and an empty dnAttributes
+     */
+    public void testDecodeSearchRequestExtensibleMatchDnAttributesEmptyType()
+    {
+        byte[] asn1BER = new byte[]
+            { 
+             0x30, 0x60,                     // LDAPMessage ::= SEQUENCE {
+               0x02, 0x01, 0x01,             //   messageID       MessageID,
+               0x63, 0x5B,                   //   protocolOp      CHOICE {
+                                             //     searchRequest   SearchRequest,
+                                             //
+                                             // SearchRequest ::= [APPLICATION 3] SEQUENCE {
+                 0x04, 0x11,                 //   baseObject      LDAPDN, (dc=example,dc=com)
+                   'd', 'c', '=', 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm',
+                                             //   scope           ENUMERATED {
+                 0x0A, 0x01, 0x00,           //      baseObject              (0), ...
+                                             //   derefAliases    ENUMERATED {
+                 0x0A, 0x01, 0x02,           //     derefFindingBaseObj     (2),...
+                 0x02, 0x01, 0x02,           //   sizeLimit       INTEGER (0 .. maxInt), (2)
+                 0x02, 0x01, 0x03,           //   timeLimit       INTEGER (0 .. maxInt), (3)
+                 0x01, 0x01, ( byte ) 0xFF,  //   typesOnly       BOOLEAN, (true)
+                 ( byte ) 0xA9, 0x20,        //   filter          Filter,
+                                             //
+                                             // Filter ::= CHOICE {
+                                             //   extensibleMatch [9] MatchingRuleAssertion }
+                                             //
+                                             // MatchingRuleAssertion ::= SEQUENCE {
+                   ( byte ) 0x81, 0x02,      //   matchingRule    [1] MatchingRuleId OPTIONAL,
+                     'c', 'n', 
+                   ( byte ) 0x82, 0x13,      //    type            [2] AttributeDescription OPTIONAL,
+                     '1', '.', '2', '.', '8', '4', '0', '.', '4', '8', '0', '1', '8', '.', '1', '.', '2', '.', '2', 
+                   ( byte ) 0x83, 0x03,      //    matchValue      [3] AssertionValue,
+                     'a', 'o', 'k', 
+                                             //    dnAttributes    [4] BOOLEAN DEFAULT FALSE  }
+                   ( byte ) 0x84, 0x00, 
+                 0x30, 0x15,                 // attributes      AttributeDescriptionList }
+                   0x04, 0x05, 'a', 't', 't', 'r', '0',
+                   0x04, 0x05, 'a', 't', 't', 'r', '1',
+                   0x04, 0x05, 'a', 't', 't', 'r', '2'
+            };
 
         Asn1Decoder ldapDecoder = new LdapDecoder();
 
@@ -412,14 +550,22 @@
     public void testDecodeSearchRequestExtensibleMatchMatchingRuleAlone()
     {
         byte[] asn1BER = new byte[]
-            { 0x30, 0x41, 0x02, 0x01, 0x04, // messageID
-                0x63, 0x3C, 0x04, 0x1F, // baseObject LDAPDN,
+            { 
+            0x30, 0x41, 
+              0x02, 0x01, 0x04, // messageID
+              0x63, 0x3C, 0x04, 0x1F, // baseObject LDAPDN,
                 'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=', 'e', 'x', 'a',
-                'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm', 0x0A, 0x01, 0x01, 0x0A, 0x01, 0x03, 0x02, 0x01,
-                0x00, 0x02, 0x01, 0x00, 0x01, 0x01, ( byte ) 0xFF, ( byte ) 0xA9, 0x06, ( byte ) 0x81, 0x04, 't', 'e',
-                's', 't', 0x30, 0x02, // AttributeDescriptionList ::= SEQUENCE
-                                        // OF AttributeDescription
-                0x04, 0x00 };
+                'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm', 
+              0x0A, 0x01, 0x01, 
+              0x0A, 0x01, 0x03, 
+              0x02, 0x01, 0x00, 
+              0x02, 0x01, 0x00, 
+              0x01, 0x01, ( byte ) 0xFF, 
+              ( byte ) 0xA9, 0x06, 
+                ( byte ) 0x81, 0x04, 't', 'e', 's', 't', 
+              0x30, 0x02, // AttributeDescriptionList ::= SEQUENCE OF AttributeDescription
+                0x04, 0x00 
+            };
 
         Asn1Decoder ldapDecoder = new LdapDecoder();
 
@@ -457,14 +603,22 @@
     public void testDecodeSearchRequestExtensibleMatchTypeAlone()
     {
         byte[] asn1BER = new byte[]
-            { 0x30, 0x43, 0x02, 0x01, 0x04, // messageID
-                0x63, 0x3E, 0x04, 0x1F, // baseObject LDAPDN,
+            { 
+            0x30, 0x43, 
+              0x02, 0x01, 0x04, // messageID
+              0x63, 0x3E, 0x04, 0x1F, // baseObject LDAPDN,
                 'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=', 'e', 'x', 'a',
-                'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm', 0x0A, 0x01, 0x01, 0x0A, 0x01, 0x03, 0x02, 0x01,
-                0x00, 0x02, 0x01, 0x00, 0x01, 0x01, ( byte ) 0xFF, ( byte ) 0xA9, 0x06, ( byte ) 0x82, 0x04, 't', 'e',
-                's', 't', 0x30, 0x02, // AttributeDescriptionList ::= SEQUENCE
-                                        // OF AttributeDescription
-                0x04, 0x00 };
+                'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm', 
+              0x0A, 0x01, 0x01, 
+              0x0A, 0x01, 0x03, 
+              0x02, 0x01, 0x00, 
+              0x02, 0x01, 0x00, 
+              0x01, 0x01, ( byte ) 0xFF, 
+              ( byte ) 0xA9, 0x06, 
+                ( byte ) 0x82, 0x04, 't', 'e', 's', 't', 
+              0x30, 0x02, // AttributeDescriptionList ::= SEQUENCE OF AttributeDescription
+                0x04, 0x00 
+            };
 
         Asn1Decoder ldapDecoder = new LdapDecoder();
 
@@ -502,14 +656,22 @@
     public void testDecodeSearchRequestExtensibleMatchMatchValueAlone()
     {
         byte[] asn1BER = new byte[]
-            { 0x30, 0x43, 0x02, 0x01, 0x04, // messageID
-                0x63, 0x3E, 0x04, 0x1F, // baseObject LDAPDN,
+            { 
+            0x30, 0x43, 
+              0x02, 0x01, 0x04, // messageID
+              0x63, 0x3E, 0x04, 0x1F, // baseObject LDAPDN,
                 'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=', 'e', 'x', 'a',
-                'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm', 0x0A, 0x01, 0x01, 0x0A, 0x01, 0x03, 0x02, 0x01,
-                0x00, 0x02, 0x01, 0x00, 0x01, 0x01, ( byte ) 0xFF, ( byte ) 0xA9, 0x06, ( byte ) 0x83, 0x04, 't', 'e',
-                's', 't', 0x30, 0x02, // AttributeDescriptionList ::= SEQUENCE
-                                        // OF AttributeDescription
-                0x04, 0x00 };
+                'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm', 
+              0x0A, 0x01, 0x01, 
+              0x0A, 0x01, 0x03, 
+              0x02, 0x01, 0x00, 
+              0x02, 0x01, 0x00, 
+              0x01, 0x01, ( byte ) 0xFF, 
+              ( byte ) 0xA9, 0x06, 
+                ( byte ) 0x83, 0x04, 't', 'e', 's', 't', 
+              0x30, 0x02, // AttributeDescriptionList ::= SEQUENCE OF AttributeDescription
+                0x04, 0x00 
+            };
 
         Asn1Decoder ldapDecoder = new LdapDecoder();
 



Mime
View raw message