directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r437712 - /directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/codec/compare/CompareRequestTest.java
Date Mon, 28 Aug 2006 14:06:29 GMT
Author: elecharny
Date: Mon Aug 28 07:06:27 2006
New Revision: 437712

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

Modified:
    directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/codec/compare/CompareRequestTest.java

Modified: directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/codec/compare/CompareRequestTest.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/codec/compare/CompareRequestTest.java?rev=437712&r1=437711&r2=437712&view=diff
==============================================================================
--- directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/codec/compare/CompareRequestTest.java
(original)
+++ directory/branches/shared/0.9.5/ldap/src/test/java/org/apache/directory/shared/ldap/codec/compare/CompareRequestTest.java
Mon Aug 28 07:06:27 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.compare.CompareRequest;
+import org.apache.directory.shared.ldap.message.CompareResponseImpl;
+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,19 +61,22 @@
         ByteBuffer stream = ByteBuffer.allocate( 0x38 );
 
         stream.put( new byte[]
-            { 0x30, 0x36, // LDAPMessage ::= SEQUENCE {
-                0x02, 0x01, 0x01, // messageID MessageID
-                // CHOICE { ..., compareRequest CompareRequest, ...
-                0x6E, 0x31, // CompareRequest ::= [APPLICATION 14] 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',
-                // ava AttributeValueAssertion }
+            { 
+            0x30, 0x36,                 // LDAPMessage ::= SEQUENCE {
+              0x02, 0x01, 0x01,         // messageID MessageID
+                                        // CHOICE { ..., compareRequest CompareRequest, ...
+              0x6E, 0x31,               // CompareRequest ::= [APPLICATION 14] 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',
+                                        // ava AttributeValueAssertion }
                 0x30, 0x0D, // AttributeValueAssertion ::= SEQUENCE {
-                // attributeDesc AttributeDescription,
-                0x04, 0x04, 't', 'e', 's', 't',
-                // assertionValue AssertionValue }
-                0x04, 0x05, 'v', 'a', 'l', 'u', 'e' } );
+                                        // attributeDesc AttributeDescription,
+                  0x04, 0x04, 't', 'e', 's', 't',
+                                        // assertionValue AssertionValue }
+                  0x04, 0x05, 'v', 'a', 'l', 'u', 'e' 
+            } );
 
         String decodedPdu = StringTools.dumpBytes( stream.array() );
         stream.flip();
@@ -127,10 +134,11 @@
         ByteBuffer stream = ByteBuffer.allocate( 0x07 );
 
         stream.put( new byte[]
-            { 0x30, 0x05, // LDAPMessage ::= SEQUENCE {
-                0x02, 0x01, 0x01, // messageID MessageID
-                // CHOICE { ..., compareRequest CompareRequest, ...
-                0x6E, 0x00 // CompareRequest ::= [APPLICATION 14] SEQUENCE {
+            { 
+            0x30, 0x05,                 // LDAPMessage ::= SEQUENCE {
+              0x02, 0x01, 0x01,         // messageID MessageID
+                                        // CHOICE { ..., compareRequest CompareRequest, ...
+              0x6E, 0x00                // CompareRequest ::= [APPLICATION 14] SEQUENCE {
             } );
 
         stream.flip();
@@ -161,17 +169,19 @@
         ByteBuffer stream = ByteBuffer.allocate( 0x18 );
 
         stream.put( new byte[]
-            { 0x30, 0x16, // LDAPMessage ::= SEQUENCE {
-                0x02, 0x01, 0x01, // messageID MessageID
-                // CHOICE { ..., compareRequest CompareRequest, ...
-                0x6E, 0x11, // CompareRequest ::= [APPLICATION 14] SEQUENCE {
-                0x04, 0x00, // entry LDAPDN,
-                // ava AttributeValueAssertion }
-                0x30, 0x0D, // AttributeValueAssertion ::= SEQUENCE {
-                // attributeDesc AttributeDescription,
-                0x04, 0x04, 't', 'e', 's', 't',
-                // assertionValue AssertionValue }
-                0x04, 0x05, 'v', 'a', 'l', 'u', 'e' } );
+            { 
+            0x30, 0x16,                 // LDAPMessage ::= SEQUENCE {
+              0x02, 0x01, 0x01,         // messageID MessageID
+                                        // CHOICE { ..., compareRequest CompareRequest, ...
+              0x6E, 0x11,               // CompareRequest ::= [APPLICATION 14] SEQUENCE {
+                0x04, 0x00,             // entry LDAPDN,
+                                        // ava AttributeValueAssertion }
+                0x30, 0x0D,             // AttributeValueAssertion ::= SEQUENCE {
+                                        // attributeDesc AttributeDescription,
+                  0x04, 0x04, 't', 'e', 's', 't',
+                                        // assertionValue AssertionValue }
+                  0x04, 0x05, 'v', 'a', 'l', 'u', 'e' 
+            } );
 
         stream.flip();
 
@@ -201,15 +211,17 @@
         ByteBuffer stream = ByteBuffer.allocate( 0x2B );
 
         stream.put( new byte[]
-            { 0x30, 0x29, // LDAPMessage ::= SEQUENCE {
-                0x02, 0x01, 0x01, // messageID MessageID
-                // CHOICE { ..., compareRequest CompareRequest, ...
-                0x6E, 0x24, // CompareRequest ::= [APPLICATION 14] 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',
-                // ava AttributeValueAssertion }
-                0x30, 0x00 // AttributeValueAssertion ::= SEQUENCE {
+            { 
+            0x30, 0x29,                 // LDAPMessage ::= SEQUENCE {
+              0x02, 0x01, 0x01,         // messageID MessageID
+                                        // CHOICE { ..., compareRequest CompareRequest, ...
+              0x6E, 0x24,               // CompareRequest ::= [APPLICATION 14] 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',
+                                        // ava AttributeValueAssertion }
+                0x30, 0x00              // AttributeValueAssertion ::= SEQUENCE {
             } );
 
         stream.flip();
@@ -229,6 +241,50 @@
         }
     }
 
+    /**
+     * Test the decoding of an empty ava
+     */
+    public void testDecodeCompareRequestInvalidDN() throws NamingException
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x2B );
+
+        stream.put( new byte[]
+            { 
+            0x30, 0x29,                 // LDAPMessage ::= SEQUENCE {
+              0x02, 0x01, 0x01,         // messageID MessageID
+                                        // CHOICE { ..., compareRequest CompareRequest, ...
+              0x6E, 0x24,               // CompareRequest ::= [APPLICATION 14] 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',
+                                        // ava AttributeValueAssertion }
+                0x30, 0x00              // AttributeValueAssertion ::= SEQUENCE {
+            } );
+
+        stream.flip();
+
+        // Allocate a LdapMessage Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        // Decode the CompareRequest PDU
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+            fail( "We should never reach this point !!!" );
+        }
+        catch ( DecoderException de )
+        {
+            assertTrue( de instanceof ResponseCarryingException );
+            Message response = ((ResponseCarryingException)de).getResponse();
+            assertTrue( response instanceof CompareResponseImpl );
+            assertEquals( ResultCodeEnum.INVALIDDNSYNTAX, ((CompareResponseImpl)response).getLdapResult().getResultCode()
);
+            return;
+        }
+    }
+
 
     /**
      * Test the decoding of an empty attributeDesc ava
@@ -240,16 +296,19 @@
         ByteBuffer stream = ByteBuffer.allocate( 0x2D );
 
         stream.put( new byte[]
-            { 0x30, 0x2B, // LDAPMessage ::= SEQUENCE {
-                0x02, 0x01, 0x01, // messageID MessageID
-                // CHOICE { ..., compareRequest CompareRequest, ...
-                0x6E, 0x26, // CompareRequest ::= [APPLICATION 14] SEQUENCE {
-                // entry LDAPDN,
-                0x04, 0x20, 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y',
',', 'o', 'u', '=', 'u',
+            { 
+            0x30, 0x2B,                 // LDAPMessage ::= SEQUENCE {
+              0x02, 0x01, 0x01,         // messageID MessageID
+                                        // CHOICE { ..., compareRequest CompareRequest, ...
+              0x6E, 0x26,               // CompareRequest ::= [APPLICATION 14] 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',
-                // ava AttributeValueAssertion }
-                0x30, 0x02, // AttributeValueAssertion ::= SEQUENCE {
-                0x04, 0x00 } );
+                                        // ava AttributeValueAssertion }
+              0x30, 0x02,               // AttributeValueAssertion ::= SEQUENCE {
+                0x04, 0x00 
+            } );
 
         stream.flip();
 
@@ -264,7 +323,11 @@
         }
         catch ( DecoderException de )
         {
-            assertTrue( true );
+            assertTrue( de instanceof ResponseCarryingException );
+            Message response = ((ResponseCarryingException)de).getResponse();
+            assertTrue( response instanceof CompareResponseImpl );
+            assertEquals( ResultCodeEnum.INVALIDATTRIBUTESYNTAX, ((CompareResponseImpl)response).getLdapResult().getResultCode()
);
+            return;
         }
     }
 
@@ -279,19 +342,22 @@
         ByteBuffer stream = ByteBuffer.allocate( 0x33 );
 
         stream.put( new byte[]
-            { 0x30, 0x31, // LDAPMessage ::= SEQUENCE {
-                0x02, 0x01, 0x01, // messageID MessageID
-                // CHOICE { ..., compareRequest CompareRequest, ...
-                0x6E, 0x2C, // CompareRequest ::= [APPLICATION 14] 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',
-                // ava AttributeValueAssertion }
-                0x30, 0x08, // AttributeValueAssertion ::= SEQUENCE {
-                // attributeDesc AttributeDescription,
-                0x04, 0x04, 't', 'e', 's', 't',
-                // assertionValue AssertionValue }
-                0x04, 0x00 } );
+            { 
+            0x30, 0x31,                 // LDAPMessage ::= SEQUENCE {
+              0x02, 0x01, 0x01,         // messageID MessageID
+                                        // CHOICE { ..., compareRequest CompareRequest, ...
+              0x6E, 0x2C,               // CompareRequest ::= [APPLICATION 14] 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',
+                                        // ava AttributeValueAssertion }
+                0x30, 0x08,             // AttributeValueAssertion ::= SEQUENCE {
+                                        // attributeDesc AttributeDescription,
+                  0x04, 0x04, 't', 'e', 's', 't',
+                                        // assertionValue AssertionValue }
+                  0x04, 0x00 
+            } );
 
         String decodedPdu = StringTools.dumpBytes( stream.array() );
         stream.flip();
@@ -349,22 +415,25 @@
         ByteBuffer stream = ByteBuffer.allocate( 0x55 );
 
         stream.put( new byte[]
-            { 0x30, 0x53, // LDAPMessage ::= SEQUENCE {
-                0x02, 0x01, 0x01, // messageID MessageID
-                // CHOICE { ..., compareRequest CompareRequest, ...
-                0x6E, 0x31, // CompareRequest ::= [APPLICATION 14] 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',
-                // ava AttributeValueAssertion }
-                0x30, 0x0D, // AttributeValueAssertion ::= SEQUENCE {
-                // attributeDesc AttributeDescription,
-                0x04, 0x04, 't', 'e', 's', 't',
-                // assertionValue AssertionValue }
-                0x04, 0x05, 'v', 'a', 'l', 'u', 'e', ( byte ) 0xA0, 0x1B, // A
-                                                                            // control
+            { 
+            0x30, 0x53,                 // LDAPMessage ::= SEQUENCE {
+              0x02, 0x01, 0x01,         // messageID MessageID
+                                        // CHOICE { ..., compareRequest CompareRequest, ...
+              0x6E, 0x31,               // CompareRequest ::= [APPLICATION 14] 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',
+                                        // ava AttributeValueAssertion }
+                0x30, 0x0D,             // AttributeValueAssertion ::= SEQUENCE {
+                                        // attributeDesc AttributeDescription,
+                  0x04, 0x04, 't', 'e', 's', 't',
+                                        // assertionValue AssertionValue }
+                  0x04, 0x05, 'v', 'a', 'l', 'u', 'e', 
+              ( byte ) 0xA0, 0x1B,      // A control
                 0x30, 0x19, 0x04, 0x17, 0x32, 0x2E, 0x31, 0x36, 0x2E, 0x38, 0x34, 0x30, 0x2E,
0x31, 0x2E, 0x31, 0x31,
-                0x33, 0x37, 0x33, 0x30, 0x2E, 0x33, 0x2E, 0x34, 0x2E, 0x32 } );
+                0x33, 0x37, 0x33, 0x30, 0x2E, 0x33, 0x2E, 0x34, 0x2E, 0x32 
+            } );
 
         String decodedPdu = StringTools.dumpBytes( stream.array() );
         stream.flip();



Mime
View raw message