Search in sources :

Example 21 with LDAPSearch

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

the class LDAPCommandLineToolTestCase method testPropertiesFileEndsWithExpectedContinuation.

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

Example 22 with LDAPSearch

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

the class SASLUtilsTestCase method testValidYubiKeyOTPBindPromptForStaticPassword.

/**
 * Tests the ability to create a valid UNBOUNDID-YUBIKEY-OTP bind request
 * when prompting for a static password.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testValidYubiKeyOTPBindPromptForStaticPassword() throws Exception {
    final LDAPSearch tool = new LDAPSearch(null, null);
    final BindRequest bindRequest;
    try {
        PasswordReader.setTestReader(new BufferedReader(new InputStreamReader(new ByteArrayInputStream("password\n".getBytes("UTF-8")))));
        bindRequest = SASLUtils.createBindRequest(null, (byte[]) null, false, tool, null, Arrays.asList("mech=UNBOUNDID-YUBIKEY-OTP", "authID=u:test.user", "otp=YubiKeyOTP", "promptForStaticPassword=true"));
    } finally {
        PasswordReader.setTestReader(null);
    }
    assertNotNull(bindRequest);
    assertTrue(bindRequest instanceof UnboundIDYubiKeyOTPBindRequest);
    final UnboundIDYubiKeyOTPBindRequest yubiKeyBind = (UnboundIDYubiKeyOTPBindRequest) bindRequest;
    assertNotNull(yubiKeyBind.getAuthenticationID());
    assertEquals(yubiKeyBind.getAuthenticationID(), "u:test.user");
    assertNull(yubiKeyBind.getAuthorizationID());
    assertNotNull(yubiKeyBind.getStaticPasswordString());
    assertEquals(yubiKeyBind.getStaticPasswordString(), "password");
    assertNotNull(yubiKeyBind.getYubiKeyOTP());
    assertEquals(yubiKeyBind.getYubiKeyOTP(), "YubiKeyOTP");
}
Also used : InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) LDAPSearch(com.unboundid.ldap.sdk.examples.LDAPSearch) UnboundIDYubiKeyOTPBindRequest(com.unboundid.ldap.sdk.unboundidds.UnboundIDYubiKeyOTPBindRequest) ANONYMOUSBindRequest(com.unboundid.ldap.sdk.ANONYMOUSBindRequest) GSSAPIBindRequest(com.unboundid.ldap.sdk.GSSAPIBindRequest) UnboundIDCertificatePlusPasswordBindRequest(com.unboundid.ldap.sdk.unboundidds.UnboundIDCertificatePlusPasswordBindRequest) BindRequest(com.unboundid.ldap.sdk.BindRequest) SCRAMSHA512BindRequest(com.unboundid.ldap.sdk.SCRAMSHA512BindRequest) SingleUseTOTPBindRequest(com.unboundid.ldap.sdk.unboundidds.SingleUseTOTPBindRequest) PLAINBindRequest(com.unboundid.ldap.sdk.PLAINBindRequest) UnboundIDYubiKeyOTPBindRequest(com.unboundid.ldap.sdk.unboundidds.UnboundIDYubiKeyOTPBindRequest) EXTERNALBindRequest(com.unboundid.ldap.sdk.EXTERNALBindRequest) DIGESTMD5BindRequest(com.unboundid.ldap.sdk.DIGESTMD5BindRequest) UnboundIDDeliveredOTPBindRequest(com.unboundid.ldap.sdk.unboundidds.UnboundIDDeliveredOTPBindRequest) OAUTHBEARERBindRequest(com.unboundid.ldap.sdk.OAUTHBEARERBindRequest) UnboundIDTOTPBindRequest(com.unboundid.ldap.sdk.unboundidds.UnboundIDTOTPBindRequest) SCRAMSHA1BindRequest(com.unboundid.ldap.sdk.SCRAMSHA1BindRequest) SCRAMSHA256BindRequest(com.unboundid.ldap.sdk.SCRAMSHA256BindRequest) CRAMMD5BindRequest(com.unboundid.ldap.sdk.CRAMMD5BindRequest) BufferedReader(java.io.BufferedReader) Test(org.testng.annotations.Test)

Example 23 with LDAPSearch

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

the class LDAPCommandLineToolTestCase method testSASLPlain.

/**
 * Provides test coverage for SASL authentication using the PLAIN method.  The
 * password will be read from a file.
 * <BR><BR>
 * Access to a Directory Server instance is required for complete processing.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testSASLPlain() throws Exception {
    if (!isDirectoryInstanceAvailable()) {
        return;
    }
    File f = createTempFile(getTestBindPassword());
    LDAPSearch ldapSearch = new LDAPSearch(null, null);
    ResultCode rc = ldapSearch.runTool("-h", getTestHost(), "-p", String.valueOf(getTestPort()), "-o", "mech=PLAIN", "-o", "authID=dn:" + getTestBindDN(), "-j", f.getAbsolutePath(), "-b", "", "-s", "base", "(objectClass=*)");
    assertEquals(rc, ResultCode.SUCCESS);
    f.delete();
    assertTrue(ldapSearch.anyLDAPArgumentsProvided());
}
Also used : LDAPSearch(com.unboundid.ldap.sdk.examples.LDAPSearch) File(java.io.File) ResultCode(com.unboundid.ldap.sdk.ResultCode) Test(org.testng.annotations.Test)

Example 24 with LDAPSearch

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

the class LDAPCommandLineToolTestCase method testValidPropertiesFileWithALotOfVariance.

/**
 * Tests the behavior with a properties file that covers a range of use cases.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testValidPropertiesFileWithALotOfVariance() throws Exception {
    final InMemoryDirectoryServer ds = getTestDSWithSSL();
    final File propertiesFile = createTempFile("# Hostname and port specified as properties general to any tool.", "# Hostname split across multiple lines.", "hostname=127.\\", " 0.\\", " 0.\\", " 1", "port=" + ds.getListenPort(), "", "# A port number specific to an unrelated tool.", "ldapmodify.port=12345", "", "# General property for no SSL, but tool-specific property with SSL", "useSSL=false", "ldapsearch.useSSL=true", "", "# Use a two-dash identifier to indicate trusting all certificates", "--trustAll=true", "", "# Use a one-dash identifier to specify the bind DN.", "-D=cn\\=Directory Manager", "", "# Use a one-dash tool-specific identifier to specify the password.", "ldapsearch.-w=password", "", "# A property that doesn't have a value", "ldapsearch.followReferrals=", "", "# A property that isn't valid for any tool.", "notValidForAnyTool=who cares");
    final LDAPSearch ldapSearch = new LDAPSearch(null, null);
    final ResultCode rc = ldapSearch.runTool("--propertiesFilePath", propertiesFile.getAbsolutePath(), "--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)

Example 25 with LDAPSearch

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

the class LDAPCommandLineToolTestCase method testPropertiesFileSpecifiedByJavaPropertyButNoPropertiesOption.

/**
 * Tests the behavior when a properties file is specified by a system property
 * but when the noPropertiesFile option is used to prevent that properties
 * file from being used.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testPropertiesFileSpecifiedByJavaPropertyButNoPropertiesOption() throws Exception {
    final InMemoryDirectoryServer ds = getTestDS();
    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", // Not valid.
    "-p", // Not valid.
    String.valueOf(getTestDSWithSSL().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=" + getTestDSWithSSL().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("--noPropertiesFile", "-h", "127.0.0.1", "-p", String.valueOf(ds.getListenPort()), "-D", "cn=Directory Manager", "-w", "password", "--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