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 2018/11/20 08:27:32 UTC
[directory-ldap-api] branch master updated: o Formatted request
tests o Added the CompareRequest factory o Added the encode method body for
some control factories
This is an automated email from the ASF dual-hosted git repository.
elecharny pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/directory-ldap-api.git
The following commit(s) were added to refs/heads/master by this push:
new e4a68e6 o Formatted request tests o Added the CompareRequest factory o Added the encode method body for some control factories
e4a68e6 is described below
commit e4a68e6f3be125b2ccfc5720b830caf0098a852d
Author: Emmanuel Lecharny <el...@apache.org>
AuthorDate: Tue Nov 20 09:27:29 2018 +0100
o Formatted request tests
o Added the CompareRequest factory
o Added the encode method body for some control factories
---
.../directory/api/ldap/codec/api/LdapEncoder.java | 5 +
.../ldap/codec/factory/CompareRequestFactory.java | 80 ++
.../api/ldap/codec/abandon/AbandonRequestTest.java | 108 +-
.../api/ldap/codec/add/AddRequestTest.java | 228 +---
.../api/ldap/codec/bind/BindRequestTest.java | 1323 +++++++-------------
.../api/ldap/codec/compare/CompareRequestTest.java | 485 ++-----
.../extras/controls/ad_impl/AdDirSyncFactory.java | 2 -
.../controls/ad_impl/AdPolicyHintsFactory.java | 11 +-
.../org/apache/directory/api/util/Strings.java | 102 +-
9 files changed, 767 insertions(+), 1577 deletions(-)
diff --git a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/api/LdapEncoder.java b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/api/LdapEncoder.java
index 1f125bd..57f1b66 100644
--- a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/api/LdapEncoder.java
+++ b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/api/LdapEncoder.java
@@ -35,6 +35,7 @@ import org.apache.directory.api.i18n.I18n;
import org.apache.directory.api.ldap.codec.factory.AbandonRequestFactory;
import org.apache.directory.api.ldap.codec.factory.AddRequestFactory;
import org.apache.directory.api.ldap.codec.factory.BindRequestFactory;
+import org.apache.directory.api.ldap.codec.factory.CompareRequestFactory;
import org.apache.directory.api.ldap.model.message.Control;
import org.apache.directory.api.ldap.model.message.Message;
import org.apache.directory.api.ldap.model.message.Referral;
@@ -203,6 +204,10 @@ public final class LdapEncoder
BindRequestFactory.INSTANCE.encodeReverse( buffer, message );
return;
+ case "CompareRequestImpl" :
+ CompareRequestFactory.INSTANCE.encodeReverse( buffer, message );
+ return;
+
default:
// Nothing to do
}
diff --git a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/factory/CompareRequestFactory.java b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/factory/CompareRequestFactory.java
new file mode 100644
index 0000000..c9e7a3b
--- /dev/null
+++ b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/factory/CompareRequestFactory.java
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.api.ldap.codec.factory;
+
+import org.apache.directory.api.asn1.ber.tlv.BerValue;
+import org.apache.directory.api.asn1.util.Asn1Buffer;
+import org.apache.directory.api.ldap.codec.api.LdapCodecConstants;
+import org.apache.directory.api.ldap.model.message.CompareRequest;
+import org.apache.directory.api.ldap.model.message.Message;
+import org.apache.directory.api.util.Strings;
+
+/**
+ * The CompareRequest factory.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public final class CompareRequestFactory implements Messagefactory
+{
+ /** The static instance */
+ public static final CompareRequestFactory INSTANCE = new CompareRequestFactory();
+
+ private CompareRequestFactory()
+ {
+ // Nothing to do
+ }
+
+ /**
+ * Encode the CompareRequest message to a PDU.
+ * <br>
+ * <pre>
+ * CompareRequest :
+ * 0x6E LL
+ * 0x04 LL entry
+ * 0x30 LL attributeValueAssertion
+ * 0x04 LL attributeDesc
+ * 0x04 LL assertionValue
+ * </pre>
+ *
+ * @param buffer The buffer where to put the PDU
+ * @param message the CompareRequest to encode
+ */
+ @Override
+ public void encodeReverse( Asn1Buffer buffer, Message message )
+ {
+ int pos = buffer.getPos();
+ CompareRequest compareMessage = ( CompareRequest ) message;
+
+ // The assertionValue
+ BerValue.encodeOctetString( buffer, compareMessage.getAssertionValue().getBytes() );
+
+ // The attributeDesc
+ BerValue.encodeOctetString( buffer, Strings.getBytesUtf8( compareMessage.getAttributeId() ) );
+
+ // The attributeValueAssertion sequence Tag
+ BerValue.encodeSequence( buffer, pos );
+
+ // The entry DN
+ BerValue.encodeOctetString( buffer, Strings.getBytesUtf8( compareMessage.getName().getName() ) );
+
+ // The CompareRequest Tag
+ BerValue.encodeSequence( buffer, LdapCodecConstants.COMPARE_REQUEST_TAG, pos );
+ }
+}
diff --git a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/abandon/AbandonRequestTest.java b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/abandon/AbandonRequestTest.java
index c73680a..e9847d2 100644
--- a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/abandon/AbandonRequestTest.java
+++ b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/abandon/AbandonRequestTest.java
@@ -64,7 +64,7 @@ public class AbandonRequestTest extends AbstractCodecServiceTest
* Test the decoding of a AbandonRequest with controls
*/
@Test
- public void testDecodeAbandonRequestWithControls()
+ public void testDecodeAbandonRequestWithControls() throws DecoderException, EncoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
@@ -102,15 +102,7 @@ public class AbandonRequestTest extends AbstractCodecServiceTest
new LdapMessageContainer<AbandonRequestDecorator>( codec );
// Decode the PDU
- try
- {
- ldapDecoder.decode( stream, ldapMessageContainer );
- }
- catch ( DecoderException de )
- {
- de.printStackTrace();
- fail( de.getMessage() );
- }
+ ldapDecoder.decode( stream, ldapMessageContainer );
// Check that everything is OK
AbandonRequestDecorator abandonRequest = ldapMessageContainer.getMessage();
@@ -153,33 +145,25 @@ public class AbandonRequestTest extends AbstractCodecServiceTest
internalAbandonRequest.addControl( control );
// Check the encoding
- try
- {
- ByteBuffer bb = LdapEncoder.encodeMessage( codec, new AbandonRequestDecorator( codec, internalAbandonRequest ) );
+ ByteBuffer bb = LdapEncoder.encodeMessage( codec, new AbandonRequestDecorator( codec, internalAbandonRequest ) );
- // Check the length
- assertEquals( 0x64, bb.limit() );
-
- // Don't check the PDU, as control are in a Map, and can be in a different order
- // So we decode the generated PDU, and we compare it with the initial message
- try
- {
- ldapDecoder.decode( bb, ldapMessageContainer );
- }
- catch ( DecoderException de )
- {
- de.printStackTrace();
- fail( de.getMessage() );
- }
+ // Check the length
+ assertEquals( 0x64, bb.limit() );
- AbandonRequest abandonRequest2 = ldapMessageContainer.getMessage();
- assertEquals( abandonRequest, abandonRequest2 );
+ // Don't check the PDU, as control are in a Map, and can be in a different order
+ // So we decode the generated PDU, and we compare it with the initial message
+ try
+ {
+ ldapDecoder.decode( bb, ldapMessageContainer );
}
- catch ( EncoderException ee )
+ catch ( DecoderException de )
{
- ee.printStackTrace();
- fail( ee.getMessage() );
+ de.printStackTrace();
+ fail( de.getMessage() );
}
+
+ AbandonRequest abandonRequest2 = ldapMessageContainer.getMessage();
+ assertEquals( abandonRequest, abandonRequest2 );
}
@@ -187,7 +171,7 @@ public class AbandonRequestTest extends AbstractCodecServiceTest
* Test the decoding of a AbandonRequest with no controls
*/
@Test
- public void testDecodeAbandonRequestNoControlsHighMessageId() throws EncoderException
+ public void testDecodeAbandonRequestNoControlsHighMessageId() throws DecoderException, EncoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
@@ -208,15 +192,7 @@ public class AbandonRequestTest extends AbstractCodecServiceTest
new LdapMessageContainer<AbandonRequestDecorator>( codec );
// Decode the PDU
- try
- {
- ldapDecoder.decode( stream, ldapMessageContainer );
- }
- catch ( DecoderException de )
- {
- de.printStackTrace();
- fail( de.getMessage() );
- }
+ ldapDecoder.decode( stream, ldapMessageContainer );
// Check that everything is OK
AbandonRequest abandonRequest = ldapMessageContainer.getMessage();
@@ -229,20 +205,12 @@ public class AbandonRequestTest extends AbstractCodecServiceTest
internalAbandonRequest.setMessageId( abandonRequest.getMessageId() );
// Check the encoding
- try
- {
- ByteBuffer bb = LdapEncoder.encodeMessage( codec, new AbandonRequestDecorator( codec, internalAbandonRequest ) );
+ ByteBuffer bb = LdapEncoder.encodeMessage( codec, new AbandonRequestDecorator( codec, internalAbandonRequest ) );
- // Check the length
- assertEquals( 0x0A, bb.limit() );
+ // Check the length
+ assertEquals( 0x0A, bb.limit() );
- assertTrue( Arrays.equals( stream.array(), bb.array() ) );
- }
- catch ( EncoderException ee )
- {
- ee.printStackTrace();
- fail( ee.getMessage() );
- }
+ assertTrue( Arrays.equals( stream.array(), bb.array() ) );
// Check the reverse encoding
Asn1Buffer buffer = new Asn1Buffer();
@@ -255,8 +223,8 @@ public class AbandonRequestTest extends AbstractCodecServiceTest
/**
* Test the decoding of a AbandonRequest with a null messageId
*/
- @Test
- public void testDecodeAbandonRequestNoMessageId()
+ @Test( expected=DecoderException.class )
+ public void testDecodeAbandonRequestNoMessageId() throws DecoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
@@ -276,25 +244,15 @@ public class AbandonRequestTest extends AbstractCodecServiceTest
new LdapMessageContainer<AbstractMessageDecorator<? extends Message>>( codec );
// Decode the PDU
- try
- {
- ldapDecoder.decode( stream, ldapMessageContainer );
- }
- catch ( DecoderException de )
- {
- assertTrue( true );
- return;
- }
-
- fail( "We should not reach this point" );
+ ldapDecoder.decode( stream, ldapMessageContainer );
}
/**
* Test the decoding of a AbandonRequest with a bad Message Id
*/
- @Test
- public void testDecodeAbandonRequestBadMessageId()
+ @Test( expected=DecoderException.class )
+ public void testDecodeAbandonRequestBadMessageId() throws DecoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
@@ -314,16 +272,6 @@ public class AbandonRequestTest extends AbstractCodecServiceTest
new LdapMessageContainer<AbstractMessageDecorator<? extends Message>>( codec );
// Decode the PDU
- try
- {
- ldapDecoder.decode( stream, ldapMessageContainer );
- }
- catch ( DecoderException de )
- {
- assertTrue( true );
- return;
- }
-
- fail( "We should not reach this point" );
+ ldapDecoder.decode( stream, ldapMessageContainer );
}
}
diff --git a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/add/AddRequestTest.java b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/add/AddRequestTest.java
index 1a069af..4d82d4c 100644
--- a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/add/AddRequestTest.java
+++ b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/add/AddRequestTest.java
@@ -31,8 +31,6 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
-import javax.naming.NamingException;
-
import org.apache.directory.api.asn1.DecoderException;
import org.apache.directory.api.asn1.EncoderException;
import org.apache.directory.api.asn1.ber.Asn1Container;
@@ -76,7 +74,7 @@ public class AddRequestTest extends AbstractCodecServiceTest
* @throws EncoderException
*/
@Test
- public void testDecodeAddRequestSuccess() throws NamingException, EncoderException
+ public void testDecodeAddRequestSuccess() throws DecoderException, EncoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
@@ -121,15 +119,7 @@ public class AddRequestTest extends AbstractCodecServiceTest
new LdapMessageContainer<AddRequestDecorator>( codec );
// Decode a AddRequest message
- try
- {
- ldapDecoder.decode( stream, container );
- }
- catch ( DecoderException de )
- {
- de.printStackTrace();
- fail( de.getMessage() );
- }
+ ldapDecoder.decode( stream, container );
AddRequest addRequest = container.getMessage();
@@ -185,34 +175,27 @@ public class AddRequestTest extends AbstractCodecServiceTest
}
// Check the encoding
- try
- {
- ByteBuffer bb = LdapEncoder.encodeMessage( codec, addRequest );
+ ByteBuffer bb = LdapEncoder.encodeMessage( codec, addRequest );
- // Check the length
- assertEquals( 0x59, bb.limit() );
-
- // We cannot compare the PDU, as the attributes order is not
- // kept. Let's decode again and compare the resulting AddRequest
- try
- {
- ldapDecoder.decode( bb, container );
- }
- catch ( DecoderException de )
- {
- de.printStackTrace();
- fail( de.getMessage() );
- }
+ // Check the length
+ assertEquals( 0x59, bb.limit() );
- AddRequest addRequest2 = container.getMessage();
- assertEquals( addRequest, addRequest2 );
+ // We cannot compare the PDU, as the attributes order is not
+ // kept. Let's decode again and compare the resulting AddRequest
+ try
+ {
+ ldapDecoder.decode( bb, container );
}
- catch ( EncoderException ee )
+ catch ( DecoderException de )
{
- ee.printStackTrace();
- fail( ee.getMessage() );
+ de.printStackTrace();
+ fail( de.getMessage() );
}
+ AddRequest addRequest2 = container.getMessage();
+ assertEquals( addRequest, addRequest2 );
+
+ // Check encode reverse
Asn1Buffer buffer = new Asn1Buffer();
AddRequest request = new AddRequestImpl();
@@ -228,8 +211,8 @@ public class AddRequestTest extends AbstractCodecServiceTest
/**
* Test the decoding of a AddRequest with a null body
*/
- @Test
- public void testDecodeAddRequestNullBody()
+ @Test( expected=DecoderException.class )
+ public void testDecodeAddRequestNullBody() throws DecoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
@@ -248,25 +231,15 @@ public class AddRequestTest extends AbstractCodecServiceTest
Asn1Container ldapMessageContainer = new LdapMessageContainer<AbstractMessageDecorator<? extends Message>>( codec );
// Decode a AddRequest message
- try
- {
- ldapDecoder.decode( stream, ldapMessageContainer );
- }
- catch ( DecoderException de )
- {
- assertTrue( true );
- return;
- }
-
- fail( "We should not reach this point" );
+ ldapDecoder.decode( stream, ldapMessageContainer );
}
/**
* Test the decoding of a AddRequest with a null entry
*/
- @Test
- public void testDecodeAddRequestNullEntry()
+ @Test( expected=DecoderException.class )
+ public void testDecodeAddRequestNullEntry() throws DecoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
@@ -316,18 +289,17 @@ public class AddRequestTest extends AbstractCodecServiceTest
assertTrue( response instanceof AddResponseImpl );
assertEquals( ResultCodeEnum.NAMING_VIOLATION, ( ( AddResponseImpl ) response ).getLdapResult()
.getResultCode() );
- return;
- }
- fail( "We should not reach this point" );
+ throw de;
+ }
}
/**
* Test the decoding of a AddRequest
*/
- @Test
- public void testDecodeAddRequestbadDN()
+ @Test( expected=DecoderException.class )
+ public void testDecodeAddRequestbadDN() throws DecoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
@@ -380,18 +352,17 @@ public class AddRequestTest extends AbstractCodecServiceTest
assertTrue( response instanceof AddResponseImpl );
assertEquals( ResultCodeEnum.INVALID_DN_SYNTAX, ( ( AddResponseImpl ) response ).getLdapResult()
.getResultCode() );
- return;
- }
- fail( "We should not reach this point" );
+ throw de;
+ }
}
/**
* Test the decoding of a AddRequest with a null attributeList
*/
- @Test
- public void testDecodeAddRequestNullAttributes()
+ @Test( expected=DecoderException.class )
+ public void testDecodeAddRequestNullAttributes() throws DecoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
@@ -417,25 +388,15 @@ public class AddRequestTest extends AbstractCodecServiceTest
Asn1Container ldapMessageContainer = new LdapMessageContainer<AbstractMessageDecorator<? extends Message>>( codec );
// Decode a AddRequest message
- try
- {
- ldapDecoder.decode( stream, ldapMessageContainer );
- }
- catch ( DecoderException de )
- {
- assertTrue( true );
- return;
- }
-
- fail( "We should not reach this point" );
+ ldapDecoder.decode( stream, ldapMessageContainer );
}
/**
* Test the decoding of a AddRequest with a empty attributeList
*/
- @Test
- public void testDecodeAddRequestNullAttributeList()
+ @Test( expected=DecoderException.class )
+ public void testDecodeAddRequestNullAttributeList() throws DecoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
@@ -462,25 +423,15 @@ public class AddRequestTest extends AbstractCodecServiceTest
Asn1Container ldapMessageContainer = new LdapMessageContainer<AbstractMessageDecorator<? extends Message>>( codec );
// Decode a AddRequest message
- try
- {
- ldapDecoder.decode( stream, ldapMessageContainer );
- }
- catch ( DecoderException de )
- {
- assertTrue( true );
- return;
- }
-
- fail( "We should not reach this point" );
+ ldapDecoder.decode( stream, ldapMessageContainer );
}
/**
* Test the decoding of a AddRequest with a empty attributeList
*/
- @Test
- public void testDecodeAddRequestNullType()
+ @Test( expected=DecoderException.class )
+ public void testDecodeAddRequestNullType() throws DecoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
@@ -519,18 +470,17 @@ public class AddRequestTest extends AbstractCodecServiceTest
assertTrue( response instanceof AddResponseImpl );
assertEquals( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, ( ( AddResponseImpl ) response ).getLdapResult()
.getResultCode() );
- return;
- }
- fail( "We should not reach this point" );
+ throw de;
+ }
}
/**
* Test the decoding of a AddRequest with a empty attributeList
*/
- @Test
- public void testDecodeAddRequestNoVals()
+ @Test( expected=DecoderException.class )
+ public void testDecodeAddRequestNoVals() throws DecoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
@@ -559,25 +509,15 @@ public class AddRequestTest extends AbstractCodecServiceTest
Asn1Container ldapMessageContainer = new LdapMessageContainer<AbstractMessageDecorator<? extends Message>>( codec );
// Decode a AddRequest message
- try
- {
- ldapDecoder.decode( stream, ldapMessageContainer );
- }
- catch ( DecoderException de )
- {
- assertTrue( true );
- return;
- }
-
- fail( "We should not reach this point" );
+ ldapDecoder.decode( stream, ldapMessageContainer );
}
/**
* Test the decoding of a AddRequest with a empty attributeList
*/
- @Test
- public void testDecodeAddRequestNullVals()
+ @Test( expected=DecoderException.class )
+ public void testDecodeAddRequestNullVals() throws DecoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
@@ -607,17 +547,7 @@ public class AddRequestTest extends AbstractCodecServiceTest
Asn1Container ldapMessageContainer = new LdapMessageContainer<AbstractMessageDecorator<? extends Message>>( codec );
// Decode a AddRequest message
- try
- {
- ldapDecoder.decode( stream, ldapMessageContainer );
- }
- catch ( DecoderException de )
- {
- assertTrue( true );
- return;
- }
-
- fail( "We should not reach this point" );
+ ldapDecoder.decode( stream, ldapMessageContainer );
}
@@ -625,7 +555,7 @@ public class AddRequestTest extends AbstractCodecServiceTest
* Test the decoding of a AddRequest with a empty attributeList
*/
@Test
- public void testDecodeAddRequestEmptyAttributeValue() throws NamingException
+ public void testDecodeAddRequestEmptyAttributeValue() throws DecoderException, EncoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
@@ -657,15 +587,7 @@ public class AddRequestTest extends AbstractCodecServiceTest
LdapMessageContainer<AddRequestDecorator> container = new LdapMessageContainer<AddRequestDecorator>( codec );
// Decode a AddRequest message
- try
- {
- ldapDecoder.decode( stream, container );
- }
- catch ( DecoderException de )
- {
- de.printStackTrace();
- fail( de.getMessage() );
- }
+ ldapDecoder.decode( stream, container );
AddRequest addRequest = container.getMessage();
@@ -687,22 +609,24 @@ public class AddRequestTest extends AbstractCodecServiceTest
}
// Check the encoding
- try
- {
- ByteBuffer bb = LdapEncoder.encodeMessage( codec, addRequest );
+ ByteBuffer bb = LdapEncoder.encodeMessage( codec, addRequest );
- // Check the length
- assertEquals( 0x34, bb.limit() );
+ // Check the length
+ assertEquals( 0x34, bb.limit() );
- String encodedPdu = Strings.dumpBytes( bb.array() );
+ String encodedPdu = Strings.dumpBytes( bb.array() );
- assertEquals( encodedPdu, decodedPdu );
- }
- catch ( EncoderException ee )
- {
- ee.printStackTrace();
- fail( ee.getMessage() );
- }
+ assertEquals( encodedPdu, decodedPdu );
+ // Check encode reverse
+ Asn1Buffer buffer = new Asn1Buffer();
+
+ AddRequest request = new AddRequestImpl();
+ request.setEntry( addRequest.getEntry() );
+ request.setMessageId( addRequest.getMessageId() );
+
+ LdapEncoder.encodeMessageReverse( buffer, codec, request );
+
+ assertTrue( Arrays.equals( stream.array(), buffer.getBytes().array() ) );
}
@@ -711,7 +635,7 @@ public class AddRequestTest extends AbstractCodecServiceTest
* control
*/
@Test
- public void testDecodeAddRequestEmptyAttributeValueWithControl() throws NamingException
+ public void testDecodeAddRequestEmptyAttributeValueWithControl() throws DecoderException, EncoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
@@ -749,15 +673,7 @@ public class AddRequestTest extends AbstractCodecServiceTest
LdapMessageContainer<AddRequestDecorator> container = new LdapMessageContainer<AddRequestDecorator>( codec );
// Decode a AddRequest message
- try
- {
- ldapDecoder.decode( stream, container );
- }
- catch ( DecoderException de )
- {
- de.printStackTrace();
- fail( de.getMessage() );
- }
+ ldapDecoder.decode( stream, container );
AddRequest addRequest = container.getMessage();
@@ -792,21 +708,13 @@ public class AddRequestTest extends AbstractCodecServiceTest
assertEquals( "", Strings.dumpBytes( control.getValue() ) );
// Check the encoding
- try
- {
- ByteBuffer bb = LdapEncoder.encodeMessage( codec, addRequest );
+ ByteBuffer bb = LdapEncoder.encodeMessage( codec, addRequest );
- // Check the length
- assertEquals( 0x51, bb.limit() );
+ // Check the length
+ assertEquals( 0x51, bb.limit() );
- String encodedPdu = Strings.dumpBytes( bb.array() );
+ String encodedPdu = Strings.dumpBytes( bb.array() );
- assertEquals( encodedPdu, decodedPdu );
- }
- catch ( EncoderException ee )
- {
- ee.printStackTrace();
- fail( ee.getMessage() );
- }
+ assertEquals( encodedPdu, decodedPdu );
}
}
diff --git a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/bind/BindRequestTest.java b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/bind/BindRequestTest.java
index b4564c7..b80949f 100644
--- a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/bind/BindRequestTest.java
+++ b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/bind/BindRequestTest.java
@@ -27,12 +27,14 @@ import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.nio.ByteBuffer;
+import java.util.Arrays;
import java.util.Map;
import org.apache.directory.api.asn1.DecoderException;
import org.apache.directory.api.asn1.EncoderException;
import org.apache.directory.api.asn1.ber.Asn1Container;
import org.apache.directory.api.asn1.ber.Asn1Decoder;
+import org.apache.directory.api.asn1.util.Asn1Buffer;
import org.apache.directory.api.ldap.codec.api.AbstractMessageDecorator;
import org.apache.directory.api.ldap.codec.api.CodecControl;
import org.apache.directory.api.ldap.codec.api.LdapEncoder;
@@ -41,6 +43,7 @@ import org.apache.directory.api.ldap.codec.api.ResponseCarryingException;
import org.apache.directory.api.ldap.codec.decorators.BindRequestDecorator;
import org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest;
import org.apache.directory.api.ldap.model.message.BindRequest;
+import org.apache.directory.api.ldap.model.message.BindRequestImpl;
import org.apache.directory.api.ldap.model.message.BindResponseImpl;
import org.apache.directory.api.ldap.model.message.Control;
import org.apache.directory.api.ldap.model.message.Message;
@@ -164,68 +167,26 @@ public class BindRequestTest extends AbstractCodecServiceTest
* controls
*/
@Test
- public void testDecodeBindRequestSimpleWithControls()
+ public void testDecodeBindRequestSimpleWithControls() throws DecoderException, EncoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
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' } );
+ {
+ 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'
+ } );
String decodedPdu = Strings.dumpBytes( stream.array() );
stream.flip();
@@ -234,15 +195,7 @@ public class BindRequestTest extends AbstractCodecServiceTest
LdapMessageContainer<BindRequestDecorator> container = new LdapMessageContainer<BindRequestDecorator>( codec );
// Decode the BindRequest PDU
- try
- {
- ldapDecoder.decode( stream, container );
- }
- catch ( DecoderException de )
- {
- de.printStackTrace();
- fail( de.getMessage() );
- }
+ ldapDecoder.decode( stream, container );
// Check the decoded BindRequest
BindRequest bindRequest = container.getMessage();
@@ -254,22 +207,14 @@ public class BindRequestTest extends AbstractCodecServiceTest
assertEquals( "password", Strings.utf8ToString( bindRequest.getCredentials() ) );
// Check the encoding
- try
- {
- ByteBuffer bb = LdapEncoder.encodeMessage( codec, bindRequest );
+ ByteBuffer bb = LdapEncoder.encodeMessage( codec, bindRequest );
- // Check the length
- assertEquals( 0x35, bb.limit() );
+ // Check the length
+ assertEquals( 0x35, bb.limit() );
- String encodedPdu = Strings.dumpBytes( bb.array() );
+ String encodedPdu = Strings.dumpBytes( bb.array() );
- assertEquals( encodedPdu, decodedPdu );
- }
- catch ( EncoderException ee )
- {
- ee.printStackTrace();
- fail( ee.getMessage() );
- }
+ assertEquals( encodedPdu, decodedPdu );
}
@@ -278,68 +223,26 @@ public class BindRequestTest extends AbstractCodecServiceTest
* controls
*/
@Test
- public void testDecodeBindRequestBadDN()
+ public void testDecodeBindRequestBadDN() throws DecoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
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' } );
+ {
+ 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();
@@ -363,7 +266,8 @@ public class BindRequestTest extends AbstractCodecServiceTest
assertTrue( response instanceof BindResponseImpl );
assertEquals( ResultCodeEnum.INVALID_DN_SYNTAX, ( ( BindResponseImpl ) response ).getLdapResult()
.getResultCode() );
- return;
+
+ throw de;
}
}
@@ -372,35 +276,24 @@ public class BindRequestTest extends AbstractCodecServiceTest
* Test the decoding of a BindRequest with Simple authentication, no name
* and no controls
*/
- @Test
- public void testDecodeBindRequestSimpleNoName()
+ @Test( expected=DecoderException.class )
+ public void testDecodeBindRequestSimpleNoName() throws DecoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
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();
@@ -408,18 +301,7 @@ public class BindRequestTest extends AbstractCodecServiceTest
Asn1Container container = new LdapMessageContainer<AbstractMessageDecorator<? extends Message>>( codec );
// Decode the BindRequest PDU
- try
- {
- ldapDecoder.decode( stream, container );
- }
- catch ( DecoderException de )
- {
- assertEquals( "ERR_01200_BAD_TRANSITION_FROM_STATE Bad transition from state VERSION_STATE, tag 0x80",
- de.getMessage() );
- return;
- }
-
- fail( "Should never reach this point." );
+ ldapDecoder.decode( stream, container );
}
@@ -428,36 +310,24 @@ public class BindRequestTest extends AbstractCodecServiceTest
* (an anonymous bind) and no controls
*/
@Test
- public void testDecodeBindRequestSimpleEmptyName()
+ public void testDecodeBindRequestSimpleEmptyName() throws DecoderException, EncoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
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 = Strings.dumpBytes( stream.array() );
@@ -467,15 +337,7 @@ public class BindRequestTest extends AbstractCodecServiceTest
LdapMessageContainer<BindRequestDecorator> container = new LdapMessageContainer<BindRequestDecorator>( codec );
// Decode the BindRequest PDU
- try
- {
- ldapDecoder.decode( stream, container );
- }
- catch ( DecoderException de )
- {
- de.printStackTrace();
- fail( de.getMessage() );
- }
+ ldapDecoder.decode( stream, container );
// Check the decoded BindRequest
BindRequest bindRequest = container.getMessage();
@@ -487,22 +349,26 @@ public class BindRequestTest extends AbstractCodecServiceTest
assertEquals( "password", Strings.utf8ToString( bindRequest.getCredentials() ) );
// Check the encoding
- try
- {
- ByteBuffer bb = LdapEncoder.encodeMessage( codec, bindRequest );
+ ByteBuffer bb = LdapEncoder.encodeMessage( codec, bindRequest );
- // Check the length
- assertEquals( 0x16, bb.limit() );
+ // Check the length
+ assertEquals( 0x16, bb.limit() );
- String encodedPdu = Strings.dumpBytes( bb.array() );
+ String encodedPdu = Strings.dumpBytes( bb.array() );
- assertEquals( encodedPdu, decodedPdu );
- }
- catch ( EncoderException ee )
- {
- ee.printStackTrace();
- fail( ee.getMessage() );
- }
+ assertEquals( encodedPdu, decodedPdu );
+
+ // Check encode reverse
+ Asn1Buffer buffer = new Asn1Buffer();
+
+ BindRequest request = new BindRequestImpl();
+ request.setCredentials( "password" );
+ request.setSimple( true );
+ request.setMessageId( 1 );
+
+ LdapEncoder.encodeMessageReverse( buffer, codec, request );
+
+ assertTrue( Arrays.equals( stream.array(), buffer.getBytes().array() ) );
}
@@ -511,76 +377,30 @@ public class BindRequestTest extends AbstractCodecServiceTest
* credentials and no controls
*/
@Test
- public void testDecodeBindRequestSaslNoCredsNoControls()
+ public void testDecodeBindRequestSaslNoCredsNoControls() throws DecoderException, EncoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
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 = Strings.dumpBytes( stream.array() );
stream.flip();
@@ -589,15 +409,7 @@ public class BindRequestTest extends AbstractCodecServiceTest
LdapMessageContainer<BindRequestDecorator> container = new LdapMessageContainer<BindRequestDecorator>( codec );
// Decode the BindRequest PDU
- try
- {
- ldapDecoder.decode( stream, container );
- }
- catch ( DecoderException de )
- {
- de.printStackTrace();
- fail( de.getMessage() );
- }
+ ldapDecoder.decode( stream, container );
// Check the decoded BindRequest
BindRequest bindRequest = container.getMessage();
@@ -609,22 +421,27 @@ public class BindRequestTest extends AbstractCodecServiceTest
assertEquals( "KERBEROS_V4", bindRequest.getSaslMechanism() );
// Check the encoding
- try
- {
- ByteBuffer bb = LdapEncoder.encodeMessage( codec, bindRequest );
+ ByteBuffer bb = LdapEncoder.encodeMessage( codec, bindRequest );
- // Check the length
- assertEquals( 0x3A, bb.limit() );
+ // Check the length
+ assertEquals( 0x3A, bb.limit() );
- String encodedPdu = Strings.dumpBytes( bb.array() );
+ String encodedPdu = Strings.dumpBytes( bb.array() );
- assertEquals( encodedPdu, decodedPdu );
- }
- catch ( EncoderException ee )
- {
- ee.printStackTrace();
- fail( ee.getMessage() );
- }
+ assertEquals( encodedPdu, decodedPdu );
+
+ // Check encode reverse
+ Asn1Buffer buffer = new Asn1Buffer();
+
+ BindRequest request = new BindRequestImpl();
+ request.setName( "uid=akarasulu,dc=example,dc=com" );
+ request.setSimple( false );
+ request.setSaslMechanism( "KERBEROS_V4" );
+ request.setMessageId( 1 );
+
+ LdapEncoder.encodeMessageReverse( buffer, codec, request );
+
+ assertTrue( Arrays.equals( stream.array(), buffer.getBytes().array() ) );
}
@@ -633,88 +450,36 @@ public class BindRequestTest extends AbstractCodecServiceTest
* credentials and no controls
*/
@Test
- public void testDecodeBindRequestSaslCredsNoControls()
+ public void testDecodeBindRequestSaslCredsNoControls() throws DecoderException, EncoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
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,
- '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' } );
+ {
+ 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'
+ } );
String decodedPdu = Strings.dumpBytes( stream.array() );
stream.flip();
@@ -723,15 +488,7 @@ public class BindRequestTest extends AbstractCodecServiceTest
LdapMessageContainer<BindRequestDecorator> container = new LdapMessageContainer<BindRequestDecorator>( codec );
// Decode the BindRequest PDU
- try
- {
- ldapDecoder.decode( stream, container );
- }
- catch ( DecoderException de )
- {
- de.printStackTrace();
- fail( de.getMessage() );
- }
+ ldapDecoder.decode( stream, container );
// Check the decoded BindRequest
BindRequest bindRequest = container.getMessage();
@@ -744,22 +501,27 @@ public class BindRequestTest extends AbstractCodecServiceTest
assertEquals( "abcdef", Strings.utf8ToString( bindRequest.getCredentials() ) );
// Check the encoding
- try
- {
- ByteBuffer bb = LdapEncoder.encodeMessage( codec, bindRequest );
+ ByteBuffer bb = LdapEncoder.encodeMessage( codec, bindRequest );
- // Check the length
- assertEquals( 0x42, bb.limit() );
+ // Check the length
+ assertEquals( 0x42, bb.limit() );
- String encodedPdu = Strings.dumpBytes( bb.array() );
+ String encodedPdu = Strings.dumpBytes( bb.array() );
- assertEquals( encodedPdu, decodedPdu );
- }
- catch ( EncoderException ee )
- {
- ee.printStackTrace();
- fail( ee.getMessage() );
- }
+ assertEquals( encodedPdu, decodedPdu );
+ // Check encode reverse
+ Asn1Buffer buffer = new Asn1Buffer();
+
+ BindRequest request = new BindRequestImpl();
+ request.setName( "uid=akarasulu,dc=example,dc=com" );
+ request.setSimple( false );
+ request.setSaslMechanism( "KERBEROS_V4" );
+ request.setMessageId( 1 );
+ request.setCredentials( "abcdef" );
+
+ LdapEncoder.encodeMessageReverse( buffer, codec, request );
+
+ assertTrue( Arrays.equals( stream.array(), buffer.getBytes().array() ) );
}
@@ -768,56 +530,34 @@ public class BindRequestTest extends AbstractCodecServiceTest
* credentials and no controls
*/
@Test
- public void testDecodeBindRequestSaslNoNameCredsNoControls()
+ public void testDecodeBindRequestSaslNoNameCredsNoControls() throws DecoderException, EncoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate( 0x23 );
stream.put( new byte[]
- { 0x30, 0x21, // LDAPMessage ::=SEQUENCE {
- 0x02,
- 0x01,
- 0x01, // messageID MessageID
- 0x60,
- 0x1C, // CHOICE { ..., bindRequest BindRequest, ...
- // BindRequest ::= APPLICATION[0] SEQUENCE {
- 0x02,
- 0x01,
- 0x03, // version INTEGER (1..127),
- 0x04,
- 0x00, // name LDAPDN,
- ( 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' } );
+ {
+ 0x30, 0x21, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x60, 0x1C, // CHOICE { ..., bindRequest BindRequest, ...
+ // BindRequest ::= APPLICATION[0] SEQUENCE {
+ 0x02, 0x01, 0x03, // version INTEGER (1..127),
+ 0x04, 0x00, // name LDAPDN,
+ ( 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 = Strings.dumpBytes( stream.array() );
stream.flip();
@@ -826,15 +566,7 @@ public class BindRequestTest extends AbstractCodecServiceTest
LdapMessageContainer<BindRequestDecorator> container = new LdapMessageContainer<BindRequestDecorator>( codec );
// Decode the BindRequest PDU
- try
- {
- ldapDecoder.decode( stream, container );
- }
- catch ( DecoderException de )
- {
- de.printStackTrace();
- fail( de.getMessage() );
- }
+ ldapDecoder.decode( stream, container );
// Check the decoded BindRequest
BindRequest bindRequest = container.getMessage();
@@ -847,42 +579,44 @@ public class BindRequestTest extends AbstractCodecServiceTest
assertEquals( "abcdef", Strings.utf8ToString( bindRequest.getCredentials() ) );
// Check the encoding
- try
- {
- ByteBuffer bb = LdapEncoder.encodeMessage( codec, bindRequest );
+ ByteBuffer bb = LdapEncoder.encodeMessage( codec, bindRequest );
- // Check the length
- assertEquals( 0x23, bb.limit() );
+ // Check the length
+ assertEquals( 0x23, bb.limit() );
- String encodedPdu = Strings.dumpBytes( bb.array() );
+ String encodedPdu = Strings.dumpBytes( bb.array() );
- assertEquals( encodedPdu, decodedPdu );
- }
- catch ( EncoderException ee )
- {
- ee.printStackTrace();
- fail( ee.getMessage() );
- }
+ assertEquals( encodedPdu, decodedPdu );
+ // Check encode reverse
+ Asn1Buffer buffer = new Asn1Buffer();
+
+ BindRequest request = new BindRequestImpl();
+ request.setSimple( false );
+ request.setSaslMechanism( "KERBEROS_V4" );
+ request.setMessageId( 1 );
+ request.setCredentials( "abcdef" );
+
+ LdapEncoder.encodeMessageReverse( buffer, codec, request );
+
+ assertTrue( Arrays.equals( stream.array(), buffer.getBytes().array() ) );
}
/**
* Test the decoding of a BindRequest with an empty body
*/
- @Test
- public void testDecodeBindRequestEmptyBody()
+ @Test( expected=DecoderException.class )
+ public void testDecodeBindRequestEmptyBody() throws DecoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
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();
@@ -890,39 +624,26 @@ public class BindRequestTest extends AbstractCodecServiceTest
LdapMessageContainer<BindRequestDecorator> container = new LdapMessageContainer<BindRequestDecorator>( codec );
// Decode a BindRequest message
- try
- {
- ldapDecoder.decode( stream, container );
- }
- catch ( DecoderException de )
- {
- assertTrue( true );
- return;
- }
-
- fail( "We should not reach this point" );
+ ldapDecoder.decode( stream, container );
}
/**
* Test the decoding of a BindRequest with an empty version
*/
- @Test
- public void testDecodeBindRequestEmptyVersion()
+ @Test( expected=DecoderException.class )
+ public void testDecodeBindRequestEmptyVersion() throws DecoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
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();
@@ -930,40 +651,26 @@ public class BindRequestTest extends AbstractCodecServiceTest
LdapMessageContainer<BindRequestDecorator> container = new LdapMessageContainer<BindRequestDecorator>( codec );
// Decode a BindRequest message
- try
- {
- ldapDecoder.decode( stream, container );
- }
- catch ( DecoderException de )
- {
- assertTrue( true );
- return;
- }
-
- fail( "We should not reach this point" );
+ ldapDecoder.decode( stream, container );
}
/**
* Test the decoding of a BindRequest with a bad version (0)
*/
- @Test
- public void testDecodeBindRequestBadVersion0()
+ @Test( expected= DecoderException.class )
+ public void testDecodeBindRequestBadVersion0() throws DecoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
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();
@@ -971,40 +678,26 @@ public class BindRequestTest extends AbstractCodecServiceTest
LdapMessageContainer<BindRequestDecorator> container = new LdapMessageContainer<BindRequestDecorator>( codec );
// Decode a BindRequest message
- try
- {
- ldapDecoder.decode( stream, container );
- }
- catch ( DecoderException de )
- {
- assertTrue( true );
- return;
- }
-
- fail( "We should not reach this point" );
+ ldapDecoder.decode( stream, container );
}
/**
* Test the decoding of a BindRequest with a bad version (4)
*/
- @Test
- public void testDecodeBindRequestBadVersion4()
+ @Test( expected=DecoderException.class )
+ public void testDecodeBindRequestBadVersion4() throws DecoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
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();
@@ -1012,41 +705,26 @@ public class BindRequestTest extends AbstractCodecServiceTest
LdapMessageContainer<BindRequestDecorator> container = new LdapMessageContainer<BindRequestDecorator>( codec );
// Decode a BindRequest message
- try
- {
- ldapDecoder.decode( stream, container );
- }
- catch ( DecoderException de )
- {
- assertTrue( true );
- return;
- }
-
- fail( "We should not reach this point" );
+ ldapDecoder.decode( stream, container );
}
/**
* Test the decoding of a BindRequest with a bad version (128)
*/
- @Test
- public void testDecodeBindRequestBadVersion128()
+ @Test( expected=DecoderException.class )
+ public void testDecodeBindRequestBadVersion128() throws DecoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
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();
@@ -1054,40 +732,26 @@ public class BindRequestTest extends AbstractCodecServiceTest
LdapMessageContainer<BindRequestDecorator> container = new LdapMessageContainer<BindRequestDecorator>( codec );
// Decode a BindRequest message
- try
- {
- ldapDecoder.decode( stream, container );
- }
- catch ( DecoderException de )
- {
- assertTrue( true );
- return;
- }
-
- fail( "We should not reach this point" );
+ ldapDecoder.decode( stream, container );
}
/**
* Test the decoding of a BindRequest with no name
*/
- @Test
- public void testDecodeBindRequestNoName()
+ @Test( expected=DecoderException.class )
+ public void testDecodeBindRequestNoName() throws DecoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
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();
@@ -1095,41 +759,27 @@ public class BindRequestTest extends AbstractCodecServiceTest
LdapMessageContainer<BindRequestDecorator> container = new LdapMessageContainer<BindRequestDecorator>( codec );
// Decode a BindRequest message
- try
- {
- ldapDecoder.decode( stream, container );
- }
- catch ( DecoderException de )
- {
- assertTrue( true );
- return;
- }
-
- fail( "We should not reach this point" );
+ ldapDecoder.decode( stream, container );
}
/**
* Test the decoding of a BindRequest with an empty name
*/
- @Test
- public void testDecodeBindRequestEmptyName()
+ @Test( expected=DecoderException.class )
+ public void testDecodeBindRequestEmptyName() throws DecoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
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),
- 0x04,
- 0x00 } );
+ {
+ 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();
@@ -1137,17 +787,7 @@ public class BindRequestTest extends AbstractCodecServiceTest
LdapMessageContainer<BindRequestDecorator> container = new LdapMessageContainer<BindRequestDecorator>( codec );
// Decode a BindRequest message
- try
- {
- ldapDecoder.decode( stream, container );
- }
- catch ( DecoderException de )
- {
- assertTrue( true );
- return;
- }
-
- fail( "We should not reach this point" );
+ ldapDecoder.decode( stream, container );
}
@@ -1155,25 +795,20 @@ public class BindRequestTest extends AbstractCodecServiceTest
* Test the decoding of a BindRequest with an empty simple
*/
@Test
- public void testDecodeBindRequestEmptySimple()
+ public void testDecodeBindRequestEmptySimple() throws DecoderException, EncoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
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 ) 0x80,
- 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 ) 0x80, 0x00
+ } );
String decodedPdu = Strings.dumpBytes( stream.array() );
stream.flip();
@@ -1182,15 +817,7 @@ public class BindRequestTest extends AbstractCodecServiceTest
LdapMessageContainer<BindRequestDecorator> container = new LdapMessageContainer<BindRequestDecorator>( codec );
// Decode the BindRequest PDU
- try
- {
- ldapDecoder.decode( stream, container );
- }
- catch ( DecoderException de )
- {
- de.printStackTrace();
- fail( de.getMessage() );
- }
+ ldapDecoder.decode( stream, container );
// Check the decoded BindRequest
BindRequest bindRequest = container.getMessage();
@@ -1202,48 +829,46 @@ public class BindRequestTest extends AbstractCodecServiceTest
assertEquals( "", Strings.utf8ToString( bindRequest.getCredentials() ) );
// Check the encoding
- try
- {
- ByteBuffer bb = LdapEncoder.encodeMessage( codec, bindRequest );
+ ByteBuffer bb = LdapEncoder.encodeMessage( codec, bindRequest );
- // Check the length
- assertEquals( 0x0E, bb.limit() );
+ // Check the length
+ assertEquals( 0x0E, bb.limit() );
- String encodedPdu = Strings.dumpBytes( bb.array() );
+ String encodedPdu = Strings.dumpBytes( bb.array() );
- assertEquals( encodedPdu, decodedPdu );
- }
- catch ( EncoderException ee )
- {
- ee.printStackTrace();
- fail( ee.getMessage() );
- }
+ assertEquals( encodedPdu, decodedPdu );
+
+ // Check encode reverse
+ Asn1Buffer buffer = new Asn1Buffer();
+
+ BindRequest request = new BindRequestImpl();
+ request.setSimple( true );
+ request.setMessageId( 1 );
+
+ LdapEncoder.encodeMessageReverse( buffer, codec, request );
+
+ assertTrue( Arrays.equals( stream.array(), buffer.getBytes().array() ) );
}
/**
* Test the decoding of a BindRequest with an empty sasl
*/
- @Test
- public void testDecodeBindRequestEmptySasl()
+ @Test( expected=DecoderException.class )
+ public void testDecodeBindRequestEmptySasl() throws DecoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
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();
@@ -1262,7 +887,8 @@ public class BindRequestTest extends AbstractCodecServiceTest
assertTrue( response instanceof BindResponseImpl );
assertEquals( ResultCodeEnum.INVALID_CREDENTIALS, ( ( BindResponseImpl ) response ).getLdapResult()
.getResultCode() );
- return;
+
+ throw de;
}
fail( "We should not reach this point" );
@@ -1273,27 +899,21 @@ public class BindRequestTest extends AbstractCodecServiceTest
* Test the decoding of a BindRequest with an empty mechanism
*/
@Test
- public void testDecodeBindRequestEmptyMechanism()
+ public void testDecodeBindRequestEmptyMechanism() throws DecoderException, EncoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
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 = Strings.dumpBytes( stream.array() );
stream.flip();
@@ -1302,15 +922,7 @@ public class BindRequestTest extends AbstractCodecServiceTest
LdapMessageContainer<BindRequestDecorator> container = new LdapMessageContainer<BindRequestDecorator>( codec );
// Decode the BindRequest PDU
- try
- {
- ldapDecoder.decode( stream, container );
- }
- catch ( DecoderException de )
- {
- de.printStackTrace();
- fail( de.getMessage() );
- }
+ ldapDecoder.decode( stream, container );
// Check the decoded BindRequest
BindRequest bindRequest = container.getMessage();
@@ -1322,22 +934,25 @@ public class BindRequestTest extends AbstractCodecServiceTest
assertEquals( "", bindRequest.getSaslMechanism() );
// Check the encoding
- try
- {
- ByteBuffer bb = LdapEncoder.encodeMessage( codec, bindRequest );
+ ByteBuffer bb = LdapEncoder.encodeMessage( codec, bindRequest );
- // Check the length
- assertEquals( 0x10, bb.limit() );
+ // Check the length
+ assertEquals( 0x10, bb.limit() );
- String encodedPdu = Strings.dumpBytes( bb.array() );
+ String encodedPdu = Strings.dumpBytes( bb.array() );
- assertEquals( encodedPdu, decodedPdu );
- }
- catch ( EncoderException ee )
- {
- ee.printStackTrace();
- fail( ee.getMessage() );
- }
+ assertEquals( encodedPdu, decodedPdu );
+
+ // Check encode reverse
+ Asn1Buffer buffer = new Asn1Buffer();
+
+ BindRequest request = new BindRequestImpl();
+ request.setSimple( false );
+ request.setMessageId( 1 );
+
+ LdapEncoder.encodeMessageReverse( buffer, codec, request );
+
+ assertTrue( Arrays.equals( stream.array(), buffer.getBytes().array() ) );
}
@@ -1389,29 +1004,22 @@ public class BindRequestTest extends AbstractCodecServiceTest
* Test the decoding of a BindRequest with an empty credentials
*/
@Test
- public void testDecodeBindRequestEmptyCredentials()
+ public void testDecodeBindRequestEmptyCredentials() throws EncoderException, DecoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
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 = Strings.dumpBytes( stream.array() );
stream.flip();
@@ -1420,15 +1028,7 @@ public class BindRequestTest extends AbstractCodecServiceTest
LdapMessageContainer<BindRequestDecorator> container = new LdapMessageContainer<BindRequestDecorator>( codec );
// Decode the BindRequest PDU
- try
- {
- ldapDecoder.decode( stream, container );
- }
- catch ( DecoderException de )
- {
- de.printStackTrace();
- fail( de.getMessage() );
- }
+ ldapDecoder.decode( stream, container );
// Check the decoded BindRequest
BindRequest bindRequest = container.getMessage();
@@ -1441,22 +1041,36 @@ public class BindRequestTest extends AbstractCodecServiceTest
assertEquals( "", Strings.utf8ToString( bindRequest.getCredentials() ) );
// Check the encoding
- try
- {
- ByteBuffer bb = LdapEncoder.encodeMessage( codec, bindRequest );
-
- // Check the length
- assertEquals( 0x12, bb.limit() );
-
- String encodedPdu = Strings.dumpBytes( bb.array() );
+ ByteBuffer bb = LdapEncoder.encodeMessage( codec, bindRequest );
- assertEquals( encodedPdu, decodedPdu );
- }
- catch ( EncoderException ee )
- {
- ee.printStackTrace();
- fail( ee.getMessage() );
- }
+ // Check the length
+ assertEquals( 0x12, bb.limit() );
+
+ String encodedPdu = Strings.dumpBytes( bb.array() );
+
+ assertEquals( encodedPdu, decodedPdu );
+ // Check encode reverse
+ Asn1Buffer buffer = new Asn1Buffer();
+
+ BindRequest request = new BindRequestImpl();
+ request.setSimple( false );
+ request.setMessageId( 1 );
+ request.setCredentials( "" );
+
+ LdapEncoder.encodeMessageReverse( buffer, codec, request );
+
+ assertTrue( Arrays.equals(
+ 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
+ },
+ buffer.getBytes().array() ) );
}
@@ -1465,59 +1079,27 @@ public class BindRequestTest extends AbstractCodecServiceTest
* controls
*/
@Test
- public void testDecodeBindRequestEmptyCredentialsWithControls()
+ public void testDecodeBindRequestEmptyCredentialsWithControls() throws DecoderException, EncoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
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 } );
+ {
+ 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,
+ '2', '.', '1', '6', '.', '8', '4', '0', '.', '1', '.',
+ '1', '1', '3', '7', '3', '0', '.', '3', '.', '4', '.', '2'
+ } );
String decodedPdu = Strings.dumpBytes( stream.array() );
stream.flip();
@@ -1526,15 +1108,7 @@ public class BindRequestTest extends AbstractCodecServiceTest
LdapMessageContainer<BindRequestDecorator> container = new LdapMessageContainer<BindRequestDecorator>( codec );
// Decode the BindRequest PDU
- try
- {
- ldapDecoder.decode( stream, container );
- }
- catch ( DecoderException de )
- {
- de.printStackTrace();
- fail( de.getMessage() );
- }
+ ldapDecoder.decode( stream, container );
// Check the decoded BindRequest
BindRequest bindRequest = container.getMessage();
@@ -1558,22 +1132,14 @@ public class BindRequestTest extends AbstractCodecServiceTest
assertEquals( "", Strings.dumpBytes( control.getValue() ) );
// Check the encoding
- try
- {
- ByteBuffer bb = LdapEncoder.encodeMessage( codec, bindRequest );
+ ByteBuffer bb = LdapEncoder.encodeMessage( codec, bindRequest );
- // Check the length
- assertEquals( 0x2F, bb.limit() );
+ // Check the length
+ assertEquals( 0x2F, bb.limit() );
- String encodedPdu = Strings.dumpBytes( bb.array() );
+ String encodedPdu = Strings.dumpBytes( bb.array() );
- assertEquals( encodedPdu, decodedPdu );
- }
- catch ( EncoderException ee )
- {
- ee.printStackTrace();
- fail( ee.getMessage() );
- }
+ assertEquals( encodedPdu, decodedPdu );
}
@@ -1581,57 +1147,26 @@ public class BindRequestTest extends AbstractCodecServiceTest
* Test the decoding of a BindRequest with an empty mechanisms with controls
*/
@Test
- public void testDecodeBindRequestEmptyMechanismWithControls()
+ public void testDecodeBindRequestEmptyMechanismWithControls() throws EncoderException, DecoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
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,
- 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, 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,
+ '2', '.', '1', '6', '.', '8', '4', '0', '.', '1', '.',
+ '1', '1', '3', '7', '3', '0', '.', '3', '.', '4', '.', '2'
+ } );
String decodedPdu = Strings.dumpBytes( stream.array() );
stream.flip();
@@ -1640,15 +1175,7 @@ public class BindRequestTest extends AbstractCodecServiceTest
LdapMessageContainer<BindRequestDecorator> container = new LdapMessageContainer<BindRequestDecorator>( codec );
// Decode the BindRequest PDU
- try
- {
- ldapDecoder.decode( stream, container );
- }
- catch ( DecoderException de )
- {
- de.printStackTrace();
- fail( de.getMessage() );
- }
+ ldapDecoder.decode( stream, container );
// Check the decoded BindRequest
BindRequest bindRequest = container.getMessage();
@@ -1672,22 +1199,14 @@ public class BindRequestTest extends AbstractCodecServiceTest
assertEquals( "", Strings.dumpBytes( control.getValue() ) );
// Check the encoding
- try
- {
- ByteBuffer bb = LdapEncoder.encodeMessage( codec, bindRequest );
+ ByteBuffer bb = LdapEncoder.encodeMessage( codec, bindRequest );
- // Check the length
- assertEquals( 0x2D, bb.limit() );
+ // Check the length
+ assertEquals( 0x2D, bb.limit() );
- String encodedPdu = Strings.dumpBytes( bb.array() );
+ String encodedPdu = Strings.dumpBytes( bb.array() );
- assertEquals( encodedPdu, decodedPdu );
- }
- catch ( EncoderException ee )
- {
- ee.printStackTrace();
- fail( ee.getMessage() );
- }
+ assertEquals( encodedPdu, decodedPdu );
}
/**
diff --git a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/compare/CompareRequestTest.java b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/compare/CompareRequestTest.java
index 49667bb..ac0bf13 100644
--- a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/compare/CompareRequestTest.java
+++ b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/compare/CompareRequestTest.java
@@ -69,67 +69,22 @@ public class CompareRequestTest extends AbstractCodecServiceTest
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,
- 0x0D, // AttributeValueAssertion ::= SEQUENCE {
- // attributeDesc AttributeDescription,
- 0x04,
- 0x04,
- 't',
- 'e',
- 's',
- 't',
- // assertionValue AssertionValue }
- 0x04,
- 0x05,
- 'v',
- 'a',
- 'l',
- 'u',
- 'e' } );
+ {
+ 0x30, 0x36, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ // CHOICE { ..., compareRequest CompareRequest, ...
+ 0x6E, 0x31, // CompareRequest ::= [APPLICATION 14] SEQUENCE {
+ 0x04, 0x20, // entry LDAPDN,
+ '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 {
+ 0x04, 0x04, // attributeDesc AttributeDescription,
+ 't', 'e', 's', 't',
+ 0x04, 0x05, // assertionValue AssertionValue }
+ 'v', 'a', 'l', 'u', 'e'
+ } );
String decodedPdu = Strings.dumpBytes( stream.array() );
stream.flip();
@@ -188,13 +143,11 @@ public class CompareRequestTest extends AbstractCodecServiceTest
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();
@@ -227,33 +180,19 @@ public class CompareRequestTest extends AbstractCodecServiceTest
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 {
+ 0x04, 0x04, // attributeDesc AttributeDescription,
+ 't', 'e', 's', 't',
+ 0x04, 0x05, // assertionValue AssertionValue }
+ 'v', 'a', 'l', 'u', 'e'
+ } );
stream.flip();
@@ -285,52 +224,17 @@ public class CompareRequestTest extends AbstractCodecServiceTest
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 {
+ 0x04, 0x20, // entry LDAPDN,
+ '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();
@@ -363,52 +267,17 @@ public class CompareRequestTest extends AbstractCodecServiceTest
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 {
+ 0x04, 0x20, // entry LDAPDN,
+ '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();
@@ -446,54 +315,19 @@ public class CompareRequestTest extends AbstractCodecServiceTest
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',
- 's',
- 'e',
- 'r',
- 's',
- ',',
- 'o',
- 'u',
- '=',
- 's',
- 'y',
- 's',
- 't',
- 'e',
- 'm',
- // ava AttributeValueAssertion }
- 0x30,
- 0x02, // AttributeValueAssertion ::= SEQUENCE {
- 0x04,
- 0x00 } );
+ {
+ 0x30, 0x2B, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ // CHOICE { ..., compareRequest CompareRequest, ...
+ 0x6E, 0x26, // CompareRequest ::= [APPLICATION 14] SEQUENCE {
+ 0x04, 0x20, // entry LDAPDN,
+ '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
+ } );
stream.flip();
@@ -530,62 +364,21 @@ public class CompareRequestTest extends AbstractCodecServiceTest
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 {
+ 0x04, 0x20, // entry LDAPDN,
+ '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 {
+ 0x04, 0x04, // attributeDesc AttributeDescription,
+ 't', 'e', 's', 't',
+ 0x04, 0x00 // assertionValue AssertionValue }
+ } );
String decodedPdu = Strings.dumpBytes( stream.array() );
stream.flip();
@@ -645,96 +438,26 @@ public class CompareRequestTest extends AbstractCodecServiceTest
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,
- 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, 0x53, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ // CHOICE { ..., compareRequest CompareRequest, ...
+ 0x6E, 0x31, // CompareRequest ::= [APPLICATION 14] SEQUENCE {
+ 0x04, 0x20, // entry LDAPDN,
+ '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 {
+ 0x04, 0x04, // attributeDesc AttributeDescription,
+ 't', 'e', 's', 't',
+ 0x04, 0x05, // assertionValue AssertionValue }
+ '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 = Strings.dumpBytes( stream.array() );
stream.flip();
diff --git a/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/controls/ad_impl/AdDirSyncFactory.java b/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/controls/ad_impl/AdDirSyncFactory.java
index 211abd0..b1d022b 100644
--- a/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/controls/ad_impl/AdDirSyncFactory.java
+++ b/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/controls/ad_impl/AdDirSyncFactory.java
@@ -84,7 +84,5 @@ public class AdDirSyncFactory implements ControlFactory<AdDirSync>
@Override
public void encodeValue( Asn1Buffer buffer, Control control )
{
- // TODO Auto-generated method stub
-
}
}
diff --git a/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/controls/ad_impl/AdPolicyHintsFactory.java b/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/controls/ad_impl/AdPolicyHintsFactory.java
index bc7b9ea..33d1a6c 100644
--- a/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/controls/ad_impl/AdPolicyHintsFactory.java
+++ b/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/controls/ad_impl/AdPolicyHintsFactory.java
@@ -20,6 +20,7 @@
package org.apache.directory.api.ldap.extras.controls.ad_impl;
+import org.apache.directory.api.asn1.ber.tlv.BerValue;
import org.apache.directory.api.asn1.util.Asn1Buffer;
import org.apache.directory.api.ldap.codec.api.CodecControl;
import org.apache.directory.api.ldap.codec.api.ControlFactory;
@@ -79,10 +80,18 @@ public class AdPolicyHintsFactory implements ControlFactory<AdPolicyHints>
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public void encodeValue( Asn1Buffer buffer, Control control )
{
- // TODO Auto-generated method stub
+ int start = buffer.getPos();
+
+ // Encode the flags
+ BerValue.encodeInteger( buffer, ( ( AdPolicyHints ) control ).getFlags() );
+ // Encode the SEQ
+ BerValue.encodeSequence( buffer, start );
}
}
\ No newline at end of file
diff --git a/util/src/main/java/org/apache/directory/api/util/Strings.java b/util/src/main/java/org/apache/directory/api/util/Strings.java
index ff23f04..4ad7ebe 100644
--- a/util/src/main/java/org/apache/directory/api/util/Strings.java
+++ b/util/src/main/java/org/apache/directory/api/util/Strings.java
@@ -58,37 +58,37 @@ public final class Strings
private static final boolean[] IS_PRINTABLE_CHAR =
{
// ---, ---, ---, ---, ---, ---, ---, ---
- false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false,
// ---, ---, ---, ---, ---, ---, ---, ---
- false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false,
// ---, ---, ---, ---, ---, ---, ---, ---
- false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false,
// ---, ---, ---, ---, ---, ---, ---, ---
- false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false,
// ' ', ---, ---, ---, ---, ---, ---, "'"
- true, false, false, false, false, false, false, true,
+ true, false, false, false, false, false, false, true,
// '(', ')', ---, '+', ',', '-', '.', '/'
- true, true, false, true, true, true, true, true,
+ true, true, false, true, true, true, true, true,
// '0', '1', '2', '3', '4', '5', '6', '7',
- true, true, true, true, true, true, true, true,
+ true, true, true, true, true, true, true, true,
// '8', '9', ':', ---, ---, '=', ---, '?'
- true, true, true, false, false, true, false, true,
+ true, true, true, false, false, true, false, true,
// ---, 'A', 'B', 'C', 'D', 'E', 'F', 'G',
- false, true, true, true, true, true, true, true,
+ false, true, true, true, true, true, true, true,
// 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O'
- true, true, true, true, true, true, true, true,
+ true, true, true, true, true, true, true, true,
// 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W'
- true, true, true, true, true, true, true, true,
+ true, true, true, true, true, true, true, true,
// 'X', 'Y', 'Z', ---, ---, ---, ---, ---
- true, true, true, false, false, false, false, false,
+ true, true, true, false, false, false, false, false,
// ---, 'a', 'b', 'c', 'd', 'e', 'f', 'g'
- false, true, true, true, true, true, true, true,
+ false, true, true, true, true, true, true, true,
// 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o'
- true, true, true, true, true, true, true, true,
+ true, true, true, true, true, true, true, true,
// 'p', 'q', 'r', 's', 't', 'u', 'v', 'w'
- true, true, true, true, true, true, true, true,
+ true, true, true, true, true, true, true, true,
// 'x', 'y', 'z', ---, ---, ---, ---, ---
- true, true, true, false, false, false, false, false
+ true, true, true, false, false, false, false, false
};
private static final char[] TO_LOWER_CASE =
@@ -210,31 +210,31 @@ public final class Strings
/** The ASCI chars */
private static final byte[] UTF8 = new byte[]
- {
- 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
- 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
- 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
- 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
- 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F,
- 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
- 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
- 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
- 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F,
- 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
- 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F,
- 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
- 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
- 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
- 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F
+ {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
+ 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
+ 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
+ 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F,
+ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
+ 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
+ 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
+ 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F,
+ 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
+ 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F,
+ 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
+ 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
+ 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
+ 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F
};
/** An empty byte array */
public static final byte[] EMPTY_BYTES = new byte[0];
-
+
/** An empty String */
public static final String EMPTY_STRING = "";
-
+
/** An empty String array */
public static final String[] EMPTY_STRING_ARRAY = new String[]{};
@@ -502,7 +502,7 @@ public final class Strings
buf.append( str.substring( 0, head ) ).append( "..." );
buf.append( str.substring( str.length() - tail ) );
buf.append( ']' );
-
+
return buf.toString();
}
@@ -1628,11 +1628,11 @@ public final class Strings
/**
- * When the string to convert to bytes is pure ascii, this is a faster
+ * When the string to convert to bytes is pure ascii, this is a faster
* method than the getBytesUtf8. Otherwise, it's slower.
- *
+ *
* @param string The string to convert to byte[]
- * @return The bytes
+ * @return The bytes
*/
public static byte[] getBytesUtf8Ascii( String string )
{
@@ -1868,7 +1868,7 @@ public final class Strings
* 'a'-'z', 'A'-'Z', '0'-'9', '.' and '-' only.
* <br>
* Deprecated : Use {@link #toLowerCaseAscii(String)}
- *
+ *
* @param value The String to lowercase
* @return The lowercase string
* @deprecated Use {@link #toLowerCaseAscii(String)}
@@ -2192,7 +2192,7 @@ public final class Strings
{
LOG.debug( I18n.msg( I18n.MSG_17007_SYNTAX_VALID, uuid ) );
}
-
+
return true;
}
@@ -2200,7 +2200,7 @@ public final class Strings
{
LOG.debug( I18n.msg( I18n.MSG_17008_SYNTAX_INVALID, uuid ) );
}
-
+
return false;
}
@@ -2391,7 +2391,7 @@ public final class Strings
/**
* Create a new UUID using a long as the least significant bits
- *
+ *
* @param value The least significant bits.
* @return The created UUID
*/
@@ -2399,8 +2399,8 @@ public final class Strings
{
return new UUID( 0, value ).toString();
}
-
-
+
+
/**
* Past an ASCII String to a number
*
@@ -2410,13 +2410,13 @@ public final class Strings
public static int parseInt( String value )
{
long res = 0;
-
+
for ( char c : value.toCharArray() )
{
if ( ( c >= '0' ) && ( c <= '9' ) )
{
res = res * 10 + ( c - '0' );
-
+
if ( res > Integer.MAX_VALUE )
{
throw new NumberFormatException( I18n.err( I18n.ERR_17002_INTEGER_TOO_BIG, value ) );
@@ -2427,11 +2427,11 @@ public final class Strings
throw new NumberFormatException( I18n.err( I18n.ERR_17003_INTEGER_INVALID, value ) );
}
}
-
+
return ( int ) res;
}
-
-
+
+
/**
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
* @param b1 The first byte[] to compare
@@ -2492,7 +2492,7 @@ public final class Strings
}
}
- // b2 is longer w/ b1 as prefix
+ // b2 is longer w/ b1 as prefix
if ( b1.length == minLength )
{
return -1;