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