directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r437706 - /directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/codec/del/DelRequestTest.java
Date Mon, 28 Aug 2006 13:43:03 GMT
Author: elecharny
Date: Mon Aug 28 06:43:02 2006
New Revision: 437706

URL: http://svn.apache.org/viewvc?rev=437706&view=rev
Log:
- Reformated the PDUs
- Added one to check throwed Exceptions

Modified:
    directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/codec/del/DelRequestTest.java

Modified: directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/codec/del/DelRequestTest.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/codec/del/DelRequestTest.java?rev=437706&r1=437705&r2=437706&view=diff
==============================================================================
--- directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/codec/del/DelRequestTest.java
(original)
+++ directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/codec/del/DelRequestTest.java
Mon Aug 28 06:43:02 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.del.DelRequest;
+import org.apache.directory.shared.ldap.message.DeleteResponseImpl;
+import org.apache.directory.shared.ldap.message.Message;
+import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.util.StringTools;
 
 import junit.framework.TestCase;
@@ -57,13 +61,14 @@
 
         stream.put( new byte[]
             {
-
-            0x30, 0x25, // LDAPMessage ::= SEQUENCE {
-                0x02, 0x01, 0x01, // messageID MessageID
-                // CHOICE { ..., delRequest DelRequest, ...
-                // DelRequest ::= [APPLICATION 10] LDAPDN;
-                0x4A, 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, 0x25,                 // LDAPMessage ::= SEQUENCE {
+              0x02, 0x01, 0x01,         // messageID MessageID
+                                        // CHOICE { ..., delRequest DelRequest, ...
+                                        // DelRequest ::= [APPLICATION 10] LDAPDN;
+              0x4A, 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' 
+            } );
 
         String decodedPdu = StringTools.dumpBytes( stream.array() );
         stream.flip();
@@ -108,6 +113,47 @@
         }
     }
 
+    /**
+     * Test the decoding of a full DelRequest
+     */
+    public void testDecodeDelRequestBadDN() throws NamingException
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x27 );
+
+        stream.put( new byte[]
+            {
+            0x30, 0x25,                 // LDAPMessage ::= SEQUENCE {
+              0x02, 0x01, 0x01,         // messageID MessageID
+                                        // CHOICE { ..., delRequest DelRequest, ...
+                                        // DelRequest ::= [APPLICATION 10] LDAPDN;
+              0x4A, 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();
+
+        // Allocate a LdapMessage Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        // Decode a DelRequest PDU
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            assertTrue( de instanceof ResponseCarryingException );
+            Message response = ((ResponseCarryingException)de).getResponse();
+            assertTrue( response instanceof DeleteResponseImpl );
+            assertEquals( ResultCodeEnum.INVALIDDNSYNTAX, ((DeleteResponseImpl)response).getLdapResult().getResultCode()
);
+            return;
+        }
+
+        fail( "We should not reach this point" );
+    }
 
     /**
      * Test the decoding of an empty DelRequest
@@ -120,12 +166,11 @@
 
         stream.put( new byte[]
             {
-
-            0x30, 0x05, // LDAPMessage ::= SEQUENCE {
-                0x02, 0x01, 0x01, // messageID MessageID
-                // CHOICE { ..., delRequest DelRequest, ...
-                // DelRequest ::= [APPLICATION 10] LDAPDN;
-                0x4A, 0x00 // Empty DN
+            0x30, 0x05,                 // LDAPMessage ::= SEQUENCE {
+              0x02, 0x01, 0x01,         // messageID MessageID
+                                        // CHOICE { ..., delRequest DelRequest, ...
+                                        // DelRequest ::= [APPLICATION 10] LDAPDN;
+              0x4A, 0x00                // Empty DN
             } );
 
         stream.flip();
@@ -157,16 +202,17 @@
 
         stream.put( new byte[]
             {
-
-            0x30, 0x42, // LDAPMessage ::= SEQUENCE {
-                0x02, 0x01, 0x01, // messageID MessageID
-                // CHOICE { ..., delRequest DelRequest, ...
-                // DelRequest ::= [APPLICATION 10] LDAPDN;
-                0x4A, 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', ( byte
) 0xA0, 0x1B, // A
-                                                                                        
                   // control
+            0x30, 0x42,                 // LDAPMessage ::= SEQUENCE {
+              0x02, 0x01, 0x01,         // messageID MessageID
+                                        // CHOICE { ..., delRequest DelRequest, ...
+                                        // DelRequest ::= [APPLICATION 10] LDAPDN;
+              0x4A, 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', 
+              ( 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();



Mime
View raw message