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