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/27 09:33:54 UTC
svn commit: r372781 - in /directory/trunks/common/ldap/src:
main/java/org/apache/ldap/common/codec/add/
main/java/org/apache/ldap/common/codec/del/
test/java/org/apache/ldap/common/codec/abandon/
test/java/org/apache/ldap/common/codec/bind/ test/java/o...
Author: elecharny
Date: Fri Jan 27 00:33:40 2006
New Revision: 372781
URL: http://svn.apache.org/viewcvs?rev=372781&view=rev
Log:
- Fixed pop transition pbs
- Fixed doco
- Added tests
Modified:
directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/add/AddResponseGrammar.java
directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/del/DelResponseGrammar.java
directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/abandon/AbandonRequestTest.java
directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/bind/BindRequestTest.java
directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/bind/BindResponseTest.java
directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/del/DelRequestTest.java
directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/del/DelResponseTest.java
Modified: directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/add/AddResponseGrammar.java
URL: http://svn.apache.org/viewcvs/directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/add/AddResponseGrammar.java?rev=372781&r1=372780&r2=372781&view=diff
==============================================================================
--- directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/add/AddResponseGrammar.java (original)
+++ directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/add/AddResponseGrammar.java Fri Jan 27 00:33:40 2006
@@ -117,7 +117,7 @@
// Ok, we have a LDAPResult Tag (0x0A). So we have to switch the grammar.
super.transitions[LdapStatesEnum.ADD_RESPONSE_LDAP_RESULT][UniversalTag.ENUMERATED_TAG] = new GrammarTransition(
LdapStatesEnum.ADD_RESPONSE_LDAP_RESULT, LdapStatesEnum.LDAP_RESULT_GRAMMAR_SWITCH,
- new GrammarAction( "Store Ldap Result referral" )
+ new GrammarAction( "Pop allowed" )
{
public void action( IAsn1Container container ) throws DecoderException
{
Modified: directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/del/DelResponseGrammar.java
URL: http://svn.apache.org/viewcvs/directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/del/DelResponseGrammar.java?rev=372781&r1=372780&r2=372781&view=diff
==============================================================================
--- directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/del/DelResponseGrammar.java (original)
+++ directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/del/DelResponseGrammar.java Fri Jan 27 00:33:40 2006
@@ -22,6 +22,7 @@
import org.apache.asn1.ber.grammar.GrammarAction;
import org.apache.asn1.ber.IAsn1Container;
import org.apache.asn1.ber.tlv.UniversalTag;
+import org.apache.asn1.codec.DecoderException;
import org.apache.ldap.common.codec.LdapConstants;
import org.apache.ldap.common.codec.LdapMessage;
import org.apache.ldap.common.codec.LdapMessageContainer;
@@ -97,7 +98,15 @@
// DelResponse ::= [APPLICATION 11] LDAPResult (Value)
// Ok, we have a LDAPResult Tag (0x0A). So we have to switch the grammar.
super.transitions[LdapStatesEnum.DEL_RESPONSE_LDAP_RESULT][UniversalTag.ENUMERATED_TAG] = new GrammarTransition(
- LdapStatesEnum.DEL_RESPONSE_LDAP_RESULT, LdapStatesEnum.LDAP_RESULT_GRAMMAR_SWITCH, null );
+ LdapStatesEnum.DEL_RESPONSE_LDAP_RESULT, LdapStatesEnum.LDAP_RESULT_GRAMMAR_SWITCH,
+ new GrammarAction( "Pop allowed" )
+ {
+ public void action( IAsn1Container container ) throws DecoderException
+ {
+ container.grammarPopAllowed( true );
+ }
+
+ });
}
//~ Methods ------------------------------------------------------------------------------------
Modified: directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/abandon/AbandonRequestTest.java
URL: http://svn.apache.org/viewcvs/directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/abandon/AbandonRequestTest.java?rev=372781&r1=372780&r2=372781&view=diff
==============================================================================
--- directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/abandon/AbandonRequestTest.java (original)
+++ directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/abandon/AbandonRequestTest.java Fri Jan 27 00:33:40 2006
@@ -17,11 +17,13 @@
package org.apache.ldap.common.codec.abandon;
import java.nio.ByteBuffer;
+import java.util.List;
import org.apache.asn1.codec.DecoderException;
import org.apache.asn1.codec.EncoderException;
import org.apache.asn1.ber.Asn1Decoder;
import org.apache.asn1.ber.IAsn1Container;
+import org.apache.ldap.common.codec.Control;
import org.apache.ldap.common.codec.LdapDecoder;
import org.apache.ldap.common.codec.LdapMessage;
import org.apache.ldap.common.codec.LdapMessageContainer;
@@ -43,14 +45,20 @@
{
Asn1Decoder ldapDecoder = new LdapDecoder();
- ByteBuffer stream = ByteBuffer.allocate( 0x08 );
+ ByteBuffer stream = ByteBuffer.allocate( 0x25 );
stream.put(
new byte[]
{
- 0x30, 0x06, // LDAPMessage ::=SEQUENCE {
- 0x02, 0x01, 0x03, // messageID MessageID
- 0x50, 0x01, 0x02 // CHOICE { ..., abandonRequest AbandonRequest,...
- // AbandonRequest ::= [APPLICATION 16] MessageID
+ 0x30, 0x23, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x03, // messageID MessageID
+ 0x50, 0x01, 0x02, // CHOICE { ..., abandonRequest AbandonRequest,...
+ // AbandonRequest ::= [APPLICATION 16] MessageID
+ (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() );
@@ -78,8 +86,17 @@
assertEquals( 2, abandonRequest.getAbandonedMessageId() );
// Check the length
- assertEquals(8, message.computeLength());
+ assertEquals( 0x25, message.computeLength());
+ // Check the Control
+ List controls = message.getControls();
+
+ assertEquals( 1, controls.size() );
+
+ Control control = message.getControls( 0 );
+ assertEquals( "2.16.840.1.113730.3.4.2", control.getControlType() );
+ assertEquals( "", StringTools.dumpBytes( (byte[])control.getControlValue() ) );
+
// Check the encoding
try
{
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=372781&r1=372780&r2=372781&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 Fri Jan 27 00:33:40 2006
@@ -17,11 +17,13 @@
package org.apache.ldap.common.codec.bind;
import java.nio.ByteBuffer;
+import java.util.List;
import org.apache.asn1.codec.DecoderException;
import org.apache.asn1.codec.EncoderException;
import org.apache.asn1.ber.Asn1Decoder;
import org.apache.asn1.ber.IAsn1Container;
+import org.apache.ldap.common.codec.Control;
import org.apache.ldap.common.codec.LdapDecoder;
import org.apache.ldap.common.codec.LdapMessage;
import org.apache.ldap.common.codec.LdapMessageContainer;
@@ -815,14 +817,14 @@
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),
+ 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
+ 0x04, 0x00,
} );
String decodedPdu = StringTools.dumpBytes( stream.array() );
@@ -856,6 +858,89 @@
// 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() );
+ }
+ }
+
+ /**
+ * Test the decoding of a BindRequest with an empty credentials
+ */
+ public void testDecodeBindRequestEmptyCredentialsWithControls()
+ {
+ Asn1Decoder ldapDecoder = new LdapDecoder();
+
+ 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, 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();
+
+ // 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( 0x2F, message.computeLength() );
+
+ // Check the Control
+ List controls = message.getControls();
+
+ assertEquals( 1, controls.size() );
+
+ Control control = message.getControls( 0 );
+ assertEquals( "2.16.840.1.113730.3.4.2", control.getControlType() );
+ assertEquals( "", StringTools.dumpBytes( (byte[])control.getControlValue() ) );
+
// Check the encoding
try
{
Modified: directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/bind/BindResponseTest.java
URL: http://svn.apache.org/viewcvs/directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/bind/BindResponseTest.java?rev=372781&r1=372780&r2=372781&view=diff
==============================================================================
--- directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/bind/BindResponseTest.java (original)
+++ directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/bind/BindResponseTest.java Fri Jan 27 00:33:40 2006
@@ -17,11 +17,13 @@
package org.apache.ldap.common.codec.bind;
import java.nio.ByteBuffer;
+import java.util.List;
import org.apache.asn1.codec.DecoderException;
import org.apache.asn1.codec.EncoderException;
import org.apache.asn1.ber.Asn1Decoder;
import org.apache.asn1.ber.IAsn1Container;
+import org.apache.ldap.common.codec.Control;
import org.apache.ldap.common.codec.LdapDecoder;
import org.apache.ldap.common.codec.LdapMessage;
import org.apache.ldap.common.codec.LdapMessageContainer;
@@ -170,6 +172,15 @@
// Check the length
assertEquals(0x3C, message.computeLength());
+
+ // Check the Control
+ List controls = message.getControls();
+
+ assertEquals( 1, controls.size() );
+
+ Control control = message.getControls( 0 );
+ assertEquals( "1.2.840.113556.1.4.319", control.getControlType() );
+ assertEquals( "0x30 0x0B 0x0A 0x01 0x08 0x04 0x03 0x61 0x3D 0x62 0x02 0x01 0x10 ", StringTools.dumpBytes( (byte[])control.getControlValue() ) );
// Check the encoding
try
Modified: directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/del/DelRequestTest.java
URL: http://svn.apache.org/viewcvs/directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/del/DelRequestTest.java?rev=372781&r1=372780&r2=372781&view=diff
==============================================================================
--- directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/del/DelRequestTest.java (original)
+++ directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/del/DelRequestTest.java Fri Jan 27 00:33:40 2006
@@ -17,6 +17,7 @@
package org.apache.ldap.common.codec.del;
import java.nio.ByteBuffer;
+import java.util.List;
import javax.naming.NamingException;
@@ -24,6 +25,7 @@
import org.apache.asn1.codec.EncoderException;
import org.apache.asn1.ber.Asn1Decoder;
import org.apache.asn1.ber.IAsn1Container;
+import org.apache.ldap.common.codec.Control;
import org.apache.ldap.common.codec.LdapDecoder;
import org.apache.ldap.common.codec.LdapMessage;
import org.apache.ldap.common.codec.LdapMessageContainer;
@@ -139,4 +141,87 @@
assertTrue( true );
}
}
+
+ /**
+ * Test the decoding of a full DelRequest with controls
+ */
+ public void testDecodeDelRequestSuccessWithControls() throws NamingException
+ {
+ Asn1Decoder ldapDecoder = new LdapDecoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x44 );
+
+ 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, 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();
+
+ // Allocate a LdapMessage Container
+ IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+ // Decode a DelRequest PDU
+ try
+ {
+ ldapDecoder.decode( stream, ldapMessageContainer );
+ }
+ catch ( DecoderException de )
+ {
+ de.printStackTrace();
+ fail( de.getMessage() );
+ }
+
+ // Check the decoded DelRequest PDU
+ LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+ DelRequest delRequest = message.getDelRequest();
+
+ assertEquals( 1, message.getMessageId() );
+ assertEquals( "cn=testModify,ou=users,ou=system", delRequest.getEntry() );
+
+ // Check the length
+ assertEquals(0x44, message.computeLength());
+
+ // Check the Control
+ List controls = message.getControls();
+
+ assertEquals( 1, controls.size() );
+
+ Control control = message.getControls( 0 );
+ assertEquals( "2.16.840.1.113730.3.4.2", control.getControlType() );
+ assertEquals( "", StringTools.dumpBytes( (byte[])control.getControlValue() ) );
+
+ // 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() );
+ }
+ }
+
}
Modified: directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/del/DelResponseTest.java
URL: http://svn.apache.org/viewcvs/directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/del/DelResponseTest.java?rev=372781&r1=372780&r2=372781&view=diff
==============================================================================
--- directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/del/DelResponseTest.java (original)
+++ directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/del/DelResponseTest.java Fri Jan 27 00:33:40 2006
@@ -17,11 +17,13 @@
package org.apache.ldap.common.codec.del;
import java.nio.ByteBuffer;
+import java.util.List;
import org.apache.asn1.codec.DecoderException;
import org.apache.asn1.codec.EncoderException;
import org.apache.asn1.ber.Asn1Decoder;
import org.apache.asn1.ber.IAsn1Container;
+import org.apache.ldap.common.codec.Control;
import org.apache.ldap.common.codec.LdapDecoder;
import org.apache.ldap.common.codec.LdapMessage;
import org.apache.ldap.common.codec.LdapMessageContainer;
@@ -145,4 +147,94 @@
fail( "We should not reach this point" );
}
+
+ /**
+ * Test the decoding of a DelResponse with controls
+ */
+ public void testDecodeDelResponseSuccessWithControls()
+ {
+ Asn1Decoder ldapDecoder = new LdapDecoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x4A );
+
+ stream.put(
+ new byte[]
+ {
+ 0x30, 0x48, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x6B, 0x26, // CHOICE { ..., delResponse DelResponse, ...
+ // DelResponse ::= [APPLICATION 11] LDAPResult
+ 0x0A, 0x01, 0x21, // LDAPResult ::= SEQUENCE {
+ // resultCode ENUMERATED {
+ // success (0), ...
+ // },
+ 0x04, 0x1F, // matchedDN 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',
+ 0x04, 0x00, // errorMessage LDAPString,
+ // referral [3] Referral 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
+
+ } );
+
+ String decodedPdu = StringTools.dumpBytes( stream.array() );
+ stream.flip();
+
+ // Allocate a LdapMessage Container
+ IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+ // Decode the DelResponse PDU
+ try
+ {
+ ldapDecoder.decode( stream, ldapMessageContainer );
+ }
+ catch ( DecoderException de )
+ {
+ de.printStackTrace();
+ fail( de.getMessage() );
+ }
+
+ // Check the decoded DelResponse PDU
+ LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+ DelResponse delResponse = message.getDelResponse();
+
+ assertEquals( 1, message.getMessageId() );
+ assertEquals( 33, delResponse.getLdapResult().getResultCode() );
+ assertEquals( "uid=akarasulu,dc=example,dc=com", delResponse.getLdapResult().getMatchedDN() );
+ assertEquals( "", delResponse.getLdapResult().getErrorMessage() );
+
+ // Check the length
+ assertEquals(0x4A, message.computeLength());
+
+ // Check the Control
+ List controls = message.getControls();
+
+ assertEquals( 1, controls.size() );
+
+ Control control = message.getControls( 0 );
+ assertEquals( "2.16.840.1.113730.3.4.2", control.getControlType() );
+ assertEquals( "", StringTools.dumpBytes( (byte[])control.getControlValue() ) );
+
+ // 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() );
+ }
+ }
+
}