Search in sources :

Example 31 with LDAPSearch

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

the class LDAPCommandLineToolTestCase method testPropertiesFilePathWithNoPropertiesFile.

/**
 * Tests the behavior when both the propertiesFilePath and noPropertiesFile
 * arguments are specified.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testPropertiesFilePathWithNoPropertiesFile() throws Exception {
    final InMemoryDirectoryServer ds = getTestDS();
    final LDAPSearch ldapSearch = new LDAPSearch(null, null);
    final File propertiesFile = createTempFile();
    final ResultCode rc = ldapSearch.runTool("--propertiesFilePath", propertiesFile.getAbsolutePath(), "--noPropertiesFile", "-h", "127.0.0.1", "-p", String.valueOf(ds.getListenPort()), "-D", "cn=Directory Manager", "-w", "password", "--baseDN", "", "--scope", "base", "(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 32 with LDAPSearch

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

the class LDAPCommandLineToolTestCase method testPropertiesFilePathWithGeneratePropertiesFile.

/**
 * Tests the behavior when both the propertiesFilePath and
 * generatePropertiesFile arguments are specified.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testPropertiesFilePathWithGeneratePropertiesFile() throws Exception {
    final InMemoryDirectoryServer ds = getTestDS();
    final LDAPSearch ldapSearch = new LDAPSearch(null, null);
    final File f1 = createTempFile();
    final File f2 = createTempFile();
    assertTrue(f2.delete());
    final ResultCode rc = ldapSearch.runTool("--propertiesFilePath", f1.getAbsolutePath(), "--generatePropertiesFile", f2.getAbsolutePath(), "-h", "127.0.0.1", "-p", String.valueOf(ds.getListenPort()), "-D", "cn=Directory Manager", "-w", "password", "--baseDN", "", "--scope", "base", "(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 33 with LDAPSearch

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

the class LDAPCommandLineToolTestCase method testUseSASLExternalFailure.

/**
 * Provides a test that uses the useSASLExternal argument in a manner that
 * cannot succeed.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testUseSASLExternalFailure() throws Exception {
    LDAPSearch ldapSearch = new LDAPSearch(null, null);
    ResultCode rc = ldapSearch.runTool("-h", getTestHost(), "-p", String.valueOf(getTestPort()), "--useSASLExternal", "-b", "", "-s", "base", "(objectClass=*)");
    assertFalse(rc == ResultCode.SUCCESS);
}
Also used : LDAPSearch(com.unboundid.ldap.sdk.examples.LDAPSearch) ResultCode(com.unboundid.ldap.sdk.ResultCode) Test(org.testng.annotations.Test)

Example 34 with LDAPSearch

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

the class LDAPCommandLineToolTestCase method testPropertiesFileUnexpectedInitialWhitespace.

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

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

the class LDAPCommandLineToolTestCase method testPropertiesFileSpecifiedByJavaProperty.

/**
 * Tests the behavior when trying to generate a properties file when values
 * are provided for a number of arguments, and then verify the ability to use
 * that properties file to actually run the tool when the properties file is
 * inferred via a system property rather than a command-line argument.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testPropertiesFileSpecifiedByJavaProperty() throws Exception {
    final InMemoryDirectoryServer ds = getTestDSWithSSL();
    LDAPSearch ldapSearch = new LDAPSearch(null, null);
    final File propertiesFile = createTempFile();
    assertTrue(propertiesFile.exists());
    assertTrue(propertiesFile.delete());
    assertFalse(propertiesFile.exists());
    ResultCode rc = ldapSearch.runTool("--generatePropertiesFile", propertiesFile.getAbsolutePath(), "-h", "127.0.0.1", "-p", String.valueOf(ds.getListenPort()), "-Z", "-X", "-D", "cn=Directory Manager", "-w", "password");
    assertEquals(rc, ResultCode.SUCCESS);
    assertTrue(propertiesFile.exists());
    assertTrue(propertiesFile.length() > 0);
    assertFileHasLine(propertiesFile, "# ldapsearch.hostname={host}");
    assertFileHasLine(propertiesFile, "# ldapsearch.port={port}");
    assertFileHasLine(propertiesFile, "# ldapsearch.bindDN={dn}");
    assertFileHasLine(propertiesFile, "# ldapsearch.bindPassword={password}");
    assertFileHasLine(propertiesFile, "ldapsearch.hostname=127.0.0.1");
    assertFileHasLine(propertiesFile, "ldapsearch.port=" + ds.getListenPort());
    assertFileHasLine(propertiesFile, "ldapsearch.bindDN=cn=Directory Manager");
    assertFileHasLine(propertiesFile, "ldapsearch.bindPassword=password");
    System.setProperty(ArgumentParser.PROPERTY_DEFAULT_PROPERTIES_FILE_PATH, propertiesFile.getAbsolutePath());
    ldapSearch = new LDAPSearch(null, null);
    rc = ldapSearch.runTool("--baseDN", "", "--scope", "base", "(objectClass=*)");
    assertEquals(rc, ResultCode.SUCCESS);
    System.clearProperty(ArgumentParser.PROPERTY_DEFAULT_PROPERTIES_FILE_PATH);
}
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