use of org.apache.directory.api.ldap.codec.decorators.ModifyRequestDecorator in project directory-ldap-api by apache.
the class ModifyRequestTest method testDecodeModifyRequestWrongOperation.
/**
* Test the decoding of a ModifyRequest with an wrong operation
*/
@Test
public void testDecodeModifyRequestWrongOperation() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x30);
stream.put(new byte[] { 0x30, // LdapMessage
0x2E, 0x02, 0x01, // Message ID : 49
0x31, 0x66, // ModifyRequest
0x29, 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', 0x30, 0x05, 0x30, 0x03, 0x0A, 0x01, 0x04 });
stream.flip();
// Allocate a LdapMessage Container
LdapMessageContainer<ModifyRequestDecorator> ldapMessageContainer = new LdapMessageContainer<ModifyRequestDecorator>(codec);
// Decode a ModifyRequest PDU
try {
ldapDecoder.decode(stream, ldapMessageContainer);
fail("We should never reach this point !!!");
} catch (DecoderException de) {
assertTrue(true);
}
}
use of org.apache.directory.api.ldap.codec.decorators.ModifyRequestDecorator in project directory-ldap-api by apache.
the class ModifyRequestTest method testDecodeModifyRequestAddOperationModificationType2Vals.
/**
* Test the decoding of a ModifyRequest with an add operation, and a
* modification with a type and two vals
*/
@Test
public void testDecodeModifyRequestAddOperationModificationType2Vals() throws LdapException {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x3D);
stream.put(new byte[] { 0x30, // LdapMessage
0x3B, 0x02, 0x01, // Message ID : 49
0x31, 0x66, // ModifyRequest
0x36, 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', 0x30, 0x12, 0x30, 0x10, 0x0A, 0x01, 0x00, 0x30, 0x0B, 0x04, 0x01, 'l', 0x31, 0x06, 0x04, 0x01, 'a', 0x04, 0x01, 'b' });
String decodedPdu = Strings.dumpBytes(stream.array());
stream.flip();
// Allocate a LdapMessage Container
LdapMessageContainer<ModifyRequestDecorator> ldapMessageContainer = new LdapMessageContainer<ModifyRequestDecorator>(codec);
// Decode a ModifyRequest PDU
try {
ldapDecoder.decode(stream, ldapMessageContainer);
} catch (DecoderException de) {
de.printStackTrace();
fail(de.getMessage());
}
// Check the decoded PDU
ModifyRequest modifyRequest = ldapMessageContainer.getMessage();
assertEquals(49, modifyRequest.getMessageId());
assertEquals("cn=testModify,ou=users,ou=system", modifyRequest.getName().toString());
Object[] modifications = modifyRequest.getModifications().toArray();
assertEquals(1, modifications.length);
Modification modification = (Modification) modifications[0];
Attribute attributeValue = modification.getAttribute();
assertEquals("l", Strings.toLowerCaseAscii(attributeValue.getUpId()));
assertEquals(2, attributeValue.size());
assertTrue(attributeValue.contains("a"));
assertTrue(attributeValue.contains("b"));
// Check the encoding
try {
ByteBuffer bb = encoder.encodeMessage(modifyRequest);
// Check the length
assertEquals(0x3D, 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.decorators.ModifyRequestDecorator in project directory-ldap-api by apache.
the class ModifyRequestTest method testDecodeModifyRequestAddOperationEmptyModification.
/**
* Test the decoding of a ModifyRequest with an add operation, and an empty
* modification
*/
@Test
public void testDecodeModifyRequestAddOperationEmptyModification() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x32);
stream.put(new byte[] { 0x30, // LdapMessage
0x30, 0x02, 0x01, // Message ID : 49
0x31, 0x66, // ModifyRequest
0x2B, 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', 0x30, 0x07, 0x30, 0x05, 0x0A, 0x01, 0x00, 0x30, 0x00 });
stream.flip();
// Allocate a LdapMessage Container
LdapMessageContainer<ModifyRequestDecorator> ldapMessageContainer = new LdapMessageContainer<ModifyRequestDecorator>(codec);
// Decode a ModifyRequest PDU
try {
ldapDecoder.decode(stream, ldapMessageContainer);
fail("We should never reach this point !!!");
} catch (DecoderException de) {
assertTrue(true);
}
}
use of org.apache.directory.api.ldap.codec.decorators.ModifyRequestDecorator in project directory-ldap-api by apache.
the class ModifyRequestTest method testDecodeModifyRequestObjectAlone.
/**
* Test the decoding of a ModifyRequest with an object and nothing else
*/
@Test
public void testDecodeModifyRequestObjectAlone() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x29);
stream.put(new byte[] { 0x30, // LdapMessage
0x27, 0x02, 0x01, // Message ID : 49
0x31, 0x66, // ModifyRequest
0x22, 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' });
stream.flip();
// Allocate a LdapMessage Container
LdapMessageContainer<ModifyRequestDecorator> ldapMessageContainer = new LdapMessageContainer<ModifyRequestDecorator>(codec);
// Decode a ModifyRequest PDU
try {
ldapDecoder.decode(stream, ldapMessageContainer);
fail("We should never reach this point !!!");
} catch (DecoderException de) {
assertTrue(true);
}
}
use of org.apache.directory.api.ldap.codec.decorators.ModifyRequestDecorator in project directory-ldap-api by apache.
the class ModifyRequestTest method testDecodeModifyRequestAddOperationEnd.
/**
* Test the decoding of a ModifyRequest with an add operation, and nothing
* more
*/
@Test
public void testDecodeModifyRequestAddOperationEnd() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x30);
stream.put(new byte[] { 0x30, // LdapMessage
0x2E, 0x02, 0x01, // Message ID : 49
0x31, 0x66, // ModifyRequest
0x29, 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', 0x30, 0x05, 0x30, 0x03, 0x0A, 0x01, 0x00 });
stream.flip();
// Allocate a LdapMessage Container
LdapMessageContainer<ModifyRequestDecorator> ldapMessageContainer = new LdapMessageContainer<ModifyRequestDecorator>(codec);
// Decode a ModifyRequest PDU
try {
ldapDecoder.decode(stream, ldapMessageContainer);
fail("We should never reach this point !!!");
} catch (DecoderException de) {
assertTrue(true);
}
}
Aggregations