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 2005/09/04 14:46:50 UTC

svn commit: r278586 - /directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/BindRequestTest.java

Author: elecharny
Date: Sun Sep  4 05:46:45 2005
New Revision: 278586

URL: http://svn.apache.org/viewcvs?rev=278586&view=rev
Log:
Added a test : a BindRequest with a null name (anonymous authentication)

Modified:
    directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/BindRequestTest.java

Modified: directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/BindRequestTest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/BindRequestTest.java?rev=278586&r1=278585&r2=278586&view=diff
==============================================================================
--- directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/BindRequestTest.java (original)
+++ directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/BindRequestTest.java Sun Sep  4 05:46:45 2005
@@ -107,10 +107,11 @@
     }
 
     /**
-     * Test the decoding of a BindRequest with Simple authentication
+     * Test the decoding of a BindRequest with Simple authentication,
+     * no name
      * and no controls
      */
-    public void testDecodeBindRequestNoName()
+    public void testDecodeBindRequestSimpleNoName()
     {
         Asn1Decoder ldapDecoder = new LdapDecoder();
 
@@ -145,6 +146,77 @@
         }
     	
         Assert.fail("Should never reach this point.");
+    }
+
+    /**
+     * Test the decoding of a BindRequest with Simple authentication,
+     * empty name (an anonymous bind)
+     * and no controls
+     */
+    public void testDecodeBindRequestSimpleEmptyName()
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x16 );
+        stream.put(
+            new byte[]
+            {
+                0x30, 0x14, 		 // LDAPMessage ::=SEQUENCE {
+				0x02, 0x01, 0x01, 	 //         messageID MessageID
+				0x60, 0x0F, 		 //        CHOICE { ..., bindRequest BindRequest, ...
+                        			 // BindRequest ::= APPLICATION[0] SEQUENCE {
+				0x02, 0x01, 0x03, 	 //        version INTEGER (1..127),
+				0x04, 0x00,          //        name LDAPDN,
+				( byte ) 0x80, 0x08, //        authentication AuthenticationChoice
+                                     // AuthenticationChoice ::= CHOICE { simple [0] OCTET STRING, ...
+				'p', 'a', 's', 's', 'w', 'o', 'r', 'd'
+            } );
+
+        String decodedPdu = StringUtils.dumpBytes( stream.array() );
+
+        stream.flip();
+
+        // Allocate a LdapMessage Container
+        IAsn1Container ldapMessageContainer =  new LdapMessageContainer();
+
+        // Decode the BindRequest PDU
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            Assert.fail( de.getMessage() );
+        }
+
+        // Check the decoded BindRequest 
+        LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+        BindRequest br      = message.getBindRequest();
+
+        Assert.assertEquals( 1, message.getMessageId() );
+        Assert.assertEquals( 3, br.getVersion() );
+        Assert.assertEquals( "", br.getName() );
+        Assert.assertEquals( true, ( br.getAuthentication() instanceof SimpleAuthentication ) );
+        Assert.assertEquals( "password", ( ( (SimpleAuthentication)br.getAuthentication() ).getSimple().toString() ) );
+
+        // Check the length
+        Assert.assertEquals(0x16, message.computeLength());
+        
+        // Check the encoding
+        try
+        {
+            ByteBuffer bb = message.encode( null );
+            
+            String encodedPdu = StringUtils.dumpBytes( bb.array() ); 
+            
+            Assert.assertEquals(encodedPdu, decodedPdu );
+        }
+        catch ( EncoderException ee )
+        {
+            ee.printStackTrace();
+            Assert.fail( ee.getMessage() );
+        }
     }
 
     /**