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);
}
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");
}
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());
}
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);
}
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);
}
Aggregations