use of com.mindbright.asn1.ASN1OctetString in project ldapsdk by pingidentity.
the class IntermediateResponseProtocolOpTestCase method testDecodeInvalidElementType.
/**
* Tests the behavior when trying to decode an intermediate response with an
* invalid element type.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test(expectedExceptions = { LDAPException.class })
public void testDecodeInvalidElementType() throws Exception {
final ASN1Sequence s = new ASN1Sequence(LDAPMessage.PROTOCOL_OP_TYPE_INTERMEDIATE_RESPONSE, new ASN1OctetString((byte) 0x79));
IntermediateResponseProtocolOp.decodeProtocolOp(s);
}
use of com.mindbright.asn1.ASN1OctetString in project ldapsdk by pingidentity.
the class LDAPMessageTestCase method testIntermediateResponseMessage.
/**
* Tests the behavior of the {@code LDAPMessage} class with an intermediate
* response protocol op.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testIntermediateResponseMessage() throws Exception {
LinkedList<Control> controls = new LinkedList<Control>();
controls.add(new Control("1.2.3.4"));
controls.add(new Control("1.2.3.5", true, new ASN1OctetString()));
IntermediateResponseProtocolOp op = new IntermediateResponseProtocolOp("1.2.3.4", new ASN1OctetString());
LDAPMessage m = new LDAPMessage(1, op, controls);
ASN1Buffer b = new ASN1Buffer();
m.writeTo(b);
ByteArrayInputStream inputStream = new ByteArrayInputStream(b.toByteArray());
ASN1StreamReader reader = new ASN1StreamReader(inputStream);
m = LDAPMessage.readFrom(reader, true);
m = LDAPMessage.decode(m.encode());
assertEquals(m.getMessageID(), 1);
assertNotNull(m.getProtocolOp());
assertTrue(m.getProtocolOp() instanceof IntermediateResponseProtocolOp);
assertEquals(m.getProtocolOpType(), LDAPMessage.PROTOCOL_OP_TYPE_INTERMEDIATE_RESPONSE);
assertNotNull(m.getControls());
assertFalse(m.getControls().isEmpty());
assertNotNull(m.getIntermediateResponseProtocolOp());
inputStream = new ByteArrayInputStream(b.toByteArray());
reader = new ASN1StreamReader(inputStream);
LDAPResponse r = LDAPMessage.readLDAPResponseFrom(reader, true);
assertNotNull(m.toString());
}
use of com.mindbright.asn1.ASN1OctetString in project ldapsdk by pingidentity.
the class AttributeTestCase method testConstructorWithNameSchemaAndOctetStringArrayValues.
/**
* Tests the constructor which takes a name, a {@code Schema} object, and an
* array of octet string values.
* <BR><BR>
* Access to a Directory Server instance is required for complete processing.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testConstructorWithNameSchemaAndOctetStringArrayValues() throws Exception {
if (!isDirectoryInstanceAvailable()) {
return;
}
// First, test with a null schema and verify that the case-ignore rule is
// selected for any attribute.
ASN1OctetString[] cnValues = { new ASN1OctetString("foo"), new ASN1OctetString("bar") };
Attribute cnAttr = new Attribute("cn", (Schema) null, cnValues);
assertNotNull(cnAttr);
assertNotNull(cnAttr.getName());
assertEquals(cnAttr.getName(), "cn");
assertNotNull(cnAttr.getMatchingRule());
assertEquals(cnAttr.getMatchingRule(), CaseIgnoreStringMatchingRule.getInstance());
assertTrue(cnAttr.hasValue("foo"));
ASN1OctetString[] memberValues = { new ASN1OctetString("uid=test.user,ou=People,dc=example,dc=com") };
Attribute memberAttr = new Attribute("member", (Schema) null, memberValues);
assertNotNull(memberAttr);
assertNotNull(memberAttr.getName());
assertEquals(memberAttr.getName(), "member");
assertNotNull(memberAttr.getMatchingRule());
assertEquals(memberAttr.getMatchingRule(), CaseIgnoreStringMatchingRule.getInstance());
assertFalse(memberAttr.hasValue("uid = test.user, ou=People, dc=example, dc=com"));
// Next, test with a non-null schema and verify that the case-ignore rule is
// selected for the cn attribute and .
cnAttr = new Attribute("cn", schema, cnValues);
assertNotNull(cnAttr);
assertNotNull(cnAttr.getName());
assertEquals(cnAttr.getName(), "cn");
assertNotNull(cnAttr.getMatchingRule());
assertEquals(cnAttr.getMatchingRule(), CaseIgnoreStringMatchingRule.getInstance());
assertTrue(cnAttr.hasValue("foo"));
memberAttr = new Attribute("member", schema, memberValues);
assertNotNull(memberAttr);
assertNotNull(memberAttr.getName());
assertEquals(memberAttr.getName(), "member");
assertNotNull(memberAttr.getMatchingRule());
assertEquals(memberAttr.getMatchingRule(), DistinguishedNameMatchingRule.getInstance());
assertTrue(memberAttr.hasValue("uid = test.user, ou=People, dc=example, dc=com"));
}
use of com.mindbright.asn1.ASN1OctetString in project ldapsdk by pingidentity.
the class BooleanMatchingRuleTestCase method testInvalidValues.
/**
* Performs a number of tests with invalid values.
*
* @param value The value to test.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test(dataProvider = "invalidValues", expectedExceptions = { LDAPException.class })
public void testInvalidValues(String value) throws Exception {
BooleanMatchingRule mr = BooleanMatchingRule.getInstance();
mr.normalize(new ASN1OctetString(value));
}
use of com.mindbright.asn1.ASN1OctetString in project ldapsdk by pingidentity.
the class BooleanMatchingRuleTestCase method testNormalizeSubstring.
/**
* Ensures that attempts to perform substring normalization will fail.
*
* @param value The value to test.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test(dataProvider = "trueValues", expectedExceptions = { LDAPException.class })
public void testNormalizeSubstring(String value) throws Exception {
BooleanMatchingRule mr = BooleanMatchingRule.getInstance();
mr.normalizeSubstring(new ASN1OctetString(value), (byte) 0x80);
}
Aggregations