use of com.unboundid.ldap.sdk.extensions.WhoAmIExtendedRequest in project ldapsdk by pingidentity.
the class InMemoryDirectoryServerDelayTestCase method testDelayCausesTimeoutSynchronousMode.
/**
* Tests to ensure that processing time which takes too long will cause a
* timeout exception to be thrown when the connection is established in
* synchronous mode.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testDelayCausesTimeoutSynchronousMode() throws Exception {
final InMemoryDirectoryServerConfig cfg = new InMemoryDirectoryServerConfig("dc=example,dc=com");
cfg.addAdditionalBindCredentials("cn=Directory Manager", "password");
final InMemoryDirectoryServer ds = new InMemoryDirectoryServer(cfg);
ds.add(generateDomainEntry("example", "dc=com"));
ds.startListening();
final LDAPConnectionOptions options = new LDAPConnectionOptions();
options.setResponseTimeoutMillis(50L);
options.setUseSynchronousMode(true);
options.setAbandonOnTimeout(true);
final LDAPConnection conn = ds.getConnection(options);
try {
assertEquals(ds.getProcessingDelayMillis(), 0L);
ds.setProcessingDelayMillis(200L);
assertEquals(ds.getProcessingDelayMillis(), 200L);
// Test the bind operation.
assertResultCodeEquals(conn, new SimpleBindRequest("cn=Directory Manager", "password"), ResultCode.TIMEOUT);
// Test the extended operation.
assertResultCodeEquals(conn, new WhoAmIExtendedRequest(), ResultCode.TIMEOUT);
// Test the add operation.
assertResultCodeEquals(conn, new AddRequest(generateOrgUnitEntry("test", "dc=example,dc=com")), ResultCode.TIMEOUT);
// Test the compare operation.
assertResultCodeEquals(conn, new CompareRequest("dc=example,dc=com", "dc", "example"), ResultCode.TIMEOUT);
// Test the modify operation.
assertResultCodeEquals(conn, new ModifyRequest("dn: ou=test,dc=example,dc=com", "changeType: modify", "replace: description", "description: foo"), ResultCode.TIMEOUT);
// Test the modify DN operation.
assertResultCodeEquals(conn, new ModifyDNRequest("ou=test,dc=example,dc=com", "ou=test 2", true), ResultCode.TIMEOUT);
// Test the search operation.
assertResultCodeEquals(conn, new SearchRequest("dc=example,dc=com", SearchScope.BASE, "(objectClass=*)"), ResultCode.TIMEOUT);
// Test the delete operation.
assertResultCodeEquals(conn, new DeleteRequest("ou=test 2,dc=example,dc=com"), ResultCode.TIMEOUT);
} finally {
ds.setProcessingDelayMillis(0L);
assertEquals(ds.getProcessingDelayMillis(), 0L);
conn.close();
ds.shutDown(true);
}
}
use of com.unboundid.ldap.sdk.extensions.WhoAmIExtendedRequest in project ldapsdk by pingidentity.
the class InMemoryDirectoryServerTestCase method testRejectNotAllowedOperationTypes.
/**
* Provides a set of test cases to that operations are properly rejected if
* they are not allowed.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testRejectNotAllowedOperationTypes() throws Exception {
final InMemoryDirectoryServerConfig cfg = new InMemoryDirectoryServerConfig("dc=example,dc=com");
cfg.setAllowedOperationTypes();
cfg.setCodeLogDetails(createTempFile().getAbsolutePath(), true);
final InMemoryDirectoryServer ds = new InMemoryDirectoryServer(cfg);
ds.startListening();
final LDAPConnection conn = ds.getConnection();
try {
conn.add("dn: dc=example,dc=com", "objectClass: top", "objectClass: domain", "dc: example");
} catch (final LDAPException le) {
assertEquals(le.getResultCode(), ResultCode.UNWILLING_TO_PERFORM);
}
ds.add("dn: dc=example,dc=com", "objectClass: top", "objectClass: domain", "dc: example");
ds.add("dn: ou=People,dc=example,dc=com", "objectClass: top", "objectClass: organizationalUnit", "ou: People");
try {
conn.bind("", "");
} catch (final LDAPException le) {
assertEquals(le.getResultCode(), ResultCode.UNWILLING_TO_PERFORM);
}
try {
conn.compare("", "supportedLDAPVersion", "3");
} catch (final LDAPException le) {
assertEquals(le.getResultCode(), ResultCode.UNWILLING_TO_PERFORM);
}
assertTrue(ds.compare("", "supportedLDAPVersion", "3").compareMatched());
try {
conn.processExtendedOperation(new WhoAmIExtendedRequest());
} catch (final LDAPException le) {
assertEquals(le.getResultCode(), ResultCode.UNWILLING_TO_PERFORM);
}
assertEquals(ds.processExtendedOperation(new WhoAmIExtendedRequest()).getResultCode(), ResultCode.SUCCESS);
try {
conn.modify("dn: dc=example,dc=com", "changetype: modify", "replace: description", "description: foo");
} catch (final LDAPException le) {
assertEquals(le.getResultCode(), ResultCode.UNWILLING_TO_PERFORM);
}
ds.modify("dn: dc=example,dc=com", "changetype: modify", "replace: description", "description: foo");
try {
conn.modifyDN("ou=People,dc=example,dc=com", "ou=Users", true);
} catch (final LDAPException le) {
assertEquals(le.getResultCode(), ResultCode.UNWILLING_TO_PERFORM);
}
ds.modifyDN("ou=People,dc=example,dc=com", "ou=Users", true);
try {
conn.search("dc=example,dc=com", SearchScope.BASE, "(objectClass=*)");
} catch (final LDAPException le) {
assertEquals(le.getResultCode(), ResultCode.UNWILLING_TO_PERFORM);
}
ds.search("dc=example,dc=com", SearchScope.BASE, "(objectClass=*)");
try {
conn.delete("ou=Users,dc=example,dc=com");
} catch (final LDAPException le) {
assertEquals(le.getResultCode(), ResultCode.UNWILLING_TO_PERFORM);
}
ds.delete("ou=Users,dc=example,dc=com");
final Control[] unbindControls = { new Control("1.2.3.4", false), new Control("1.2.3.5", false, new ASN1OctetString("foo")) };
conn.close(unbindControls);
ds.shutDown(true);
}
Aggregations