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/17 14:49:51 UTC
svn commit: r369774 - in /directory/trunks/common/ldap/src:
main/java/org/apache/ldap/common/codec/bind/SimpleAuthentication.java
test/java/org/apache/ldap/common/codec/bind/BindRequestTest.java
Author: elecharny
Date: Tue Jan 17 05:49:41 2006
New Revision: 369774
URL: http://svn.apache.org/viewcvs?rev=369774&view=rev
Log:
- Added some tests case
- Modified logs
Modified:
directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/bind/SimpleAuthentication.java
directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/bind/BindRequestTest.java
Modified: directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/bind/SimpleAuthentication.java
URL: http://svn.apache.org/viewcvs/directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/bind/SimpleAuthentication.java?rev=369774&r1=369773&r2=369774&view=diff
==============================================================================
--- directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/bind/SimpleAuthentication.java (original)
+++ directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/bind/SimpleAuthentication.java Tue Jan 17 05:49:41 2006
@@ -82,7 +82,7 @@
if ( log.isDebugEnabled() )
{
- log.debug( "Simple Authentication length : " + length );
+ log.debug( "Simple Authentication length : {}", new Integer( length ) );
}
return length;
Modified: directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/bind/BindRequestTest.java
URL: http://svn.apache.org/viewcvs/directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/bind/BindRequestTest.java?rev=369774&r1=369773&r2=369774&view=diff
==============================================================================
--- directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/bind/BindRequestTest.java (original)
+++ directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/bind/BindRequestTest.java Tue Jan 17 05:49:41 2006
@@ -698,4 +698,177 @@
fail( ee.getMessage() );
}
}
+
+ /**
+ * Test the decoding of a BindRequest with an empty sasl
+ */
+ public void testDecodeBindRequestEmptySasl()
+ {
+ Asn1Decoder ldapDecoder = new LdapDecoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x0E );
+ stream.put(
+ new byte[]
+ {
+ 0x30, 0x0C, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x60, 0x07, // CHOICE { ..., bindRequest BindRequest, ...
+ 0x02, 0x01, 0x03, // version INTEGER (1..127),
+ 0x04, 0x00,
+ (byte)0xA3, 0x00
+ } );
+
+ stream.flip();
+
+ // Allocate a LdapMessage Container
+ IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+ // Decode a BindRequest message
+ try
+ {
+ ldapDecoder.decode( stream, ldapMessageContainer );
+ }
+ catch ( DecoderException de )
+ {
+ System.out.println( de.getMessage() );
+ assertTrue( true );
+ return;
+ }
+
+ fail( "We should not reach this point" );
+ }
+
+ /**
+ * Test the decoding of a BindRequest with an empty mechanism
+ */
+ public void testDecodeBindRequestEmptyMechanism()
+ {
+ Asn1Decoder ldapDecoder = new LdapDecoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x10 );
+ stream.put(
+ new byte[]
+ {
+ 0x30, 0x0E, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x60, 0x09, // CHOICE { ..., bindRequest BindRequest, ...
+ 0x02, 0x01, 0x03, // version INTEGER (1..127),
+ 0x04, 0x00,
+ (byte)0xA3, 0x02,
+ 0x04, 0x00
+ } );
+
+ String decodedPdu = StringTools.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();
+ fail( de.getMessage() );
+ }
+
+ // Check the decoded BindRequest
+ LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+ BindRequest br = message.getBindRequest();
+
+ assertEquals( 1, message.getMessageId() );
+ assertEquals( 3, br.getVersion() );
+ assertEquals( "", br.getName() );
+ assertEquals( true, ( br.getAuthentication() instanceof SaslCredentials ) );
+ assertEquals( "", ( ( SaslCredentials ) br.getAuthentication() ).getMechanism() );
+
+ // Check the length
+ assertEquals(0x10, message.computeLength());
+
+ // Check the encoding
+ try
+ {
+ ByteBuffer bb = message.encode( null );
+
+ String encodedPdu = StringTools.dumpBytes( bb.array() );
+
+ assertEquals(encodedPdu, decodedPdu );
+ }
+ catch ( EncoderException ee )
+ {
+ ee.printStackTrace();
+ fail( ee.getMessage() );
+ }
+ }
+
+ /**
+ * Test the decoding of a BindRequest with an empty credentials
+ */
+ public void testDecodeBindRequestEmptyCredentials()
+ {
+ Asn1Decoder ldapDecoder = new LdapDecoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x12 );
+ stream.put(
+ new byte[]
+ {
+ 0x30, 0x10, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x60, 0x0B, // CHOICE { ..., bindRequest BindRequest, ...
+ 0x02, 0x01, 0x03, // version INTEGER (1..127),
+ 0x04, 0x00,
+ (byte)0xA3, 0x04,
+ 0x04, 0x00,
+ 0x04, 0x00
+ } );
+
+ String decodedPdu = StringTools.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();
+ fail( de.getMessage() );
+ }
+
+ // Check the decoded BindRequest
+ LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+ BindRequest br = message.getBindRequest();
+
+ assertEquals( 1, message.getMessageId() );
+ assertEquals( 3, br.getVersion() );
+ assertEquals( "", br.getName() );
+ assertEquals( true, ( br.getAuthentication() instanceof SaslCredentials ) );
+ assertEquals( "", ( ( SaslCredentials ) br.getAuthentication() ).getMechanism() );
+ assertEquals( "", StringTools.utf8ToString( ( ( SaslCredentials ) br.getAuthentication() ).getCredentials() ) );
+
+ // Check the length
+ assertEquals(0x12, message.computeLength());
+
+ // Check the encoding
+ try
+ {
+ ByteBuffer bb = message.encode( null );
+
+ String encodedPdu = StringTools.dumpBytes( bb.array() );
+
+ assertEquals(encodedPdu, decodedPdu );
+ }
+ catch ( EncoderException ee )
+ {
+ ee.printStackTrace();
+ fail( ee.getMessage() );
+ }
+ }
}