use of org.apache.directory.api.ldap.codec.api.ResponseCarryingException in project directory-ldap-api by apache.
the class SearchRequestTest method testDecodeSearchRequestGlobalBadObjectBase.
/**
* Test the decoding of a SearchRequest with a bad objectBase
*/
@Test
public void testDecodeSearchRequestGlobalBadObjectBase() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x90);
stream.put(new byte[] { 0x30, (byte) 0x81, // LDAPMessage ::=SEQUENCE {
(byte) 0x8D, 0x02, 0x01, // messageID MessageID
0x01, 0x63, (byte) 0x81, // CHOICE { ...,
(byte) 0x87, // SearchRequest ::= APPLICATION[3] SEQUENCE {
0x04, // baseObject LDAPDN,
0x1F, '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', 0x0A, 0x01, // scope ENUMERATED {
0x01, // wholeSubtree (2) },
0x0A, 0x01, // derefAliases ENUMERATED {
0x03, // derefAlways (3) },
0x02, 0x02, 0x03, // sizeLimit INTEGER (0 .. maxInt), (1000)
(byte) 0xE8, 0x02, 0x02, 0x03, // timeLimit INTEGER (0 .. maxInt), (1000)
(byte) 0xE8, 0x01, 0x01, // typesOnly BOOLEAN, (TRUE)
(byte) 0xFF, // filter Filter,
(byte) 0xA0, // Filter ::= CHOICE {
0x3C, // and [0] SET OF Filter,
(byte) 0xA1, // or [1] SET of Filter,
0x24, (byte) 0xA3, // equalityMatch [3]
0x12, // attributeDesc AttributeDescription (LDAPString),
0x04, 0x0B, 'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's', // assertionValue AssertionValue (OCTET STRING) }
0x04, 0x03, 't', 'o', 'p', (byte) 0xA3, // equalityMatch [3] Assertion,
0x0E, // Assertion ::= SEQUENCE {
0x04, 0x02, 'o', // attributeDesc AttributeDescription (LDAPString),
'u', // assertionValue AssertionValue (OCTET STRING) }
0x04, 0x08, 'c', 'o', 'n', 't', 'a', 'c', 't', 's', (byte) 0xA2, // not [2] Filter,
0x14, (byte) 0xA3, // equalityMatch [3] Assertion,
0x12, // attributeDesc AttributeDescription (LDAPString),
0x04, 0x0B, 'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's', // assertionValue AssertionValue (OCTET STRING) }
0x04, 0x03, 't', 't', 't', // attributes AttributeDescriptionList }
0x30, // AttributeDescriptionList ::= SEQUENCE OF
0x15, // AttributeDescription
0x04, 0x05, 'a', 't', 't', 'r', // AttributeDescription ::= LDAPString
'0', 0x04, 0x05, 'a', 't', 't', 'r', // AttributeDescription ::= LDAPString
'1', 0x04, 0x05, 'a', 't', 't', 'r', // AttributeDescription ::= LDAPString
'2' });
stream.flip();
// Allocate a LdapMessage Container
LdapMessageContainer<SearchRequestDecorator> ldapMessageContainer = new LdapMessageContainer<SearchRequestDecorator>(codec);
try {
ldapDecoder.decode(stream, ldapMessageContainer);
} catch (DecoderException de) {
assertTrue(de instanceof ResponseCarryingException);
Message response = ((ResponseCarryingException) de).getResponse();
assertTrue(response instanceof SearchResultDoneImpl);
assertEquals(ResultCodeEnum.INVALID_DN_SYNTAX, ((SearchResultDoneImpl) response).getLdapResult().getResultCode());
return;
}
fail("We should not reach this point");
}
use of org.apache.directory.api.ldap.codec.api.ResponseCarryingException in project directory-ldap-api by apache.
the class AddRequestTest method testDecodeAddRequestNullType.
/**
* Test the decoding of a AddRequest with a empty attributeList
*/
@Test
public void testDecodeAddRequestNullType() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x2F);
stream.put(new byte[] { 0x30, // LDAPMessage ::= SEQUENCE {
0x2D, 0x02, 0x01, // messageID MessageID
0x01, 0x68, // CHOICE { ..., addRequest AddRequest, ...
0x28, // 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', // attributes AttributeList }
0x30, // AttributeList ::= SEQUENCE OF SEQUENCE {
0x04, 0x30, // attribute 1
0x02, 0x04, // type AttributeDescription,
0x00 });
stream.flip();
// Allocate a LdapMessage Container
Asn1Container ldapMessageContainer = new LdapMessageContainer<MessageDecorator<? extends Message>>(codec);
// Decode a AddRequest message
try {
ldapDecoder.decode(stream, ldapMessageContainer);
} catch (DecoderException de) {
assertTrue(de instanceof ResponseCarryingException);
Message response = ((ResponseCarryingException) de).getResponse();
assertTrue(response instanceof AddResponseImpl);
assertEquals(ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, ((AddResponseImpl) response).getLdapResult().getResultCode());
return;
}
fail("We should not reach this point");
}
use of org.apache.directory.api.ldap.codec.api.ResponseCarryingException in project directory-ldap-api by apache.
the class BindRequestTest method testDecodeBindRequestBadDN.
/**
* Test the decoding of a BindRequest with Simple authentication and
* controls
*/
@Test
public void testDecodeBindRequestBadDN() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x35);
stream.put(new byte[] { 0x30, // LDAPMessage ::=SEQUENCE {
0x33, 0x02, 0x01, // messageID MessageID
0x01, 0x60, // CHOICE { ..., bindRequest BindRequest, ...
0x2E, // BindRequest ::= APPLICATION[0] SEQUENCE {
0x02, 0x01, // version INTEGER (1..127),
0x03, 0x04, // name LDAPDN,
0x1F, '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, // authentication AuthenticationChoice
0x08, // ...
'p', 'a', 's', 's', 'w', 'o', 'r', 'd' });
stream.flip();
// Allocate a LdapMessage Container
LdapMessageContainer<MessageDecorator<? extends Message>> container = new LdapMessageContainer<MessageDecorator<? extends Message>>(codec);
// Decode the BindRequest PDU
try {
ldapDecoder.decode(stream, container);
BindRequest bindRequest = ((BindRequestDecorator) container.getMessage());
assertNull(bindRequest.getDn());
assertEquals("uid:akarasulu,dc=example,dc=com", bindRequest.getName());
} catch (DecoderException de) {
assertTrue(de instanceof ResponseCarryingException);
Message response = ((ResponseCarryingException) de).getResponse();
assertTrue(response instanceof BindResponseImpl);
assertEquals(ResultCodeEnum.INVALID_DN_SYNTAX, ((BindResponseImpl) response).getLdapResult().getResultCode());
return;
}
}
use of org.apache.directory.api.ldap.codec.api.ResponseCarryingException in project directory-ldap-api by apache.
the class BindRequestTest method testDecodeBindRequestEmptySasl.
/**
* Test the decoding of a BindRequest with an empty sasl
*/
@Test
public void testDecodeBindRequestEmptySasl() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x0E);
stream.put(new byte[] { // LDAPMessage ::=SEQUENCE {
0x30, // LDAPMessage ::=SEQUENCE {
0x0C, 0x02, 0x01, // messageID MessageID
0x01, 0x60, // CHOICE { ..., bindRequest BindRequest, ...
0x07, 0x02, 0x01, // version INTEGER (1..127),
0x03, 0x04, 0x00, (byte) 0xA3, 0x00 });
stream.flip();
// Allocate a LdapMessage Container
LdapMessageContainer<BindRequestDecorator> container = new LdapMessageContainer<BindRequestDecorator>(codec);
// Decode a BindRequest message
try {
ldapDecoder.decode(stream, container);
} catch (DecoderException de) {
assertTrue(de instanceof ResponseCarryingException);
Message response = ((ResponseCarryingException) de).getResponse();
assertTrue(response instanceof BindResponseImpl);
assertEquals(ResultCodeEnum.INVALID_CREDENTIALS, ((BindResponseImpl) response).getLdapResult().getResultCode());
return;
}
fail("We should not reach this point");
}
use of org.apache.directory.api.ldap.codec.api.ResponseCarryingException in project directory-ldap-api by apache.
the class CompareRequestTest method testDecodeCompareRequestInvalidDN.
/**
* Test the decoding of an empty ava
*/
@Test
public void testDecodeCompareRequestInvalidDN() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x2B);
stream.put(new byte[] { 0x30, // LDAPMessage ::= SEQUENCE {
0x29, 0x02, 0x01, // messageID MessageID
0x01, // CHOICE { ..., compareRequest CompareRequest, ...
0x6E, // CompareRequest ::= [APPLICATION 14] SEQUENCE {
0x24, // 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, // AttributeValueAssertion ::= SEQUENCE {
0x00 });
stream.flip();
// Allocate a LdapMessage Container
LdapMessageContainer<CompareRequestDecorator> container = new LdapMessageContainer<CompareRequestDecorator>(codec);
// Decode the CompareRequest PDU
try {
ldapDecoder.decode(stream, container);
fail("We should never reach this point !!!");
} catch (DecoderException de) {
assertTrue(de instanceof ResponseCarryingException);
Message response = ((ResponseCarryingException) de).getResponse();
assertTrue(response instanceof CompareResponseImpl);
assertEquals(ResultCodeEnum.INVALID_DN_SYNTAX, ((CompareResponseImpl) response).getLdapResult().getResultCode());
return;
}
}
Aggregations