Search in sources :

Example 6 with LDAPSearch

use of com.unboundid.ldap.sdk.examples.LDAPSearch in project ldapsdk by pingidentity.

the class InteractiveCommandLineToolTestCase method testLDAPSearchAuthenticatedRootDSESearch.

/**
 * Tests the ldapsearch tool to run a full search to retrieve the root DSE.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testLDAPSearchAuthenticatedRootDSESearch() throws Exception {
    final InMemoryDirectoryServer ds = getTestDS();
    System.setIn(getInputStream(// Server address
    "localhost", // Do not attempt to communicate securely.
    "5", // Server port
    String.valueOf(ds.getListenPort()), // Default to simple authentication.
    "", // Bind DN
    "cn=Directory Manager", // Bind password
    "password", // Empty base DN
    "", // First trailing argument
    "(objectClass=*)", // Second trailing argument
    "*", // Third trailing argument
    "+", // No more trailing arguments
    "", // Select the scope argument
    "3", // Select a baseObject scope.
    "1", // Display the command that will be run.
    "d", // Return from displaying the command.
    "", // Run the tool.
    "r"));
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    final LDAPSearch tool = new LDAPSearch(out, out);
    final ResultCode resultCode = tool.runTool();
    assertEquals(resultCode, ResultCode.SUCCESS, "Tool output:  " + StaticUtils.toUTF8String(out.toByteArray()));
}
Also used : InMemoryDirectoryServer(com.unboundid.ldap.listener.InMemoryDirectoryServer) LDAPSearch(com.unboundid.ldap.sdk.examples.LDAPSearch) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ResultCode(com.unboundid.ldap.sdk.ResultCode) Test(org.testng.annotations.Test)

Example 7 with LDAPSearch

use of com.unboundid.ldap.sdk.examples.LDAPSearch in project ldapsdk by pingidentity.

the class LDAPCommandLineToolTestCase method testPropertiesFilePropertyMissingEquals.

/**
 * Tests the behavior with a properties file that has a property line that
 * does not include an equal sign to separate the property name from the
 * value.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testPropertiesFilePropertyMissingEquals() throws Exception {
    final InMemoryDirectoryServer ds = getTestDS();
    final File propertiesFile = createTempFile("# The hostname", "hostname=127.0.0.1", "", "# The port", "--port " + ds.getListenPort());
    final LDAPSearch ldapSearch = new LDAPSearch(null, null);
    final ResultCode rc = ldapSearch.runTool("--propertiesFilePath", propertiesFile.getAbsolutePath(), "--baseDN", "", "(objectClass=*)");
    assertFalse(rc == ResultCode.SUCCESS);
}
Also used : InMemoryDirectoryServer(com.unboundid.ldap.listener.InMemoryDirectoryServer) LDAPSearch(com.unboundid.ldap.sdk.examples.LDAPSearch) File(java.io.File) ResultCode(com.unboundid.ldap.sdk.ResultCode) Test(org.testng.annotations.Test)

Example 8 with LDAPSearch

use of com.unboundid.ldap.sdk.examples.LDAPSearch in project ldapsdk by pingidentity.

the class LDAPCommandLineToolTestCase method testPropertiesFileCommentWithExpectedContinuation.

/**
 * Tests the behavior with a properties file that has a comment line when a
 * continuation was expected.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testPropertiesFileCommentWithExpectedContinuation() throws Exception {
    final InMemoryDirectoryServer ds = getTestDS();
    final File propertiesFile = createTempFile("# The hostname", "hostname=\\", "# The port", "port=" + ds.getListenPort());
    final LDAPSearch ldapSearch = new LDAPSearch(null, null);
    final ResultCode rc = ldapSearch.runTool("--propertiesFilePath", propertiesFile.getAbsolutePath(), "--baseDN", "", "(objectClass=*)");
    assertFalse(rc == ResultCode.SUCCESS);
}
Also used : InMemoryDirectoryServer(com.unboundid.ldap.listener.InMemoryDirectoryServer) LDAPSearch(com.unboundid.ldap.sdk.examples.LDAPSearch) File(java.io.File) ResultCode(com.unboundid.ldap.sdk.ResultCode) Test(org.testng.annotations.Test)

Example 9 with LDAPSearch

use of com.unboundid.ldap.sdk.examples.LDAPSearch in project ldapsdk by pingidentity.

the class LDAPCommandLineToolTestCase method testStartTLS.

/**
 * Provides test coverage for StartTLS-based communication.
 * <BR><BR>
 * Access to an SSL-enabled Directory Server instance is required for complete
 * processing.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testStartTLS() throws Exception {
    if (!isSSLEnabledDirectoryInstanceAvailable()) {
        return;
    }
    LDAPSearch ldapSearch = new LDAPSearch(null, null);
    ResultCode rc = ldapSearch.runTool("-h", getTestHost(), "-p", String.valueOf(getTestPort()), "-q", "-X", "-D", getTestBindDN(), "-w", getTestBindPassword(), "-b", "", "-s", "base", "(objectClass=*)");
    assertEquals(rc, ResultCode.SUCCESS);
    assertTrue(ldapSearch.anyLDAPArgumentsProvided());
}
Also used : LDAPSearch(com.unboundid.ldap.sdk.examples.LDAPSearch) ResultCode(com.unboundid.ldap.sdk.ResultCode) Test(org.testng.annotations.Test)

Example 10 with LDAPSearch

use of com.unboundid.ldap.sdk.examples.LDAPSearch in project ldapsdk by pingidentity.

the class LDAPCommandLineToolTestCase method testGetConnectionPool.

/**
 * Provides test coverage for the method used to get a connection pool.
 * <BR><BR>
 * Access to an SSL-enabled Directory Server instance is required for complete
 * processing.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testGetConnectionPool() throws Exception {
    if (!isSSLEnabledDirectoryInstanceAvailable()) {
        return;
    }
    LDAPSearch ldapSearch = new LDAPSearch(null, null);
    ResultCode rc = ldapSearch.runTool("-h", getTestHost(), "-p", String.valueOf(getTestPort()), "-q", "-X", "-D", getTestBindDN(), "-w", getTestBindPassword(), "-b", "", "-s", "base", "(objectClass=*)");
    assertEquals(rc, ResultCode.SUCCESS);
    LDAPConnectionPool pool = ldapSearch.getConnectionPool(1, 5);
    assertNotNull(pool);
    assertNotNull(pool.getRootDSE());
    LDAPConnection conn = pool.getConnection();
    assertNotNull(conn);
    assertNotNull(conn.getRootDSE());
    LDAPConnection conn2 = pool.getConnection();
    assertNotNull(conn2);
    assertNotNull(conn2.getRootDSE());
    pool.releaseConnection(conn);
    pool.releaseConnection(conn2);
    pool.close();
    assertTrue(ldapSearch.anyLDAPArgumentsProvided());
}
Also used : LDAPConnectionPool(com.unboundid.ldap.sdk.LDAPConnectionPool) LDAPSearch(com.unboundid.ldap.sdk.examples.LDAPSearch) LDAPConnection(com.unboundid.ldap.sdk.LDAPConnection) ResultCode(com.unboundid.ldap.sdk.ResultCode) Test(org.testng.annotations.Test)

Aggregations

LDAPSearch (com.unboundid.ldap.sdk.examples.LDAPSearch)39 Test (org.testng.annotations.Test)39 ResultCode (com.unboundid.ldap.sdk.ResultCode)35 File (java.io.File)21 InMemoryDirectoryServer (com.unboundid.ldap.listener.InMemoryDirectoryServer)20 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 ANONYMOUSBindRequest (com.unboundid.ldap.sdk.ANONYMOUSBindRequest)3 BindRequest (com.unboundid.ldap.sdk.BindRequest)3 CRAMMD5BindRequest (com.unboundid.ldap.sdk.CRAMMD5BindRequest)3 DIGESTMD5BindRequest (com.unboundid.ldap.sdk.DIGESTMD5BindRequest)3 EXTERNALBindRequest (com.unboundid.ldap.sdk.EXTERNALBindRequest)3 GSSAPIBindRequest (com.unboundid.ldap.sdk.GSSAPIBindRequest)3 OAUTHBEARERBindRequest (com.unboundid.ldap.sdk.OAUTHBEARERBindRequest)3 PLAINBindRequest (com.unboundid.ldap.sdk.PLAINBindRequest)3 SCRAMSHA1BindRequest (com.unboundid.ldap.sdk.SCRAMSHA1BindRequest)3 SCRAMSHA256BindRequest (com.unboundid.ldap.sdk.SCRAMSHA256BindRequest)3 SCRAMSHA512BindRequest (com.unboundid.ldap.sdk.SCRAMSHA512BindRequest)3 SingleUseTOTPBindRequest (com.unboundid.ldap.sdk.unboundidds.SingleUseTOTPBindRequest)3 UnboundIDCertificatePlusPasswordBindRequest (com.unboundid.ldap.sdk.unboundidds.UnboundIDCertificatePlusPasswordBindRequest)3 UnboundIDDeliveredOTPBindRequest (com.unboundid.ldap.sdk.unboundidds.UnboundIDDeliveredOTPBindRequest)3