You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2006/09/08 18:44:44 UTC

svn commit: r441561 - /directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/test/java/org/apache/directory/shared/ldap/codec/asn1ber/messages/bind/BindRequestDecoratorTest.java

Author: elecharny
Date: Fri Sep  8 09:44:43 2006
New Revision: 441561

URL: http://svn.apache.org/viewvc?view=rev&rev=441561
Log:
Added a complete encoding test (not working atm)

Modified:
    directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/test/java/org/apache/directory/shared/ldap/codec/asn1ber/messages/bind/BindRequestDecoratorTest.java

Modified: directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/test/java/org/apache/directory/shared/ldap/codec/asn1ber/messages/bind/BindRequestDecoratorTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/test/java/org/apache/directory/shared/ldap/codec/asn1ber/messages/bind/BindRequestDecoratorTest.java?view=diff&rev=441561&r1=441560&r2=441561
==============================================================================
--- directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/test/java/org/apache/directory/shared/ldap/codec/asn1ber/messages/bind/BindRequestDecoratorTest.java (original)
+++ directory/sandbox/akarasulu/apacheds-2.0/shared/ldap/src/test/java/org/apache/directory/shared/ldap/codec/asn1ber/messages/bind/BindRequestDecoratorTest.java Fri Sep  8 09:44:43 2006
@@ -19,6 +19,10 @@
  */
 package org.apache.directory.shared.ldap.codec.asn1ber.messages.bind;
 
+import java.nio.ByteBuffer;
+
+import org.apache.directory.shared.asn1.ber.tlv.ValueException;
+import org.apache.directory.shared.ldap.codec.EncoderException;
 import org.apache.directory.shared.ldap.codec.asn1ber.messages.bind.BindRequestAsn1Ber;
 import org.apache.directory.shared.ldap.messages.Message;
 import org.apache.directory.shared.ldap.messages.bind.ConcreteBindRequest;
@@ -60,7 +64,7 @@
         
         int length = bindRequestDecorator.computeLength();
         
-        assertEquals( 13, length );
+        assertEquals( 18, length );
     }
 
     /**
@@ -86,6 +90,71 @@
         
         int length = bindRequestDecorator.computeLength();
         
-        assertEquals( 21, length );
+        assertEquals( 26, length );
+    }
+    
+    /**
+     * Test the decoding of a BindRequest with Simple authentication and no
+     * controls
+     */
+    public void testDecodeBindRequestSimpleNoControls()
+    {
+        ByteBuffer stream = ByteBuffer.allocate( 0x52 );
+        stream.put( new byte[]
+            { 
+            0x30, 0x50,                 // LDAPMessage ::=SEQUENCE {
+              0x02, 0x01, 0x01,         // messageID MessageID
+              0x60, 0x2E,               // CHOICE { ..., bindRequest BindRequest, ...
+                                        // BindRequest ::= APPLICATION[0] SEQUENCE {
+                0x02, 0x01, 0x03,       // version INTEGER (1..127),
+                0x04, 0x1F,             // name 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', 
+                ( byte ) 0x80, 0x08,    // authentication AuthenticationChoice
+                                        // AuthenticationChoice ::= CHOICE { simple [0] OCTET STRING,
+                                        // ...
+                  'p', 'a', 's', 's', 'w', 'o', 'r', 'd', 
+              ( byte ) 0xA0, 0x1B, // A control
+                0x30, 0x19, 
+                  0x04, 0x17, 
+                    0x32, 0x2E, 0x31, 0x36, 0x2E, 0x38, 0x34, 0x30, 0x2E, 0x31, 0x2E, 0x31, 0x31, 0x33, 0x37, 0x33, 
+                    0x30, 0x2E, 0x33, 0x2E, 0x34, 0x2E, 0x32 
+            } );
+
+        String decodedPdu = StringTools.dumpBytes( stream.array() );
+        stream.flip();
+
+        // Create a BindRequest message
+        BindRequest bindRequest = new ConcreteBindRequest( 1 );
+
+        bindRequest.setName( new LdapDN() );
+        bindRequest.setVersion( 3 );
+        
+        ConcreteSimpleAuthentication simpleAuthentication = new ConcreteSimpleAuthentication();
+        simpleAuthentication.setSimple( StringTools.getBytesUtf8( "test" ) );
+        
+        bindRequest.setAuthentication( simpleAuthentication );
+        
+        BindRequestAsn1Ber bindRequestDecorator = new BindRequestAsn1Ber( (Message)bindRequest );
+
+        // Check the encoding
+        try
+        {
+            ByteBuffer bb = bindRequestDecorator.encode( null );
+
+            String encodedPdu = StringTools.dumpBytes( bb.array() );
+
+            assertEquals( encodedPdu, decodedPdu );
+        }
+        catch( EncoderException ee )
+        {
+            ee.printStackTrace();
+            fail( ee.getMessage() );
+        }
+        catch ( ValueException ve )
+        {
+            ve.printStackTrace();
+            fail( ve.getMessage() );
+        }
     }
 }