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/01/06 00:40:02 UTC

svn commit: r366341 - /directory/trunk/ldap-common/src/test/java/org/apache/ldap/common/codec/bind/BindResponseTest.java

Author: elecharny
Date: Thu Jan  5 15:39:58 2006
New Revision: 366341

URL: http://svn.apache.org/viewcvs?rev=366341&view=rev
Log:
Added a testcase with a control in a BindResponse

Modified:
    directory/trunk/ldap-common/src/test/java/org/apache/ldap/common/codec/bind/BindResponseTest.java

Modified: directory/trunk/ldap-common/src/test/java/org/apache/ldap/common/codec/bind/BindResponseTest.java
URL: http://svn.apache.org/viewcvs/directory/trunk/ldap-common/src/test/java/org/apache/ldap/common/codec/bind/BindResponseTest.java?rev=366341&r1=366340&r2=366341&view=diff
==============================================================================
--- directory/trunk/ldap-common/src/test/java/org/apache/ldap/common/codec/bind/BindResponseTest.java (original)
+++ directory/trunk/ldap-common/src/test/java/org/apache/ldap/common/codec/bind/BindResponseTest.java Thu Jan  5 15:39:58 2006
@@ -108,6 +108,87 @@
     }
 
     /**
+     * Test the decoding of a BindResponse with a control
+     */
+    public void testDecodeBindResponseWithControlSuccess()
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x3C );
+        
+        stream.put(
+            new byte[]
+            {
+                0x30, 0x3A, 		// LDAPMessage ::=SEQUENCE {
+				0x02, 0x01, 0x01, 	//         messageID MessageID
+				0x61, 0x07, 		//        CHOICE { ..., bindResponse BindResponse, ...
+                        			// BindResponse ::= APPLICATION[1] SEQUENCE {
+									//        COMPONENTS OF LDAPResult,
+				0x0A, 0x01, 0x00, 	//   LDAPResult ::= SEQUENCE {
+									//		resultCode ENUMERATED {
+									//			success (0), ...
+				 					//      },
+				0x04, 0x00,			//		matchedDN    LDAPDN,
+				0x04, 0x00,  		//      errorMessage LDAPString,
+									//		referral     [3] Referral OPTIONAL }
+									// serverSaslCreds [7] OCTET STRING OPTIONAL }
+               (byte)0xa0, 0x2C, // controls
+                   0x30, 0x2A,
+                       0x04, 0x16,
+                           0x31, 0x2e, 0x32, 0x2e, 0x38, 0x34, 0x30, 0x2e, 0x31, 0x31,
+                                   0x33, 0x35, 0x35, 0x36, 0x2e, 0x31, 0x2e, 0x34, 0x2e, 0x33,
+                                   0x31, 0x39, // control oid: 1.2.840.113556.1.4.319
+                       0x01, 0x01, (byte)0xff, // criticality: false
+                       0x04, 0x0D,
+                         0x30, 0x0B, 0x0A, 0x01, 0x08, 0x04, 0x03, 'a', '=', 'b',	0x02, 0x01, 0x10
+            } );
+
+        String decodedPdu = StringTools.dumpBytes( stream.array() );
+        stream.flip();
+
+        // Allocate a LdapMessage Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        // Decode the BindResponse PDU
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            Assert.fail( de.getMessage() );
+        }
+    	
+        // Check the decoded BindResponse
+        LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+        BindResponse br      = message.getBindResponse();
+
+        Assert.assertEquals( 1, message.getMessageId() );
+        Assert.assertEquals( 0, br.getLdapResult().getResultCode() );
+        Assert.assertEquals( "", br.getLdapResult().getMatchedDN() );
+        Assert.assertEquals( "", br.getLdapResult().getErrorMessage() );
+
+        // Check the length
+        Assert.assertEquals(0x3C, message.computeLength());
+
+        // Check the encoding
+        try
+        {
+            ByteBuffer bb = message.encode( null );
+            
+            String encodedPdu = StringTools.dumpBytes( bb.array() ); 
+            
+            Assert.assertEquals(encodedPdu, decodedPdu );
+        }
+        catch ( EncoderException ee )
+        {
+            ee.printStackTrace();
+            Assert.fail( ee.getMessage() );
+        }
+    }
+
+    /**
      * Test the decoding of a BindResponse with a credentials
      */
     public void testDecodeBindResponseServerSASL()