use of org.apache.directory.api.ldap.codec.api.LdapMessageContainer in project directory-ldap-api by apache.
the class LdapResultTest method testDecodeAddResponseEmptyResultCodeOKReferral.
/**
* Test the decoding of a AddResponse with a valid LdapResult with referral
*/
@Test
public void testDecodeAddResponseEmptyResultCodeOKReferral() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x1A);
stream.put(new byte[] { // LDAPMessage ::=SEQUENCE {
0x30, // LDAPMessage ::=SEQUENCE {
0x18, 0x02, 0x01, // messageID MessageID
0x01, 0x69, // CHOICE { ..., addResponse AddResponse, ...
0x13, 0x0A, 0x01, // resultCode success (Referral)
0x0A, 0x04, // Empty matched Dn
0x00, 0x04, // Empty errorMessage
0x00, (byte) 0xA3, 0x0A, 0x04, 0x08, 'l', 'd', 'a', 'p', ':', '/', '/', '/' });
String decodedPdu = Strings.dumpBytes(stream.array());
stream.flip();
// Allocate a LdapMessage Container
LdapMessageContainer<AddResponseDecorator> container = new LdapMessageContainer<AddResponseDecorator>(codec);
// Decode the AddResponse PDU
try {
ldapDecoder.decode(stream, container);
} catch (DecoderException de) {
de.printStackTrace();
fail(de.getMessage());
}
// Check the decoded AddResponse
AddResponse addResponse = container.getMessage();
assertEquals(1, addResponse.getMessageId());
assertEquals(ResultCodeEnum.REFERRAL, addResponse.getLdapResult().getResultCode());
assertEquals("", addResponse.getLdapResult().getMatchedDn().getName());
assertEquals("", addResponse.getLdapResult().getDiagnosticMessage());
Referral referral = addResponse.getLdapResult().getReferral();
assertNotNull(referral);
assertEquals(1, referral.getLdapUrls().size());
Collection<String> ldapUrls = referral.getLdapUrls();
assertTrue(ldapUrls.contains("ldap:///"));
try {
ByteBuffer bb = encoder.encodeMessage(addResponse);
// Check the length
assertEquals(0x1A, bb.limit());
String encodedPdu = Strings.dumpBytes(bb.array());
assertEquals(encodedPdu, decodedPdu);
} catch (EncoderException ee) {
ee.printStackTrace();
fail(ee.getMessage());
}
}
use of org.apache.directory.api.ldap.codec.api.LdapMessageContainer in project directory-ldap-api by apache.
the class LdapResultTest method testDecodeAddResponseEmptyResultCodeAbove90.
/**
* Test the decoding of a AddResponse with no LdapResult
*/
@Test
public void testDecodeAddResponseEmptyResultCodeAbove90() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x10);
stream.put(new byte[] { // LDAPMessage ::=SEQUENCE {
0x30, // LDAPMessage ::=SEQUENCE {
0x0E, 0x02, 0x01, // messageID MessageID
0x01, 0x69, // CHOICE { ..., addResponse AddResponse, ...
0x02, 0x0A, 0x03, 0x01, // resultCode too high
0x01 });
stream.flip();
// Allocate a LdapMessage Container
Asn1Container ldapMessageContainer = new LdapMessageContainer<MessageDecorator<? extends Message>>(codec);
// Decode a AddResponse message
try {
ldapDecoder.decode(stream, ldapMessageContainer);
} catch (DecoderException de) {
assertTrue(true);
return;
}
fail("We should not reach this point");
}
use of org.apache.directory.api.ldap.codec.api.LdapMessageContainer in project directory-ldap-api by apache.
the class AbandonRequestTest method testDecodeAbandonRequestNoControlsHighMessageId.
/**
* Test the decoding of a AbandonRequest with no controls
*/
@Test
public void testDecodeAbandonRequestNoControlsHighMessageId() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x0A);
stream.put(new byte[] { // LDAPMessage ::=SEQUENCE {
0x30, // LDAPMessage ::=SEQUENCE {
0x08, // messageID MessageID
0x02, 0x03, 0x00, (byte) 0x80, 0x13, 0x50, 0x01, // CHOICE { ..., abandonRequest
0x02 // AbandonRequest,...
// AbandonRequest ::= [APPLICATION 16] MessageID
});
String decodedPdu = Strings.dumpBytes(stream.array());
stream.flip();
// Allocate a LdapMessageContainer Container
LdapMessageContainer<AbandonRequestDecorator> ldapMessageContainer = new LdapMessageContainer<AbandonRequestDecorator>(codec);
// Decode the PDU
try {
ldapDecoder.decode(stream, ldapMessageContainer);
} catch (DecoderException de) {
de.printStackTrace();
fail(de.getMessage());
}
// Check that everything is OK
AbandonRequest abandonRequest = ldapMessageContainer.getMessage();
assertEquals(32787, abandonRequest.getMessageId());
assertEquals(2, abandonRequest.getAbandoned());
// Check the length
AbandonRequest internalAbandonRequest = new AbandonRequestImpl(abandonRequest.getAbandoned());
internalAbandonRequest.setMessageId(abandonRequest.getMessageId());
// Check the encoding
try {
ByteBuffer bb = encoder.encodeMessage(internalAbandonRequest);
// Check the length
assertEquals(0x0A, bb.limit());
String encodedPdu = Strings.dumpBytes(bb.array());
assertEquals(encodedPdu, decodedPdu);
} catch (EncoderException ee) {
ee.printStackTrace();
fail(ee.getMessage());
}
}
use of org.apache.directory.api.ldap.codec.api.LdapMessageContainer in project directory-ldap-api by apache.
the class AbandonRequestTest method testDecodeAbandonRequestNoMessageId.
/**
* Test the decoding of a AbandonRequest with a null messageId
*/
@Test
public void testDecodeAbandonRequestNoMessageId() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x0A);
stream.put(new byte[] { // LDAPMessage ::=SEQUENCE {
0x30, // LDAPMessage ::=SEQUENCE {
0x08, 0x02, 0x01, // messageID MessageID
0x01, 0x50, // CHOICE { ..., abandonRequest AbandonRequest,...
0x00 // AbandonRequest ::= [APPLICATION 16] MessageID
});
stream.flip();
// Allocate a LdapMessageContainer Container
LdapMessageContainer<MessageDecorator<? extends Message>> ldapMessageContainer = new LdapMessageContainer<MessageDecorator<? extends Message>>(codec);
// Decode the PDU
try {
ldapDecoder.decode(stream, ldapMessageContainer);
} catch (DecoderException de) {
assertTrue(true);
return;
}
fail("We should not reach this point");
}
use of org.apache.directory.api.ldap.codec.api.LdapMessageContainer in project directory-ldap-api by apache.
the class AbandonRequestTest method testDecodeAbandonRequestBadMessageId.
/**
* Test the decoding of a AbandonRequest with a bad Message Id
*/
@Test
public void testDecodeAbandonRequestBadMessageId() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x0B);
stream.put(new byte[] { // LDAPMessage ::=SEQUENCE {
0x30, // LDAPMessage ::=SEQUENCE {
0x09, 0x02, 0x01, // messageID MessageID
0x01, 0x50, 0x01, // CHOICE { ..., abandonRequest AbandonRequest,...
(byte) 0xFF // AbandonRequest ::= [APPLICATION 16] MessageID
});
stream.flip();
// Allocate a LdapMessageContainer Container
LdapMessageContainer<MessageDecorator<? extends Message>> ldapMessageContainer = new LdapMessageContainer<MessageDecorator<? extends Message>>(codec);
// Decode the PDU
try {
ldapDecoder.decode(stream, ldapMessageContainer);
} catch (DecoderException de) {
assertTrue(true);
return;
}
fail("We should not reach this point");
}
Aggregations