2375N/A/*
2375N/A * CDDL HEADER START
2375N/A *
2375N/A * The contents of this file are subject to the terms of the
2375N/A * Common Development and Distribution License, Version 1.0 only
2375N/A * (the "License"). You may not use this file except in compliance
2375N/A * with the License.
2375N/A *
2375N/A * You can obtain a copy of the license at
2375N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE
2375N/A * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
2375N/A * See the License for the specific language governing permissions
2375N/A * and limitations under the License.
2375N/A *
2375N/A * When distributing Covered Code, include this CDDL HEADER in each
2375N/A * file and include the License file at
2375N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
2375N/A * add the following below this CDDL HEADER, with the fields enclosed
2375N/A * by brackets "[]" replaced with your own identifying information:
2375N/A * Portions Copyright [yyyy] [name of copyright owner]
2375N/A *
2375N/A * CDDL HEADER END
2375N/A *
2375N/A *
3232N/A * Copyright 2006-2008 Sun Microsystems, Inc.
2375N/A */
2375N/Apackage org.opends.server.tools.dsconfig;
2375N/A
2375N/A
2375N/A
2375N/Aimport java.io.File;
2375N/Aimport java.io.FileWriter;
2375N/A
2375N/Aimport org.testng.annotations.AfterClass;
2375N/Aimport org.testng.annotations.BeforeClass;
2375N/Aimport org.testng.annotations.Test;
2375N/A
2375N/Aimport org.opends.server.TestCaseUtils;
2375N/Aimport org.opends.server.DirectoryServerTestCase;
2375N/Aimport org.opends.server.core.DirectoryServer;
2375N/A
2375N/Aimport static org.testng.Assert.*;
2375N/A
2375N/Aimport static org.opends.server.admin.client.cli.DsFrameworkCliReturnCode.*;
2375N/A
2375N/A
2375N/A
2375N/A/**
2375N/A * A set of test cases for the dsservice tool.
2375N/A */
2375N/Apublic class DsconfigLdapConnectionTestCase extends DirectoryServerTestCase {
2375N/A // The path to a file containing an invalid bind password.
2375N/A private String invalidPasswordFile;
2375N/A
2375N/A // The path to a file containing a valid bind password.
2375N/A private String validPasswordFile;
2375N/A
2375N/A
2375N/A
2375N/A /**
2375N/A * Ensures that the Directory Server is running and performs other necessary
2375N/A * setup.
2375N/A *
2375N/A * @throws Exception If an unexpected problem occurs.
2375N/A */
2375N/A @BeforeClass()
2375N/A public void before()
2375N/A throws Exception
2375N/A {
2375N/A TestCaseUtils.startServer();
2375N/A
2375N/A File pwFile = File.createTempFile("valid-bind-password-", ".txt");
2375N/A pwFile.deleteOnExit();
2375N/A FileWriter fileWriter = new FileWriter(pwFile);
2375N/A fileWriter.write("password" + System.getProperty("line.separator"));
2375N/A fileWriter.close();
2375N/A validPasswordFile = pwFile.getAbsolutePath();
2375N/A
2375N/A pwFile = File.createTempFile("invalid-bind-password-", ".txt");
2375N/A pwFile.deleteOnExit();
2375N/A fileWriter = new FileWriter(pwFile);
2375N/A fileWriter.write("wrongPassword" + System.getProperty("line.separator"));
2375N/A fileWriter.close();
2375N/A invalidPasswordFile = pwFile.getAbsolutePath();
2375N/A }
2375N/A
2375N/A /**
2375N/A * Ensures ADS is removed.
2375N/A * @throws Exception If an unexpected problem occurs.
2375N/A */
2375N/A @AfterClass()
2375N/A public void afterClass()
2375N/A throws Exception
2375N/A {
2375N/A }
2375N/A
2375N/A /**
2375N/A * Tests list-list-connection-handlers with a malformed bind DN.
2375N/A */
2375N/A @Test()
2375N/A public void testMalformedBindDN()
2375N/A {
2375N/A String[] args =
2375N/A {
2375N/A "-n",
2568N/A "--noPropertiesFile",
2375N/A "-Q",
2375N/A "list-connection-handlers",
3853N/A "-p", String.valueOf(TestCaseUtils.getServerAdminPort()),
2375N/A "-D", "malformed",
3853N/A "-w", "password",
3853N/A "-X"
2375N/A };
2375N/A
2375N/A assertFalse(DSConfig.main(args, false, null, null)
2375N/A == SUCCESSFUL.getReturnCode());
2375N/A }
2375N/A
2375N/A /**
2375N/A * Tests list-connection-handlers with a nonexistent bind DN.
2375N/A */
2375N/A @Test()
2375N/A public void testNonExistentBindDN()
2375N/A {
2375N/A String[] args =
2375N/A {
2375N/A "-n",
2568N/A "--noPropertiesFile",
2375N/A "-Q",
2375N/A "list-connection-handlers",
3853N/A "-p", String.valueOf(TestCaseUtils.getServerAdminPort()),
2375N/A "-D", "cn=Does Not Exist",
3853N/A "-w", "password",
3853N/A "-X"
2375N/A };
2375N/A
2375N/A assertFalse(DSConfig.main(args, false, System.out, System.err)
2375N/A == SUCCESSFUL.getReturnCode());
2375N/A }
2375N/A
2375N/A /**
2375N/A * Tests list-connection-handlers with an invalid password.
2375N/A */
2375N/A @Test()
2375N/A public void testInvalidBindPassword()
2375N/A {
2375N/A String[] args =
2375N/A {
2375N/A "-n",
2568N/A "--noPropertiesFile",
2375N/A "-Q",
2375N/A "list-connection-handlers",
3853N/A "-p", String.valueOf(TestCaseUtils.getServerAdminPort()),
2375N/A "-D", "cn=Directory Manager",
3853N/A "-w", "wrongPassword",
3853N/A "-X"
2375N/A };
2375N/A
2375N/A assertFalse(DSConfig.main(args, false, System.out, System.err)
2375N/A == SUCCESSFUL.getReturnCode());
2375N/A }
2375N/A
2375N/A
2375N/A
2375N/A
2375N/A /**
2375N/A * Tests list-connection-handlers with a valid password read from a file.
2375N/A *
2375N/A * @throws Exception If an unexpected problem occurs.
2375N/A */
2375N/A @Test()
2375N/A public void testValidPasswordFromFile()
2375N/A throws Exception
2375N/A {
2375N/A String[] args =
2375N/A {
2375N/A "-n",
2568N/A "--noPropertiesFile",
2375N/A "-Q",
2375N/A "list-connection-handlers",
3853N/A "-p", String.valueOf(TestCaseUtils.getServerAdminPort()),
2375N/A "-D", "cn=Directory Manager",
2375N/A "-j", validPasswordFile,
3853N/A "-X"
2375N/A };
2375N/A
2375N/A assertEquals(DSConfig.main(args, false, System.out,
2375N/A System.err), SUCCESSFUL.getReturnCode());
2375N/A }
2375N/A
2375N/A /**
2375N/A * Tests list-connection-handlers with an invalid password read from a file.
2375N/A *
2375N/A * @throws Exception If an unexpected problem occurs.
2375N/A */
2375N/A @Test()
2375N/A public void testInvalidPasswordFromFile()
2375N/A throws Exception
2375N/A {
2375N/A String[] args =
2375N/A {
2375N/A "-n",
2568N/A "--noPropertiesFile",
2375N/A "-Q",
2375N/A "list-connection-handlers",
3853N/A "-p", String.valueOf(TestCaseUtils.getServerAdminPort()),
2375N/A "-D", "cn=Directory Manager",
3853N/A "-j",invalidPasswordFile,
3853N/A "-X"
2375N/A };
2375N/A
2375N/A assertFalse(DSConfig.main(args, false, System.out, System.err)
2375N/A == SUCCESSFUL.getReturnCode());
2375N/A }
2375N/A
2375N/A
2375N/A /**
2375N/A * Tests list-connection-handlers over SSL using a trust store.
2375N/A */
2375N/A @Test()
2375N/A public void testListConnectionHandlersSSLTrustStore()
2375N/A {
3824N/A String trustStorePath = DirectoryServer.getInstanceRoot() + File.separator +
3853N/A "config" + File.separator + "admin-truststore";
2375N/A
2375N/A String[] args =
2375N/A {
2375N/A "-n",
2568N/A "--noPropertiesFile",
2375N/A "-Q",
2375N/A "list-connection-handlers",
3853N/A "-p", String.valueOf(TestCaseUtils.getServerAdminPort()),
2375N/A "-w", "password",
2375N/A "-P", trustStorePath
2375N/A };
2375N/A
2375N/A assertEquals(DSConfig.main(args, false, System.out,
2375N/A System.err), SUCCESSFUL.getReturnCode());
2375N/A }
2375N/A
2375N/A
2375N/A /**
2375N/A * Tests the dsconfig with the "--help" option.
2375N/A */
2375N/A @Test()
2375N/A public void testHelp()
2375N/A {
2568N/A String[] args = {"--noPropertiesFile","--help" };
2375N/A assertEquals(DSConfig.main(args, false, null, null),
2375N/A SUCCESSFUL.getReturnCode());
2375N/A
2568N/A args = new String[] { "--noPropertiesFile", "-H" };
2375N/A assertEquals(DSConfig.main(args, false, null, null),
2375N/A SUCCESSFUL.getReturnCode());
2375N/A
2568N/A args = new String[] { "--noPropertiesFile", "-?" };
2375N/A assertEquals(DSConfig.main(args, false, null, null),
2375N/A SUCCESSFUL.getReturnCode());
2375N/A }
2375N/A}
2375N/A