use of org.apache.directory.api.asn1.DecoderException in project directory-ldap-api by apache.
the class SearchResultEntryTest method testDecodeSearchResultEntryEmptyAttributes.
/**
* Test the decoding of an SearchResultEntry with an empty attributes
*/
@Test
public void testDecodeSearchResultEntryEmptyAttributes() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x26);
stream.put(new byte[] { 0x30, // LDAPMessage ::=SEQUENCE {
0x24, 0x02, 0x01, // messageID MessageID
0x01, 0x64, // CHOICE { ..., searchResEntry SearchResultEntry,
0x1F, // objectName LDAPDN,
0x04, 0x1B, 'o', 'u', '=', 'c', 'o', 'n', 't', 'a', 'c', 't', 's', ',', 'd', 'c', '=', 'i', 'k', 't', 'e', 'k', ',', 'd', 'c', '=', 'c', 'o', 'm', // PartialAttributeList ::= SEQUENCE OF SEQUENCE {
0x30, 0x00 });
String decodedPdu = Strings.dumpBytes(stream.array());
stream.flip();
// Allocate a BindRequest Container
LdapMessageContainer<SearchResultEntryDecorator> ldapMessageContainer = new LdapMessageContainer<SearchResultEntryDecorator>(codec);
try {
ldapDecoder.decode(stream, ldapMessageContainer);
} catch (DecoderException de) {
de.printStackTrace();
fail(de.getMessage());
}
SearchResultEntry searchResultEntry = ldapMessageContainer.getMessage();
assertEquals(1, searchResultEntry.getMessageId());
assertEquals("ou=contacts,dc=iktek,dc=com", searchResultEntry.getObjectName().toString());
Entry entry = searchResultEntry.getEntry();
assertEquals(0, entry.size());
// Check the encoding
try {
ByteBuffer bb = encoder.encodeMessage(searchResultEntry);
// Check the length
assertEquals(0x26, 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.asn1.DecoderException in project directory-ldap-api by apache.
the class SearchResultEntryTest method testDecodeSearchResultEntryEmptyAttributeList.
/**
* Test the decoding of an SearchResultEntry with an empty attributes list
*/
@Test
public void testDecodeSearchResultEntryEmptyAttributeList() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x28);
stream.put(new byte[] { 0x30, // LDAPMessage ::=SEQUENCE {
0x26, 0x02, 0x01, // messageID MessageID
0x01, 0x64, // CHOICE { ..., searchResEntry SearchResultEntry,
0x21, // objectName LDAPDN,
0x04, 0x1B, 'o', 'u', '=', 'c', 'o', 'n', 't', 'a', 'c', 't', 's', ',', 'd', 'c', '=', 'i', 'k', 't', 'e', 'k', ',', 'd', 'c', '=', 'c', 'o', 'm', // PartialAttributeList ::= SEQUENCE OF SEQUENCE {
0x30, 0x02, 0x30, 0x00 });
stream.flip();
// Allocate a BindRequest Container
LdapMessageContainer<SearchResultEntryDecorator> ldapMessageContainer = new LdapMessageContainer<SearchResultEntryDecorator>(codec);
try {
ldapDecoder.decode(stream, ldapMessageContainer);
} catch (DecoderException de) {
assertTrue(true);
return;
}
fail("We should not reach this point");
}
use of org.apache.directory.api.asn1.DecoderException in project directory-ldap-api by apache.
the class SearchResultEntryTest method testDecodeSearchResultEntrySuccess.
/**
* Test the decoding of a SearchResultEntry
*/
@Test
public void testDecodeSearchResultEntrySuccess() throws NamingException {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x50);
stream.put(new byte[] { 0x30, // LDAPMessage ::=SEQUENCE {
0x4e, 0x02, 0x01, // messageID MessageID
0x01, 0x64, // CHOICE { ..., searchResEntry SearchResultEntry,
0x49, // objectName LDAPDN,
0x04, 0x1b, 'o', 'u', '=', 'c', 'o', 'n', 't', 'a', 'c', 't', 's', ',', 'd', 'c', '=', 'i', 'k', 't', 'e', 'k', ',', 'd', 'c', '=', 'c', 'o', 'm', // PartialAttributeList ::= SEQUENCE OF SEQUENCE {
0x30, 0x2a, 0x30, 0x28, // type AttributeDescription,
0x04, 0x0b, 'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's', // vals SET OF AttributeValue }
0x31, 0x19, // AttributeValue ::= OCTET STRING
0x04, 0x03, 't', 'o', 'p', // AttributeValue ::= OCTET STRING
0x04, 0x12, 'o', 'r', 'g', 'a', 'n', 'i', 'z', 'a', 't', 'i', 'o', 'n', 'a', 'l', 'U', 'n', 'i', 't' });
String decodedPdu = Strings.dumpBytes(stream.array());
stream.flip();
// Allocate a BindRequest Container
LdapMessageContainer<SearchResultEntryDecorator> ldapMessageContainer = new LdapMessageContainer<SearchResultEntryDecorator>(codec);
try {
ldapDecoder.decode(stream, ldapMessageContainer);
} catch (DecoderException de) {
de.printStackTrace();
fail(de.getMessage());
}
SearchResultEntry searchResultEntry = ldapMessageContainer.getMessage();
assertEquals(1, searchResultEntry.getMessageId());
assertEquals("ou=contacts,dc=iktek,dc=com", searchResultEntry.getObjectName().toString());
Entry entry = searchResultEntry.getEntry();
assertEquals(1, entry.size());
for (int i = 0; i < entry.size(); i++) {
Attribute attribute = entry.get("objectclass");
assertEquals(Strings.toLowerCaseAscii("objectClass"), Strings.toLowerCaseAscii(attribute.getUpId()));
assertTrue(attribute.contains("top"));
assertTrue(attribute.contains("organizationalUnit"));
}
// Check the encoding
try {
ByteBuffer bb = encoder.encodeMessage(searchResultEntry);
// Check the length
assertEquals(0x50, 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.asn1.DecoderException in project directory-ldap-api by apache.
the class SearchResultEntryTest method testDecodeSearchResultEntryEmptyType.
/**
* Test the decoding of a SearchResultEntry with an empty type
*/
@Test
public void testDecodeSearchResultEntryEmptyType() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x2A);
stream.put(new byte[] { 0x30, // LDAPMessage ::=SEQUENCE {
0x28, 0x02, 0x01, // messageID MessageID
0x01, 0x64, // CHOICE { ..., searchResEntry SearchResultEntry,
0x23, // objectName LDAPDN,
0x04, 0x1b, 'o', 'u', '=', 'c', 'o', 'n', 't', 'a', 'c', 't', 's', ',', 'd', 'c', '=', 'i', 'k', 't', 'e', 'k', ',', 'd', 'c', '=', 'c', 'o', 'm', // PartialAttributeList ::= SEQUENCE OF SEQUENCE {
0x30, 0x04, 0x30, 0x02, // type AttributeDescription,
0x04, 0x00 });
stream.flip();
// Allocate a BindRequest Container
LdapMessageContainer<SearchResultEntryDecorator> ldapMessageContainer = new LdapMessageContainer<SearchResultEntryDecorator>(codec);
try {
ldapDecoder.decode(stream, ldapMessageContainer);
} catch (DecoderException de) {
assertTrue(true);
return;
}
fail("We should not reach this point");
}
use of org.apache.directory.api.asn1.DecoderException in project directory-ldap-api by apache.
the class SearchResultReferenceTest method testDecodeSearchResultReferenceSuccess.
/**
* Test the decoding of a SearchResultReference
*/
@Test
public void testDecodeSearchResultReferenceSuccess() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x3d8);
String[] ldapUrls = new String[] { "ldap:///", "ldap://directory.apache.org:80/", "ldap://d-a.org:80/", "ldap://1.2.3.4/", "ldap://1.2.3.4:80/", "ldap://1.1.1.100000.a/", "ldap://directory.apache.org:389/dc=example,dc=org/", "ldap://directory.apache.org:389/dc=example", "ldap://directory.apache.org:389/dc=example%202,dc=org", "ldap://directory.apache.org:389/dc=example,dc=org?ou", "ldap://directory.apache.org:389/dc=example,dc=org?ou,objectclass,dc", "ldap://directory.apache.org:389/dc=example,dc=org?ou,dc,ou", "ldap:///o=University%20of%20Michigan,c=US", "ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US", "ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US?postalAddress", "ldap://host.com:6666/o=University%20of%20Michigan,c=US??sub?(cn=Babs%20Jensen)", "ldap://ldap.itd.umich.edu/c=GB?objectClass?one", "ldap://ldap.question.com/o=Question%3f,c=US?mail", "ldap://ldap.netscape.com/o=Babsco,c=US???(int=%5c00%5c00%5c00%5c04)", "ldap:///??sub??bindname=cn=Manager%2co=Foo", "ldap:///??sub??!bindname=cn=Manager%2co=Foo" };
stream.put(new byte[] { // LDAPMessage
0x30, // LDAPMessage
(byte) 0x82, // LDAPMessage
0x03, // LDAPMessage
(byte) 0xd4, // ::=SEQUENCE {
0x02, 0x01, // messageID MessageID
0x01, 0x73, (byte) 0x82, 0x03, // CHOICE { ...,
(byte) 0xcd // searchResEntry
// SearchResultEntry,
// ...
// SearchResultReference ::= [APPLICATION 19] SEQUENCE OF LDAPURL
});
for (int i = 0; i < ldapUrls.length; i++) {
stream.put((byte) 0x04);
stream.put((byte) Strings.getBytesUtf8(ldapUrls[i]).length);
byte[] bytes = Strings.getBytesUtf8(ldapUrls[i]);
for (int j = 0; j < bytes.length; j++) {
stream.put(bytes[j]);
}
}
String decodedPdu = Strings.dumpBytes(stream.array());
stream.flip();
// Allocate a BindRequest Container
LdapMessageContainer<SearchResultReferenceDecorator> ldapMessageContainer = new LdapMessageContainer<SearchResultReferenceDecorator>(codec);
try {
ldapDecoder.decode(stream, ldapMessageContainer);
} catch (DecoderException de) {
de.printStackTrace();
fail(de.getMessage());
}
SearchResultReference searchResultReference = ldapMessageContainer.getMessage();
assertEquals(1, searchResultReference.getMessageId());
Set<String> ldapUrlsSet = new HashSet<String>();
for (int i = 0; i < ldapUrls.length; i++) {
ldapUrlsSet.add(ldapUrls[i]);
}
Referral referral = searchResultReference.getReferral();
assertNotNull(referral);
for (String ldapUrl : referral.getLdapUrls()) {
if (ldapUrlsSet.contains(ldapUrl)) {
ldapUrlsSet.remove(ldapUrl);
} else {
fail(ldapUrl.toString() + " is not present");
}
}
assertTrue(ldapUrlsSet.size() == 0);
// Check the encoding
try {
ByteBuffer bb = encoder.encodeMessage(searchResultReference);
// Check the length
assertEquals(0x3D8, bb.limit());
String encodedPdu = Strings.dumpBytes(bb.array());
assertEquals(encodedPdu, decodedPdu);
} catch (EncoderException ee) {
ee.printStackTrace();
fail(ee.getMessage());
}
}
Aggregations