Search in sources :

Example 36 with WhoAmIExtendedRequest

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);
    }
}
Also used : LDAPConnectionOptions(com.unboundid.ldap.sdk.LDAPConnectionOptions) AddRequest(com.unboundid.ldap.sdk.AddRequest) ModifyDNRequest(com.unboundid.ldap.sdk.ModifyDNRequest) SearchRequest(com.unboundid.ldap.sdk.SearchRequest) SimpleBindRequest(com.unboundid.ldap.sdk.SimpleBindRequest) CompareRequest(com.unboundid.ldap.sdk.CompareRequest) WhoAmIExtendedRequest(com.unboundid.ldap.sdk.extensions.WhoAmIExtendedRequest) LDAPConnection(com.unboundid.ldap.sdk.LDAPConnection) ModifyRequest(com.unboundid.ldap.sdk.ModifyRequest) DeleteRequest(com.unboundid.ldap.sdk.DeleteRequest) Test(org.testng.annotations.Test)

Example 37 with WhoAmIExtendedRequest

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);
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) AuthorizationIdentityRequestControl(com.unboundid.ldap.sdk.controls.AuthorizationIdentityRequestControl) Control(com.unboundid.ldap.sdk.Control) IgnoreNoUserModificationRequestControl(com.unboundid.ldap.sdk.unboundidds.controls.IgnoreNoUserModificationRequestControl) AuthorizationIdentityResponseControl(com.unboundid.ldap.sdk.controls.AuthorizationIdentityResponseControl) LDAPException(com.unboundid.ldap.sdk.LDAPException) WhoAmIExtendedRequest(com.unboundid.ldap.sdk.extensions.WhoAmIExtendedRequest) LDAPConnection(com.unboundid.ldap.sdk.LDAPConnection) Test(org.testng.annotations.Test)

Aggregations

WhoAmIExtendedRequest (com.unboundid.ldap.sdk.extensions.WhoAmIExtendedRequest)37 Test (org.testng.annotations.Test)31 LDAPConnection (com.unboundid.ldap.sdk.LDAPConnection)21 WhoAmIExtendedResult (com.unboundid.ldap.sdk.extensions.WhoAmIExtendedResult)15 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)9 Control (com.unboundid.ldap.sdk.Control)8 LDAPException (com.unboundid.ldap.sdk.LDAPException)7 SimpleBindRequest (com.unboundid.ldap.sdk.SimpleBindRequest)7 AuthorizationIdentityRequestControl (com.unboundid.ldap.sdk.controls.AuthorizationIdentityRequestControl)6 AuthorizationIdentityResponseControl (com.unboundid.ldap.sdk.controls.AuthorizationIdentityResponseControl)6 InMemoryDirectoryServer (com.unboundid.ldap.listener.InMemoryDirectoryServer)4 BindResult (com.unboundid.ldap.sdk.BindResult)4 AddRequest (com.unboundid.ldap.sdk.AddRequest)3 CompareRequest (com.unboundid.ldap.sdk.CompareRequest)3 DeleteRequest (com.unboundid.ldap.sdk.DeleteRequest)3 ExtendedResult (com.unboundid.ldap.sdk.ExtendedResult)3 LDAPConnectionOptions (com.unboundid.ldap.sdk.LDAPConnectionOptions)3 ModifyDNRequest (com.unboundid.ldap.sdk.ModifyDNRequest)3 ModifyRequest (com.unboundid.ldap.sdk.ModifyRequest)3 PLAINBindRequest (com.unboundid.ldap.sdk.PLAINBindRequest)3