Search in sources :

Example 26 with LDAPSearch

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

the class InteractiveCommandLineToolTestCase method testLDAPSearchMD5Coverage.

/**
 * Tests the ldapsearch tool with failed attempts at CRAM-MD5 and DIGEST-MD5
 * before successful simple authentication.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testLDAPSearchMD5Coverage() throws Exception {
    final InMemoryDirectoryServer ds = getTestDS();
    System.setIn(getInputStream(// Server address
    "localhost", // No communication encryption
    "5", String.valueOf(ds.getListenPort()), // Use SASL authentication
    "2", // Use CRAM-MD5
    "1", // Authentication ID
    "dn:cn=Directory Manager", // Password
    "password", // Re-try LDAP settings
    "1", // Directory server address.
    "localhost", // No communication encryption
    "5", String.valueOf(ds.getListenPort()), // Use SASL authentication
    "2", // Use DIGEST-MD5
    "2", // Authentication ID
    "dn:cn=Directory Manager", // Authorization ID
    "dn:cn=Directory Manager", // Example realm
    "EXAMPLE-REALM", // Password
    "password", // Re-try LDAP settings
    "1", // Directory server address.
    "localhost", // No communication encryption
    "5", String.valueOf(ds.getListenPort()), // Use LDAP simple authentication
    "1", // Bind DN is no DN -- there won't be a password prompt
    "", // Invalid base DN
    "invalid", // Empty base DN
    "", // Trailing arguments
    "t", // First trailing argument
    "(objectClass=*)", // No more trailing arguments.
    "", // Change scope
    "3", // BaseObject scope.
    "1", // Specify trailing arguments again.
    "t", // First trailing argument -- the filter
    "(objectClass=*)", // Second trailing argument -- all user attributes
    "*", // Third trailing argument -- all operational attributes
    "+", // No more trailing arguments
    "", // Display the arguments.
    "d", // Return from displaying the arguments.
    "", // Run the tool with the selected arguments.
    "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 27 with LDAPSearch

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

the class LDAPCommandLineToolTestCase method testPropertiesFileBlankWithExpectedContinuation.

/**
 * Tests the behavior with a properties file that has a blank line when a
 * continuation was expected.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testPropertiesFileBlankWithExpectedContinuation() 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 28 with LDAPSearch

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

the class LDAPCommandLineToolTestCase method testCommandLineTool.

/**
 * Provides test coverage for the general methods in the CommandLineTool
 * class.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testCommandLineTool() throws Exception {
    LDAPSearch ldapSearch = new LDAPSearch(System.out, System.err);
    assertNotNull(ldapSearch.getToolName());
    assertNotNull(ldapSearch.getToolDescription());
    assertTrue(ldapSearch.getMaxTrailingArguments() < 0);
    assertNotNull(ldapSearch.getTrailingArgumentsPlaceholder());
    assertNotNull(ldapSearch.getOut());
    assertNotNull(ldapSearch.getErr());
    assertNotNull(LDAPCommandLineTool.getLongLDAPArgumentIdentifiers(ldapSearch));
    assertFalse(LDAPCommandLineTool.getLongLDAPArgumentIdentifiers(ldapSearch).isEmpty());
    assertFalse(ldapSearch.anyLDAPArgumentsProvided());
}
Also used : LDAPSearch(com.unboundid.ldap.sdk.examples.LDAPSearch) Test(org.testng.annotations.Test)

Example 29 with LDAPSearch

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

the class LDAPCommandLineToolTestCase method testGetConnectionPoolExtendedOptions.

/**
 * Provides test coverage for the method used to get a connection pool with an
 * extended set of options.
 * <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 testGetConnectionPoolExtendedOptions() 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, 1, new TestPostConnectProcessor(null, null), new TestPostConnectProcessor(null, null), false, new TestLDAPConnectionPoolHealthCheck());
    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) TestPostConnectProcessor(com.unboundid.ldap.sdk.TestPostConnectProcessor) TestLDAPConnectionPoolHealthCheck(com.unboundid.ldap.sdk.TestLDAPConnectionPoolHealthCheck) Test(org.testng.annotations.Test)

Example 30 with LDAPSearch

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

the class LDAPCommandLineToolTestCase method testPropertiesFileHandlingOfArgumentsInAnExclusiveSet.

/**
 * Test the behavior when trying to using a properties file that has a value
 * set for an argument in an exclusive argument set when another argument in
 * that set was provided on the command line.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testPropertiesFileHandlingOfArgumentsInAnExclusiveSet() throws Exception {
    final InMemoryDirectoryServer ds = getTestDSWithSSL();
    LDAPSearch ldapSearch = new LDAPSearch(null, null);
    final File wrongPasswordFile = createTempFile("wrong-password");
    final File propertiesFile = createTempFile();
    assertTrue(propertiesFile.exists());
    assertTrue(propertiesFile.delete());
    assertFalse(propertiesFile.exists());
    ResultCode rc = ldapSearch.runTool("--generatePropertiesFile", propertiesFile.getAbsolutePath(), "--hostname", "127.0.0.1", "--port", String.valueOf(ds.getListenPort()), "--useSSL", "--trustAll", "--bindDN", "cn=Directory Manager", "--bindPasswordFile", wrongPasswordFile.getAbsolutePath());
    assertEquals(rc, ResultCode.SUCCESS);
    // Make sure that an attempt to run ldapsearch with that properties file and
    // values for other necessary arguments (but no password) will fail with an
    // "invalid credentials" result because it's picking up the wrong password
    // from the bindPasswordFile property set in the properties file.
    ldapSearch = new LDAPSearch(null, null);
    rc = ldapSearch.runTool("--propertiesFilePath", propertiesFile.getAbsolutePath(), "--baseDN", "", "--scope", "base", "(objectClass=*)");
    assertEquals(rc, ResultCode.INVALID_CREDENTIALS);
    // Issue the same command, but this time provide the right password as a
    // command-line argument.  This should succeed because the bind password
    // provided on the command line will override the value of the bind password
    // file set in the properties file because they're part of an exclusive
    // argument set.
    ldapSearch = new LDAPSearch(null, null);
    rc = ldapSearch.runTool("--propertiesFilePath", propertiesFile.getAbsolutePath(), "--bindPassword", "password", "--baseDN", "", "--scope", "base", "(objectClass=*)");
    assertEquals(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)

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