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/08/31 12:33:48 UTC
svn commit: r438859 [2/4] - in /directory/trunks/shared/ldap: ./
src/main/java/org/apache/directory/shared/ldap/codec/
src/main/java/org/apache/directory/shared/ldap/codec/abandon/
src/main/java/org/apache/directory/shared/ldap/codec/add/ src/main/java...
Modified: directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/codec/add/AddRequestTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/codec/add/AddRequestTest.java?rev=438859&r1=438858&r2=438859&view=diff
==============================================================================
--- directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/codec/add/AddRequestTest.java (original)
+++ directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/codec/add/AddRequestTest.java Thu Aug 31 03:33:43 2006
@@ -38,7 +38,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.add.AddRequest;
+import org.apache.directory.shared.ldap.message.AddResponseImpl;
+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;
@@ -61,28 +65,33 @@
ByteBuffer stream = ByteBuffer.allocate( 0x59 );
stream.put( new byte[]
- { 0x30, 0x57, // LDAPMessage ::= SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- 0x68, 0x52, // CHOICE { ..., addRequest AddRequest, ...
- // AddRequest ::= [APPLICATION 8] SEQUENCE {
- // entry LDAPDN,
- 0x04, 0x20, 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
+ {
+ 0x30, 0x57, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x68, 0x52, // CHOICE { ..., addRequest AddRequest, ...
+ // AddRequest ::= [APPLICATION 8] 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',
- // attributes AttributeList }
- 0x30, 0x2E, // AttributeList ::= SEQUENCE OF SEQUENCE {
- 0x30, 0x0c, // attribute 1
- 0x04, 0x01, 'l', // type AttributeDescription,
- 0x31, 0x07, // vals SET OF AttributeValue }
- 0x04, 0x05, 'P', 'a', 'r', 'i', 's',
-
- 0x30, 0x1E, // attribute 2
- // type AttributeDescription,
- 0x04, 0x05, 'a', 't', 't', 'r', 's', 0x31, 0x15, // vals SET
- // OF
- // AttributeValue
- // }
- 0x04, 0x05, 't', 'e', 's', 't', '1', 0x04, 0x05, 't', 'e', 's', 't', '2', 0x04, 0x05, 't', 'e', 's',
- 't', '3', } );
+ // attributes AttributeList }
+ 0x30, 0x2E, // AttributeList ::= SEQUENCE OF SEQUENCE {
+ 0x30, 0x0c, // attribute 1
+ 0x04, 0x01, 'l', // type AttributeDescription,
+ 0x31, 0x07, // vals SET OF AttributeValue }
+ 0x04, 0x05, 'P', 'a', 'r', 'i', 's',
+
+ 0x30, 0x1E, // attribute 2
+ // type AttributeDescription,
+ 0x04, 0x05, 'a', 't', 't', 'r', 's',
+ 0x31, 0x15, // vals SET
+ // OF
+ // AttributeValue
+ // }
+ 0x04, 0x05, 't', 'e', 's', 't', '1',
+ 0x04, 0x05, 't', 'e', 's', 't', '2',
+ 0x04, 0x05, 't', 'e', 's', 't', '3',
+ } );
String decodedPdu = StringTools.dumpBytes( stream.array() );
stream.flip();
@@ -191,9 +200,10 @@
ByteBuffer stream = ByteBuffer.allocate( 0x07 );
stream.put( new byte[]
- { 0x30, 0x05, // LDAPMessage ::= SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- 0x68, 0x00 // CHOICE { ..., addRequest AddRequest, ...
+ {
+ 0x30, 0x05, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x68, 0x00 // CHOICE { ..., addRequest AddRequest, ...
} );
stream.flip();
@@ -226,27 +236,31 @@
ByteBuffer stream = ByteBuffer.allocate( 0x39 );
stream.put( new byte[]
- { 0x30, 0x37, // LDAPMessage ::= SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- 0x68, 0x26, // CHOICE { ..., addRequest AddRequest, ...
- // AddRequest ::= [APPLICATION 8] SEQUENCE {
- // entry LDAPDN,
+ {
+ 0x30, 0x37, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x68, 0x26, // CHOICE { ..., addRequest AddRequest, ...
+ // AddRequest ::= [APPLICATION 8] SEQUENCE {
+ // entry LDAPDN,
0x04, 0x00,
- // attributes AttributeList }
- 0x30, 0x2E, // AttributeList ::= SEQUENCE OF SEQUENCE {
- 0x30, 0x0c, // attribute 1
- 0x04, 0x01, 'l', // type AttributeDescription,
- 0x31, 0x07, // vals SET OF AttributeValue }
- 0x04, 0x05, 'P', 'a', 'r', 'i', 's',
-
- 0x30, 0x1E, // attribute 2
- // type AttributeDescription,
- 0x04, 0x05, 'a', 't', 't', 'r', 's', 0x31, 0x15, // vals SET
- // OF
- // AttributeValue
- // }
- 0x04, 0x05, 't', 'e', 's', 't', '1', 0x04, 0x05, 't', 'e', 's', 't', '2', 0x04, 0x05, 't', 'e', 's',
- 't', '3', } );
+ // attributes AttributeList }
+ 0x30, 0x2E, // AttributeList ::= SEQUENCE OF SEQUENCE {
+ 0x30, 0x0c, // attribute 1
+ 0x04, 0x01, 'l', // type AttributeDescription,
+ 0x31, 0x07, // vals SET OF AttributeValue }
+ 0x04, 0x05, 'P', 'a', 'r', 'i', 's',
+
+ 0x30, 0x1E, // attribute 2
+ // type AttributeDescription,
+ 0x04, 0x05, 'a', 't', 't', 'r', 's',
+ 0x31, 0x15, // vals SET
+ // OF
+ // AttributeValue
+ // }
+ 0x04, 0x05, 't', 'e', 's', 't', '1',
+ 0x04, 0x05, 't', 'e', 's', 't', '2',
+ 0x04, 0x05, 't', 'e', 's', 't', '3',
+ } );
stream.flip();
@@ -260,13 +274,75 @@
}
catch ( DecoderException de )
{
- assertTrue( true );
+ assertTrue( de instanceof ResponseCarryingException );
+ Message response = ((ResponseCarryingException)de).getResponse();
+ assertTrue( response instanceof AddResponseImpl );
+ assertEquals( ResultCodeEnum.NAMINGVIOLATION, ((AddResponseImpl)response).getLdapResult().getResultCode() );
return;
}
fail( "We should not reach this point" );
}
+ /**
+ * Test the decoding of a AddRequest
+ */
+ public void testDecodeAddRequestbadDN() throws NamingException
+ {
+ Asn1Decoder ldapDecoder = new LdapDecoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x59 );
+
+ stream.put( new byte[]
+ {
+ 0x30, 0x57, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x68, 0x52, // CHOICE { ..., addRequest AddRequest, ...
+ // AddRequest ::= [APPLICATION 8] 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',
+ // attributes AttributeList }
+ 0x30, 0x2E, // AttributeList ::= SEQUENCE OF SEQUENCE {
+ 0x30, 0x0c, // attribute 1
+ 0x04, 0x01, 'l', // type AttributeDescription,
+ 0x31, 0x07, // vals SET OF AttributeValue }
+ 0x04, 0x05, 'P', 'a', 'r', 'i', 's',
+
+ 0x30, 0x1E, // attribute 2
+ // type AttributeDescription,
+ 0x04, 0x05, 'a', 't', 't', 'r', 's',
+ 0x31, 0x15, // vals SET
+ // OF
+ // AttributeValue
+ // }
+ 0x04, 0x05, 't', 'e', 's', 't', '1',
+ 0x04, 0x05, 't', 'e', 's', 't', '2',
+ 0x04, 0x05, 't', 'e', 's', 't', '3',
+ } );
+
+ stream.flip();
+
+ // Allocate a LdapMessage Container
+ IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+ // Decode a AddRequest message
+ try
+ {
+ ldapDecoder.decode( stream, ldapMessageContainer );
+ }
+ catch ( DecoderException de )
+ {
+ assertTrue( de instanceof ResponseCarryingException );
+ Message response = ((ResponseCarryingException)de).getResponse();
+ assertTrue( response instanceof AddResponseImpl );
+ assertEquals( ResultCodeEnum.INVALIDDNSYNTAX, ((AddResponseImpl)response).getLdapResult().getResultCode() );
+ return;
+ }
+
+ fail( "We should not reach this point" );
+ }
/**
* Test the decoding of a AddRequest with a null attributeList
@@ -278,15 +354,17 @@
ByteBuffer stream = ByteBuffer.allocate( 0x2B );
stream.put( new byte[]
- { 0x30, 0x29, // LDAPMessage ::= SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- 0x68, 0x24, // CHOICE { ..., addRequest AddRequest, ...
- // AddRequest ::= [APPLICATION 8] 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',
- // attributes AttributeList }
- 0x30, 0x00, // AttributeList ::= SEQUENCE OF SEQUENCE {
+ {
+ 0x30, 0x29, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x68, 0x24, // CHOICE { ..., addRequest AddRequest, ...
+ // AddRequest ::= [APPLICATION 8] 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',
+ // attributes AttributeList }
+ 0x30, 0x00, // AttributeList ::= SEQUENCE OF SEQUENCE {
} );
stream.flip();
@@ -319,16 +397,18 @@
ByteBuffer stream = ByteBuffer.allocate( 0x2D );
stream.put( new byte[]
- { 0x30, 0x2B, // LDAPMessage ::= SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- 0x68, 0x26, // CHOICE { ..., addRequest AddRequest, ...
- // AddRequest ::= [APPLICATION 8] 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',
- // attributes AttributeList }
- 0x30, 0x02, // AttributeList ::= SEQUENCE OF SEQUENCE {
- 0x30, 0x00, // AttributeList ::= SEQUENCE OF SEQUENCE {
+ {
+ 0x30, 0x2B, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x68, 0x26, // CHOICE { ..., addRequest AddRequest, ...
+ // AddRequest ::= [APPLICATION 8] 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',
+ // attributes AttributeList }
+ 0x30, 0x02, // AttributeList ::= SEQUENCE OF SEQUENCE {
+ 0x30, 0x00, // AttributeList ::= SEQUENCE OF SEQUENCE {
} );
stream.flip();
@@ -361,17 +441,19 @@
ByteBuffer stream = ByteBuffer.allocate( 0x2F );
stream.put( new byte[]
- { 0x30, 0x2D, // LDAPMessage ::= SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- 0x68, 0x28, // CHOICE { ..., addRequest AddRequest, ...
- // AddRequest ::= [APPLICATION 8] 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',
- // attributes AttributeList }
- 0x30, 0x04, // AttributeList ::= SEQUENCE OF SEQUENCE {
- 0x30, 0x02, // attribute 1
- 0x04, 0x00, // type AttributeDescription,
+ {
+ 0x30, 0x2D, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x68, 0x28, // CHOICE { ..., addRequest AddRequest, ...
+ // AddRequest ::= [APPLICATION 8] 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',
+ // attributes AttributeList }
+ 0x30, 0x04, // AttributeList ::= SEQUENCE OF SEQUENCE {
+ 0x30, 0x02, // attribute 1
+ 0x04, 0x00, // type AttributeDescription,
} );
stream.flip();
@@ -386,7 +468,10 @@
}
catch ( DecoderException de )
{
- assertTrue( true );
+ assertTrue( de instanceof ResponseCarryingException );
+ Message response = ((ResponseCarryingException)de).getResponse();
+ assertTrue( response instanceof AddResponseImpl );
+ assertEquals( ResultCodeEnum.INVALIDATTRIBUTESYNTAX, ((AddResponseImpl)response).getLdapResult().getResultCode() );
return;
}
@@ -404,17 +489,19 @@
ByteBuffer stream = ByteBuffer.allocate( 0x30 );
stream.put( new byte[]
- { 0x30, 0x2E, // LDAPMessage ::= SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- 0x68, 0x29, // CHOICE { ..., addRequest AddRequest, ...
- // AddRequest ::= [APPLICATION 8] 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',
- // attributes AttributeList }
- 0x30, 0x05, // AttributeList ::= SEQUENCE OF SEQUENCE {
- 0x30, 0x03, // attribute 1
- 0x04, 0x01, 'A', // type AttributeDescription,
+ {
+ 0x30, 0x2E, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x68, 0x29, // CHOICE { ..., addRequest AddRequest, ...
+ // AddRequest ::= [APPLICATION 8] 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',
+ // attributes AttributeList }
+ 0x30, 0x05, // AttributeList ::= SEQUENCE OF SEQUENCE {
+ 0x30, 0x03, // attribute 1
+ 0x04, 0x01, 'A', // type AttributeDescription,
} );
stream.flip();
@@ -447,18 +534,21 @@
ByteBuffer stream = ByteBuffer.allocate( 0x32 );
stream.put( new byte[]
- { 0x30, 0x30, // LDAPMessage ::= SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- 0x68, 0x2B, // CHOICE { ..., addRequest AddRequest, ...
- // AddRequest ::= [APPLICATION 8] 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',
- // attributes AttributeList }
- 0x30, 0x07, // AttributeList ::= SEQUENCE OF SEQUENCE {
- 0x30, 0x05, // attribute 1
- 0x04, 0x01, 'A', // type AttributeDescription,
- 0x31, 0x00 } );
+ {
+ 0x30, 0x30, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x68, 0x2B, // CHOICE { ..., addRequest AddRequest, ...
+ // AddRequest ::= [APPLICATION 8] 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',
+ // attributes AttributeList }
+ 0x30, 0x07, // AttributeList ::= SEQUENCE OF SEQUENCE {
+ 0x30, 0x05, // attribute 1
+ 0x04, 0x01, 'A', // type AttributeDescription,
+ 0x31, 0x00
+ } );
stream.flip();
@@ -490,18 +580,22 @@
ByteBuffer stream = ByteBuffer.allocate( 0x34 );
stream.put( new byte[]
- { 0x30, 0x32, // LDAPMessage ::= SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- 0x68, 0x2D, // CHOICE { ..., addRequest AddRequest, ...
- // AddRequest ::= [APPLICATION 8] 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',
- // attributes AttributeList }
- 0x30, 0x09, // AttributeList ::= SEQUENCE OF SEQUENCE {
- 0x30, 0x07, // attribute 1
- 0x04, 0x01, 'l', // type AttributeDescription,
- 0x31, 0x02, 0x04, 0x00 } );
+ {
+ 0x30, 0x32, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x68, 0x2D, // CHOICE { ..., addRequest AddRequest, ...
+ // AddRequest ::= [APPLICATION 8] 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',
+ // attributes AttributeList }
+ 0x30, 0x09, // AttributeList ::= SEQUENCE OF SEQUENCE {
+ 0x30, 0x07, // attribute 1
+ 0x04, 0x01, 'l', // type AttributeDescription,
+ 0x31, 0x02,
+ 0x04, 0x00
+ } );
String decodedPdu = StringTools.dumpBytes( stream.array() );
stream.flip();
@@ -575,20 +669,25 @@
ByteBuffer stream = ByteBuffer.allocate( 0x51 );
stream.put( new byte[]
- { 0x30, 0x4F, // LDAPMessage ::= SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- 0x68, 0x2D, // CHOICE { ..., addRequest AddRequest, ...
- // AddRequest ::= [APPLICATION 8] 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',
- // attributes AttributeList }
- 0x30, 0x09, // AttributeList ::= SEQUENCE OF SEQUENCE {
- 0x30, 0x07, // attribute 1
- 0x04, 0x01, 'l', // type AttributeDescription,
- 0x31, 0x02, 0x04, 0x00, ( byte ) 0xA0, 0x1B, // A control
+ {
+ 0x30, 0x4F, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x68, 0x2D, // CHOICE { ..., addRequest AddRequest, ...
+ // AddRequest ::= [APPLICATION 8] 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',
+ // attributes AttributeList }
+ 0x30, 0x09, // AttributeList ::= SEQUENCE OF SEQUENCE {
+ 0x30, 0x07, // attribute 1
+ 0x04, 0x01, 'l', // type AttributeDescription,
+ 0x31, 0x02,
+ 0x04, 0x00,
+ ( 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();
Modified: directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/codec/bind/BindRequestTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/codec/bind/BindRequestTest.java?rev=438859&r1=438858&r2=438859&view=diff
==============================================================================
--- directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/codec/bind/BindRequestTest.java (original)
+++ directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/codec/bind/BindRequestTest.java Thu Aug 31 03:33:43 2006
@@ -33,9 +33,13 @@
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.bind.BindRequest;
import org.apache.directory.shared.ldap.codec.bind.SaslCredentials;
import org.apache.directory.shared.ldap.codec.bind.SimpleAuthentication;
+import org.apache.directory.shared.ldap.message.BindResponseImpl;
+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;
@@ -56,21 +60,25 @@
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,
+ {
+ 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 } );
+ '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();
@@ -144,18 +152,20 @@
ByteBuffer stream = ByteBuffer.allocate( 0x35 );
stream.put( new byte[]
- { 0x30, 0x33, // 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,
+ {
+ 0x30, 0x33, // 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' } );
+ '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'
+ } );
String decodedPdu = StringTools.dumpBytes( stream.array() );
stream.flip();
@@ -209,6 +219,58 @@
}
}
+ /**
+ * Test the decoding of a BindRequest with Simple authentication and
+ * controls
+ */
+ public void testDecodeBindRequestBadDN()
+ {
+ Asn1Decoder ldapDecoder = new LdapDecoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x35 );
+ stream.put( new byte[]
+ {
+ 0x30, 0x33, // 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'
+ } );
+
+ stream.flip();
+
+ // Allocate a LdapMessage Container
+ IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+ // Decode the BindRequest PDU
+ try
+ {
+ ldapDecoder.decode( stream, ldapMessageContainer );
+ }
+ catch ( DecoderException de )
+ {
+ assertTrue( de instanceof ResponseCarryingException );
+ Message response = ((ResponseCarryingException)de).getResponse();
+ assertTrue( response instanceof BindResponseImpl );
+ assertEquals( ResultCodeEnum.INVALIDDNSYNTAX, ((BindResponseImpl)response).getLdapResult().getResultCode() );
+ return;
+ }
+ catch ( NamingException ne )
+ {
+ ne.printStackTrace();
+ fail( ne.getMessage() );
+ }
+
+ fail( "We should not reach this point" );
+ }
+
/**
* Test the decoding of a BindRequest with Simple authentication, no name
@@ -220,15 +282,17 @@
ByteBuffer stream = ByteBuffer.allocate( 0x15 );
stream.put( new byte[]
- { 0x30, 0x13, // LDAPMessage ::=SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- 0x60, 0x0D, // CHOICE { ..., bindRequest BindRequest, ...
- // BindRequest ::= APPLICATION[0] SEQUENCE {
- 0x02, 0x01, 0x03, // version INTEGER (1..127),
- ( byte ) 0x80, 0x08, // authentication AuthenticationChoice
- // AuthenticationChoice ::= CHOICE { simple [0] OCTET STRING,
- // ...
- 'p', 'a', 's', 's', 'w', 'o', 'r', 'd' } );
+ {
+ 0x30, 0x13, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x60, 0x0D, // CHOICE { ..., bindRequest BindRequest, ...
+ // BindRequest ::= APPLICATION[0] SEQUENCE {
+ 0x02, 0x01, 0x03, // version INTEGER (1..127),
+ ( byte ) 0x80, 0x08, // authentication AuthenticationChoice
+ // AuthenticationChoice ::= CHOICE { simple [0] OCTET STRING,
+ // ...
+ 'p', 'a', 's', 's', 'w', 'o', 'r', 'd'
+ } );
stream.flip();
@@ -266,16 +330,18 @@
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' } );
+ {
+ 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 = StringTools.dumpBytes( stream.array() );
@@ -341,21 +407,24 @@
ByteBuffer stream = ByteBuffer.allocate( 0x3A );
stream.put( new byte[]
- { 0x30, 0x38, // LDAPMessage ::=SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- 0x60, 0x33, // 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 ) 0xA3, 0x0D, // authentication
- // AuthenticationChoice
- // AuthenticationChoice ::= CHOICE { ... sasl [3]
- // SaslCredentials }
- // SaslCredentials ::= SEQUENCE {
- // mechanism LDAPSTRING,
- // ...
- 0x04, 0x0B, 'K', 'E', 'R', 'B', 'E', 'R', 'O', 'S', '_', 'V', '4' } );
+ {
+ 0x30, 0x38, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x60, 0x33, // 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 ) 0xA3, 0x0D, // authentication AuthenticationChoice
+ // AuthenticationChoice ::= CHOICE { ... sasl [3]
+ // SaslCredentials }
+ // SaslCredentials ::= SEQUENCE {
+ // mechanism LDAPSTRING,
+ // ...
+ 0x04, 0x0B,
+ 'K', 'E', 'R', 'B', 'E', 'R', 'O', 'S', '_', 'V', '4'
+ } );
String decodedPdu = StringTools.dumpBytes( stream.array() );
stream.flip();
@@ -419,29 +488,31 @@
ByteBuffer stream = ByteBuffer.allocate( 0x42 );
stream.put( new byte[]
- { 0x30, 0x40, // LDAPMessage ::=SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- 0x60, 0x3B, // CHOICE { ..., bindRequest BindRequest, ...
- // BindRequest ::= APPLICATION[0] SEQUENCE {
- 0x02, 0x01, 0x03, // version INTEGER (1..127),
- 0x04, 0x1F, // name LDAPDN,
+ {
+ 0x30, 0x40, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x60, 0x3B, // 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 ) 0xA3, 0x15, // authentication
- // AuthenticationChoice
- // }
- // AuthenticationChoice ::= CHOICE { ... sasl [3]
- // SaslCredentials }
- // SaslCredentials ::= SEQUENCE {
- // mechanism LDAPSTRING,
- // ...
- 0x04, 0x0B, 'K', 'E', 'R', 'B', 'E', 'R', 'O', 'S', '_', 'V', '4', ( byte ) 0x04, 0x06, // SaslCredentials
- // ::=
- // SEQUENCE
- // {
- // ...
- // credentials OCTET STRING OPTIONAL }
- //
- 'a', 'b', 'c', 'd', 'e', 'f' } );
+ 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm',
+ ( byte ) 0xA3, 0x15, // authentication AuthenticationChoice
+ // }
+ // AuthenticationChoice ::= CHOICE { ... sasl [3]
+ // SaslCredentials }
+ // SaslCredentials ::= SEQUENCE {
+ // mechanism LDAPSTRING,
+ // ...
+ 0x04, 0x0B,
+ 'K', 'E', 'R', 'B', 'E', 'R', 'O', 'S', '_', 'V', '4',
+ ( byte ) 0x04, 0x06, // SaslCredentials ::= SEQUENCE {
+ // ...
+ // credentials OCTET STRING OPTIONAL }
+ //
+ 'a', 'b', 'c', 'd', 'e', 'f'
+ } );
+
String decodedPdu = StringTools.dumpBytes( stream.array() );
stream.flip();
@@ -506,9 +577,10 @@
ByteBuffer stream = ByteBuffer.allocate( 0x07 );
stream.put( new byte[]
- { 0x30, 0x05, // LDAPMessage ::=SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- 0x60, 0x00 // CHOICE { ..., bindRequest BindRequest, ...
+ {
+ 0x30, 0x05, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x60, 0x00 // CHOICE { ..., bindRequest BindRequest, ...
} );
stream.flip();
@@ -545,10 +617,11 @@
ByteBuffer stream = ByteBuffer.allocate( 0x09 );
stream.put( new byte[]
- { 0x30, 0x07, // LDAPMessage ::=SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- 0x60, 0x02, // CHOICE { ..., bindRequest BindRequest, ...
- 0x02, 0x00 // version INTEGER (1..127),
+ {
+ 0x30, 0x07, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x60, 0x02, // CHOICE { ..., bindRequest BindRequest, ...
+ 0x02, 0x00 // version INTEGER (1..127),
} );
stream.flip();
@@ -585,10 +658,11 @@
ByteBuffer stream = ByteBuffer.allocate( 0x0A );
stream.put( new byte[]
- { 0x30, 0x08, // LDAPMessage ::=SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- 0x60, 0x03, // CHOICE { ..., bindRequest BindRequest, ...
- 0x02, 0x01, 0x00 // version INTEGER (1..127),
+ {
+ 0x30, 0x08, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x60, 0x03, // CHOICE { ..., bindRequest BindRequest, ...
+ 0x02, 0x01, 0x00 // version INTEGER (1..127),
} );
stream.flip();
@@ -625,10 +699,11 @@
ByteBuffer stream = ByteBuffer.allocate( 0x0A );
stream.put( new byte[]
- { 0x30, 0x08, // LDAPMessage ::=SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- 0x60, 0x03, // CHOICE { ..., bindRequest BindRequest, ...
- 0x02, 0x01, 0x04 // version INTEGER (1..127),
+ {
+ 0x30, 0x08, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x60, 0x03, // CHOICE { ..., bindRequest BindRequest, ...
+ 0x02, 0x01, 0x04 // version INTEGER (1..127),
} );
stream.flip();
@@ -665,10 +740,12 @@
ByteBuffer stream = ByteBuffer.allocate( 0x0C );
stream.put( new byte[]
- { 0x30, 0x0A, // LDAPMessage ::=SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- 0x60, 0x04, // CHOICE { ..., bindRequest BindRequest, ...
- 0x02, 0x02, 0x00, ( byte ) 0x80 // version INTEGER (1..127),
+ {
+ 0x30, 0x0A, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x60, 0x04, // CHOICE { ..., bindRequest BindRequest, ...
+ 0x02, 0x02, 0x00,
+ ( byte ) 0x80 // version INTEGER (1..127),
} );
stream.flip();
@@ -705,10 +782,11 @@
ByteBuffer stream = ByteBuffer.allocate( 0x0A );
stream.put( new byte[]
- { 0x30, 0x08, // LDAPMessage ::=SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- 0x60, 0x03, // CHOICE { ..., bindRequest BindRequest, ...
- 0x02, 0x01, 0x03 // version INTEGER (1..127),
+ {
+ 0x30, 0x08, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x60, 0x03, // CHOICE { ..., bindRequest BindRequest, ...
+ 0x02, 0x01, 0x03 // version INTEGER (1..127),
} );
stream.flip();
@@ -745,10 +823,11 @@
ByteBuffer stream = ByteBuffer.allocate( 0x0C );
stream.put( new byte[]
- { 0x30, 0x0A, // LDAPMessage ::=SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- 0x60, 0x05, // CHOICE { ..., bindRequest BindRequest, ...
- 0x02, 0x01, 0x03, // version INTEGER (1..127),
+ {
+ 0x30, 0x0A, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x60, 0x05, // CHOICE { ..., bindRequest BindRequest, ...
+ 0x02, 0x01, 0x03, // version INTEGER (1..127),
0x04, 0x00 } );
stream.flip();
@@ -785,10 +864,11 @@
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),
+ {
+ 0x30, 0x0C, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x60, 0x07, // CHOICE { ..., bindRequest BindRequest, ...
+ 0x02, 0x01, 0x03, // version INTEGER (1..127),
0x04, 0x00, ( byte ) 0x80, 0x00 } );
String decodedPdu = StringTools.dumpBytes( stream.array() );
@@ -852,11 +932,14 @@
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 } );
+ {
+ 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();
@@ -870,7 +953,10 @@
}
catch ( DecoderException de )
{
- assertTrue( true );
+ assertTrue( de instanceof ResponseCarryingException );
+ Message response = ((ResponseCarryingException)de).getResponse();
+ assertTrue( response instanceof BindResponseImpl );
+ assertEquals( ResultCodeEnum.INVALIDCREDENTIALS, ((BindResponseImpl)response).getLdapResult().getResultCode() );
return;
}
catch ( NamingException ne )
@@ -892,11 +978,15 @@
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 } );
+ {
+ 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();
@@ -951,6 +1041,54 @@
/**
+ * Test the decoding of a BindRequest with an bad mechanism
+ */
+ /* This test is not valid. I don't know how to generate a UnsupportedEncodingException ...
+ public void testDecodeBindRequestBadMechanism()
+ {
+ Asn1Decoder ldapDecoder = new LdapDecoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x11 );
+ stream.put( new byte[]
+ {
+ 0x30, 0x0F, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x60, 0x0A, // CHOICE { ..., bindRequest BindRequest, ...
+ 0x02, 0x01, 0x03, // version INTEGER (1..127),
+ 0x04, 0x00,
+ ( byte ) 0xA3, 0x03,
+ 0x04, 0x01, (byte)0xFF
+ } );
+
+ stream.flip();
+
+ // Allocate a LdapMessage Container
+ IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+ // Decode the BindRequest PDU
+ try
+ {
+ ldapDecoder.decode( stream, ldapMessageContainer );
+ }
+ catch ( DecoderException de )
+ {
+ assertTrue( de instanceof ResponseCarryingException );
+ Message response = ((ResponseCarryingException)de).getResponse();
+ assertTrue( response instanceof BindResponseImpl );
+ assertEquals( ResultCodeEnum.INAPPROPRIATEAUTHENTICATION, ((BindResponseImpl)response).getLdapResult().getResultCode() );
+ return;
+ }
+ catch ( NamingException ne )
+ {
+ ne.printStackTrace();
+ fail( ne.getMessage() );
+ }
+
+ fail( "We should not reach this point" );
+ }
+ */
+
+ /**
* Test the decoding of a BindRequest with an empty credentials
*/
public void testDecodeBindRequestEmptyCredentials()
@@ -959,11 +1097,15 @@
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, } );
+ {
+ 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();
@@ -1028,14 +1170,19 @@
ByteBuffer stream = ByteBuffer.allocate( 0x2F );
stream.put( new byte[]
- { 0x30, 0x2D, // 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, ( byte ) 0xA0, 0x1B, // A
- // control
+ {
+ 0x30, 0x2D, // 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,
+ ( 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();
@@ -1108,14 +1255,18 @@
ByteBuffer stream = ByteBuffer.allocate( 0x2D );
stream.put( new byte[]
- { 0x30, 0x2B, // 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, ( byte ) 0xA0, 0x1B, // A
- // control
+ {
+ 0x30, 0x2B, // 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,
+ ( 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();
Modified: directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/codec/compare/CompareRequestTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/codec/compare/CompareRequestTest.java?rev=438859&r1=438858&r2=438859&view=diff
==============================================================================
--- directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/codec/compare/CompareRequestTest.java (original)
+++ directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/codec/compare/CompareRequestTest.java Thu Aug 31 03:33:43 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();
Modified: directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/codec/del/DelRequestTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/codec/del/DelRequestTest.java?rev=438859&r1=438858&r2=438859&view=diff
==============================================================================
--- directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/codec/del/DelRequestTest.java (original)
+++ directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/codec/del/DelRequestTest.java Thu Aug 31 03:33:43 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.del.DelRequest;
+import org.apache.directory.shared.ldap.message.DeleteResponseImpl;
+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,13 +61,14 @@
stream.put( new byte[]
{
-
- 0x30, 0x25, // LDAPMessage ::= SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- // CHOICE { ..., delRequest DelRequest, ...
- // DelRequest ::= [APPLICATION 10] LDAPDN;
- 0x4A, 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' } );
+ 0x30, 0x25, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ // CHOICE { ..., delRequest DelRequest, ...
+ // DelRequest ::= [APPLICATION 10] LDAPDN;
+ 0x4A, 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'
+ } );
String decodedPdu = StringTools.dumpBytes( stream.array() );
stream.flip();
@@ -108,6 +113,47 @@
}
}
+ /**
+ * Test the decoding of a full DelRequest
+ */
+ public void testDecodeDelRequestBadDN() throws NamingException
+ {
+ Asn1Decoder ldapDecoder = new LdapDecoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x27 );
+
+ stream.put( new byte[]
+ {
+ 0x30, 0x25, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ // CHOICE { ..., delRequest DelRequest, ...
+ // DelRequest ::= [APPLICATION 10] LDAPDN;
+ 0x4A, 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'
+ } );
+
+ stream.flip();
+
+ // Allocate a LdapMessage Container
+ IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+ // Decode a DelRequest PDU
+ try
+ {
+ ldapDecoder.decode( stream, ldapMessageContainer );
+ }
+ catch ( DecoderException de )
+ {
+ assertTrue( de instanceof ResponseCarryingException );
+ Message response = ((ResponseCarryingException)de).getResponse();
+ assertTrue( response instanceof DeleteResponseImpl );
+ assertEquals( ResultCodeEnum.INVALIDDNSYNTAX, ((DeleteResponseImpl)response).getLdapResult().getResultCode() );
+ return;
+ }
+
+ fail( "We should not reach this point" );
+ }
/**
* Test the decoding of an empty DelRequest
@@ -120,12 +166,11 @@
stream.put( new byte[]
{
-
- 0x30, 0x05, // LDAPMessage ::= SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- // CHOICE { ..., delRequest DelRequest, ...
- // DelRequest ::= [APPLICATION 10] LDAPDN;
- 0x4A, 0x00 // Empty DN
+ 0x30, 0x05, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ // CHOICE { ..., delRequest DelRequest, ...
+ // DelRequest ::= [APPLICATION 10] LDAPDN;
+ 0x4A, 0x00 // Empty DN
} );
stream.flip();
@@ -157,16 +202,17 @@
stream.put( new byte[]
{
-
- 0x30, 0x42, // LDAPMessage ::= SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- // CHOICE { ..., delRequest DelRequest, ...
- // DelRequest ::= [APPLICATION 10] LDAPDN;
- 0x4A, 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', ( byte ) 0xA0, 0x1B, // A
- // control
+ 0x30, 0x42, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ // CHOICE { ..., delRequest DelRequest, ...
+ // DelRequest ::= [APPLICATION 10] LDAPDN;
+ 0x4A, 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',
+ ( 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();
Modified: directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/codec/extended/ExtendedRequestTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/codec/extended/ExtendedRequestTest.java?rev=438859&r1=438858&r2=438859&view=diff
==============================================================================
--- directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/codec/extended/ExtendedRequestTest.java (original)
+++ directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/codec/extended/ExtendedRequestTest.java Thu Aug 31 03:33:43 2006
@@ -56,14 +56,16 @@
ByteBuffer stream = ByteBuffer.allocate( 0x1D );
stream.put( new byte[]
- { 0x30, 0x1B, // LDAPMessage ::= SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- // CHOICE { ..., extendedReq ExtendedRequest, ...
- 0x77, 0x16, // ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
- // requestName [0] LDAPOID,
- ( byte ) 0x80, 0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '2',
- // requestValue [1] OCTET STRING OPTIONAL }
- ( byte ) 0x81, 0x05, 'v', 'a', 'l', 'u', 'e' } );
+ {
+ 0x30, 0x1B, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ // CHOICE { ..., extendedReq ExtendedRequest, ...
+ 0x77, 0x16, // ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
+ // requestName [0] LDAPOID,
+ ( byte ) 0x80, 0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '2',
+ // requestValue [1] OCTET STRING OPTIONAL }
+ ( byte ) 0x81, 0x05, 'v', 'a', 'l', 'u', 'e'
+ } );
String decodedPdu = StringTools.dumpBytes( stream.array() );
stream.flip();
@@ -120,17 +122,21 @@
ByteBuffer stream = ByteBuffer.allocate( 0x3A );
stream.put( new byte[]
- { 0x30, 0x38, // LDAPMessage ::= SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- // CHOICE { ..., extendedReq ExtendedRequest, ...
- 0x77, 0x16, // ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
- // requestName [0] LDAPOID,
+ {
+ 0x30, 0x38, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ // CHOICE { ..., extendedReq ExtendedRequest, ...
+ 0x77, 0x16, // ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
+ // requestName [0] LDAPOID,
( byte ) 0x80, 0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '2',
- // requestValue [1] OCTET STRING OPTIONAL }
- ( byte ) 0x81, 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 } );
+ // requestValue [1] OCTET STRING OPTIONAL }
+ ( byte ) 0x81, 0x05, 'v', 'a', 'l', 'u', 'e',
+ ( byte ) 0xA0, 0x1B, // A control
+ 0x30, 0x19,
+ 0x04, 0x17,
+ '2', '.', '1', '6', '.', '8', '4', '0', '.', '1', '.', '1', '1', '3', '7', '3',
+ '0', '.', '3', '.', '4', '.', '2'
+ } );
String decodedPdu = StringTools.dumpBytes( stream.array() );
stream.flip();
@@ -197,16 +203,21 @@
ByteBuffer stream = ByteBuffer.allocate( 0x33 );
stream.put( new byte[]
- { 0x30, 0x31, // LDAPMessage ::= SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- // CHOICE { ..., extendedReq ExtendedRequest, ...
- 0x77, 0x0F, // ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
- // requestName [0] LDAPOID,
- ( byte ) 0x80, 0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '2',
- // requestValue [1] OCTET STRING OPTIONAL }
- ( 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 } );
+ {
+ 0x30, 0x31, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ // CHOICE { ..., extendedReq ExtendedRequest, ...
+ 0x77, 0x0F, // ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
+ // requestName [0] LDAPOID,
+ ( byte ) 0x80, 0x0D,
+ '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '2',
+ // requestValue [1] OCTET STRING OPTIONAL }
+ ( byte ) 0xA0, 0x1B, // A control
+ 0x30, 0x19,
+ 0x04, 0x17,
+ '2', '.', '1', '6', '.', '8', '4', '0', '.', '1', '.', '1', '1', '3', '7', '3',
+ '0', '.', '3', '.', '4', '.', '2'
+ } );
String decodedPdu = StringTools.dumpBytes( stream.array() );
stream.flip();
@@ -272,10 +283,11 @@
ByteBuffer stream = ByteBuffer.allocate( 0x07 );
stream.put( new byte[]
- { 0x30, 0x05, // LDAPMessage ::= SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- // CHOICE { ..., extendedReq ExtendedRequest, ...
- 0x77, 0x00, // ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
+ {
+ 0x30, 0x05, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ // CHOICE { ..., extendedReq ExtendedRequest, ...
+ 0x77, 0x00, // ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
} );
stream.flip();
@@ -306,11 +318,13 @@
ByteBuffer stream = ByteBuffer.allocate( 0x09 );
stream.put( new byte[]
- { 0x30, 0x07, // LDAPMessage ::= SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- // CHOICE { ..., extendedReq ExtendedRequest, ...
- 0x77, 0x02, // ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
- ( byte ) 0x80, 0x00 } );
+ {
+ 0x30, 0x07, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ // CHOICE { ..., extendedReq ExtendedRequest, ...
+ 0x77, 0x02, // ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
+ ( byte ) 0x80, 0x00
+ } );
stream.flip();
@@ -329,6 +343,42 @@
}
}
+ /**
+ * Test the decoding of a bad name
+ */
+ public void testDecodeExtendedBadRequestName() throws NamingException
+ {
+ Asn1Decoder ldapDecoder = new LdapDecoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x16 );
+
+ stream.put( new byte[]
+ {
+ 0x30, 0x14, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ // CHOICE { ..., extendedReq ExtendedRequest, ...
+ 0x77, 0x0F, // ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
+ // requestName [0] LDAPOID,
+ ( byte ) 0x80, 0x0D,
+ '1', '-', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '2',
+ } );
+
+ stream.flip();
+
+ // Allocate a LdapMessage Container
+ IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+ // Decode a ExtendedRequest PDU
+ try
+ {
+ ldapDecoder.decode( stream, ldapMessageContainer );
+ fail( "We should never reach this point !!!" );
+ }
+ catch ( DecoderException de )
+ {
+ assertTrue( true );
+ }
+ }
/**
* Test the decoding of a name only ExtendedRequest
@@ -340,12 +390,15 @@
ByteBuffer stream = ByteBuffer.allocate( 0x16 );
stream.put( new byte[]
- { 0x30, 0x14, // LDAPMessage ::= SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- // CHOICE { ..., extendedReq ExtendedRequest, ...
- 0x77, 0x0F, // ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
- // requestName [0] LDAPOID,
- ( byte ) 0x80, 0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '2', } );
+ {
+ 0x30, 0x14, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ // CHOICE { ..., extendedReq ExtendedRequest, ...
+ 0x77, 0x0F, // ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
+ // requestName [0] LDAPOID,
+ ( byte ) 0x80, 0x0D,
+ '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '2',
+ } );
String decodedPdu = StringTools.dumpBytes( stream.array() );
stream.flip();
@@ -401,13 +454,16 @@
ByteBuffer stream = ByteBuffer.allocate( 0x18 );
stream.put( new byte[]
- { 0x30, 0x16, // LDAPMessage ::= SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- // CHOICE { ..., extendedReq ExtendedRequest, ...
- 0x77, 0x11, // ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
- // requestName [0] LDAPOID,
- ( byte ) 0x80, 0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '2', ( byte ) 0x81,
- 0x00 } );
+ {
+ 0x30, 0x16, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ // CHOICE { ..., extendedReq ExtendedRequest, ...
+ 0x77, 0x11, // ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
+ // requestName [0] LDAPOID,
+ ( byte ) 0x80, 0x0D,
+ '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '2',
+ ( byte ) 0x81, 0x00
+ } );
String decodedPdu = StringTools.dumpBytes( stream.array() );
stream.flip();