use of org.apache.directory.api.asn1.util.Oid in project directory-ldap-api by apache.
the class SearchRequestTest method testDecodeSearchRequestSubEntryControl.
/**
* Test the decoding of a SearchRequest with SubEntry control.
*/
@Test
public void testDecodeSearchRequestSubEntryControl() {
byte[] asn1BER = new byte[] { 0x30, 0x5D, 0x02, 0x01, // messageID
0x04, 0x63, 0x33, 0x04, // baseObject: dc=my-domain,dc=com
0x13, 'd', 'c', '=', 'm', 'y', '-', 'd', 'o', 'm', 'a', 'i', 'n', ',', 'd', 'c', '=', 'c', 'o', 'm', 0x0a, 0x01, // scope: subtree
0x02, 0x0a, 0x01, // derefAliases: derefAlways
0x03, 0x02, 0x01, // sizeLimit: 0
0x00, 0x02, 0x01, // timeLimit: 0
0x00, 0x01, 0x01, // typesOnly: false
0x00, (byte) 0x87, // filter: (objectClass=*)
0x0b, 'o', 'b', 'j', 'e', 'c', 't', 'C', 'l', 'a', 's', 's', 0x30, 0x00, (byte) 0xa0, // controls
0x23, 0x30, 0x21, 0x04, 0x17, '1', '.', '3', '.', '6', '.', '1', '.', '4', '.', '1', '.', '4', '2', '0', '3', '.', '1', '.', '1', '0', '.', // SubEntry OID
'1', 0x01, 0x01, // criticality: true
(byte) 0xFF, 0x04, 0x03, 0x01, 0x01, // SubEntry visibility
(byte) 0xFF };
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(asn1BER.length);
stream.put(asn1BER);
String decodedPdu = Strings.dumpBytes(stream.array());
stream.flip();
LdapMessageContainer<SearchRequestDecorator> ldapMessageContainer = new LdapMessageContainer<SearchRequestDecorator>(codec);
try {
ldapDecoder.decode(stream, ldapMessageContainer);
} catch (DecoderException de) {
de.printStackTrace();
fail(de.getMessage());
}
assertEquals(TLVStateEnum.PDU_DECODED, ldapMessageContainer.getState());
SearchRequest searchRequest = ldapMessageContainer.getMessage();
assertEquals(4, searchRequest.getMessageId());
assertEquals(1, searchRequest.getControls().size());
// SubEntry Control
String subEntryControlOID = "1.3.6.1.4.1.4203.1.10.1";
Control subEntryControl = searchRequest.getControl(subEntryControlOID);
assertEquals(subEntryControlOID, subEntryControl.getOid());
assertTrue(subEntryControl.isCritical());
assertTrue(subEntryControl instanceof SubentriesDecorator);
assertTrue(((SubentriesDecorator) subEntryControl).getDecorated().isVisible());
assertEquals("dc=my-domain,dc=com", searchRequest.getBase().toString());
assertEquals(SearchScope.SUBTREE, searchRequest.getScope());
assertEquals(AliasDerefMode.DEREF_ALWAYS, searchRequest.getDerefAliases());
assertEquals(0, searchRequest.getSizeLimit());
assertEquals(0, searchRequest.getTimeLimit());
assertEquals(false, searchRequest.getTypesOnly());
ExprNode filter = searchRequest.getFilter();
assertTrue(filter instanceof PresenceNode);
assertEquals("objectClass", ((PresenceNode) filter).getAttribute());
// Check the encoding
try {
ByteBuffer bb = encoder.encodeMessage(searchRequest);
// Check the length
assertEquals(0x5F, bb.limit());
String encodedPdu = Strings.dumpBytes(bb.array());
assertEquals(decodedPdu, encodedPdu);
} catch (EncoderException ee) {
ee.printStackTrace();
fail(ee.getMessage());
}
}
use of org.apache.directory.api.asn1.util.Oid in project directory-ldap-api by apache.
the class IntermediateResponseTest method testDecodeEmptyOID.
/**
* Test the decoding of an empty OID
*/
@Test
public void testDecodeEmptyOID() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x09);
stream.put(new byte[] { // LDAPMessage ::= SEQUENCE {
0x30, // LDAPMessage ::= SEQUENCE {
0x07, 0x02, 0x01, // messageID MessageID
0x01, // CHOICE { ..., intermediateResponse IntermediateResponse, ...
0x79, // IntermediateResponse ::= [APPLICATION 25] SEQUENCE {
0x02, (byte) 0x80, 0x00 });
stream.flip();
// Allocate a LdapMessage Container
LdapMessageContainer<IntermediateResponseDecorator<?>> ldapMessageContainer = new LdapMessageContainer<IntermediateResponseDecorator<?>>(codec);
// Decode a IntermediateResponse PDU
try {
ldapDecoder.decode(stream, ldapMessageContainer);
fail("We should never reach this point !!!");
} catch (DecoderException de) {
assertTrue(true);
}
}
Aggregations