Search in sources :

Example 11 with LDAPSearch

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

the class LDAPCommandLineToolTestCase method testGeneratePropertiesFileWithNoPropertiesFile.

/**
 * Tests the behavior when both the generatePropertiesFile and
 * noPropertiesFile arguments are specified.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testGeneratePropertiesFileWithNoPropertiesFile() throws Exception {
    final InMemoryDirectoryServer ds = getTestDS();
    final LDAPSearch ldapSearch = new LDAPSearch(null, null);
    final File propertiesFile = createTempFile();
    assertTrue(propertiesFile.delete());
    final ResultCode rc = ldapSearch.runTool("--generatePropertiesFile", 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 12 with LDAPSearch

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

the class LDAPCommandLineToolTestCase method testSSL.

/**
 * Provides test coverage for SSL-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 testSSL() throws Exception {
    if (!isSSLEnabledDirectoryInstanceAvailable()) {
        return;
    }
    LDAPSearch ldapSearch = new LDAPSearch(null, null);
    ResultCode rc = ldapSearch.runTool("-h", getTestHost(), "-p", String.valueOf(getTestSSLPort()), "-Z", "-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 13 with LDAPSearch

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

the class LDAPCommandLineToolTestCase method testGenerateAndUsePropertiesFileWithArguments.

/**
 * 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.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testGenerateAndUsePropertiesFileWithArguments() 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(), "--hostname", "127.0.0.1", "--port", String.valueOf(ds.getListenPort()), "--useSSL", "--trustAll", "--bindDN", "cn=Directory Manager", "--bindPassword", "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");
    ldapSearch = new LDAPSearch(null, null);
    rc = ldapSearch.runTool("--propertiesFilePath", propertiesFile.getAbsolutePath(), "--suppressPropertiesFileComment", "--baseDN", "", "--scope", "base", "(objectClass=*)");
    assertEquals(rc, ResultCode.SUCCESS);
    assertTrue(ldapSearch.anyLDAPArgumentsProvided());
}
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 14 with LDAPSearch

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

the class LDAPCommandLineToolTestCase method testEmptyPropertiesFile.

/**
 * Tests the behavior when an empty properties file is specified.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testEmptyPropertiesFile() throws Exception {
    final InMemoryDirectoryServer ds = getTestDS();
    final File propertiesFile = createTempFile();
    assertTrue(propertiesFile.delete());
    OutputStream outputStream = new FileOutputStream(propertiesFile);
    outputStream = new PassphraseEncryptedOutputStream("encryption-password", outputStream);
    outputStream = new GZIPOutputStream(outputStream);
    outputStream.flush();
    outputStream.close();
    final LDAPSearch ldapSearch = new LDAPSearch(null, null);
    ldapSearch.getPasswordFileReader().addToEncryptionPasswordCache("encryption-password");
    final ResultCode rc = ldapSearch.runTool("--propertiesFilePath", propertiesFile.getAbsolutePath(), "--hostname", "127.0.0.1", "--port", String.valueOf(ds.getListenPort()), "--bindDN", "cn=Directory Manager", "--bindPassword", "password", "--baseDN", "", "--scope", "base", "(objectClass=*)");
    assertEquals(rc, ResultCode.SUCCESS);
}
Also used : GZIPOutputStream(java.util.zip.GZIPOutputStream) InMemoryDirectoryServer(com.unboundid.ldap.listener.InMemoryDirectoryServer) LDAPSearch(com.unboundid.ldap.sdk.examples.LDAPSearch) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FileOutputStream(java.io.FileOutputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) ResultCode(com.unboundid.ldap.sdk.ResultCode) Test(org.testng.annotations.Test)

Example 15 with LDAPSearch

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

the class LDAPCommandLineToolTestCase method testSSLWithUnsatisfiedDefaultTrust.

/**
 * Tests the behavior when trying to communicate with a server over SSL when
 * the defaultTrust argument is provided and the certificate cannot be trusted
 * using the default trust mechanism.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testSSLWithUnsatisfiedDefaultTrust() throws Exception {
    final InMemoryDirectoryServerConfig cfg = new InMemoryDirectoryServerConfig("dc=example,dc=com", "o=example.com");
    cfg.addAdditionalBindCredentials("cn=Directory Manager", "password");
    cfg.addAdditionalBindCredentials("cn=Manager", "password");
    cfg.setSchema(Schema.getDefaultStandardSchema());
    final File resourceDir = new File(System.getProperty("unit.resource.dir"));
    final File serverKeyStore = new File(resourceDir, "server.keystore");
    final SSLUtil serverSSLUtil = new SSLUtil(new KeyStoreKeyManager(serverKeyStore, "password".toCharArray(), "JKS", "server-cert"), new TrustAllTrustManager());
    final SSLUtil clientSSLUtil = new SSLUtil(new TrustAllTrustManager());
    cfg.setListenerConfigs(InMemoryListenerConfig.createLDAPSConfig("LDAPS", null, 0, serverSSLUtil.createSSLServerSocketFactory(), clientSSLUtil.createSSLSocketFactory()));
    try (InMemoryDirectoryServer ds = new InMemoryDirectoryServer(cfg)) {
        ds.startListening();
        final LDAPSearch ldapSearch = new LDAPSearch(null, null);
        final ResultCode rc = ldapSearch.runTool("--hostname", "127.0.0.1", "--port", String.valueOf(ds.getListenPort()), "--useSSL", "--defaultTrust", "--bindDN", "cn=Directory Manager", "--bindPassword", "password", "--baseDN", "", "--scope", "base", "(objectClass=*)");
        assertFalse(rc.equals(ResultCode.SUCCESS));
    }
}
Also used : SSLUtil(com.unboundid.util.ssl.SSLUtil) KeyStoreKeyManager(com.unboundid.util.ssl.KeyStoreKeyManager) InMemoryDirectoryServer(com.unboundid.ldap.listener.InMemoryDirectoryServer) LDAPSearch(com.unboundid.ldap.sdk.examples.LDAPSearch) InMemoryDirectoryServerConfig(com.unboundid.ldap.listener.InMemoryDirectoryServerConfig) TrustAllTrustManager(com.unboundid.util.ssl.TrustAllTrustManager) 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