/**
  * Utility method which is called by the testcase sending a DELETE request.
  *
  * @param authentication The flag to set the authentication on and off.
  * @return The error code of operation performed.
  * @throws Exception If an unexpected problem occurs.
  */
 private int performDeleteOperation(boolean authentication) throws Exception {
   String[] args = null;
   if (authentication)
     args =
         new String[] {
           "--noPropertiesFile",
           "-h",
           "127.0.0.1",
           "-p",
           String.valueOf(TestCaseUtils.getServerLdapPort()),
           "-V",
           "3",
           "-D",
           "cn=Directory Manager",
           "-w",
           "password",
           "o=mod_rejectTestCase,o=test"
         };
   else
     args =
         new String[] {
           "--noPropertiesFile",
           "-h",
           "127.0.0.1",
           "-p",
           String.valueOf(TestCaseUtils.getServerLdapPort()),
           "o=mod_rejectTestCase,o=test"
         };
   return LDAPDelete.mainDelete(args, false, null, null);
 }
  @BeforeClass()
  public void setUp() throws Exception {
    TestCaseUtils.startServer();
    TestCaseUtils.clearJEBackend(false, "userRoot", SUFFIX);

    InternalClientConnection connection = InternalClientConnection.getRootConnection();

    // Add suffix entry.
    DN suffixDN = DN.decode(SUFFIX);
    if (DirectoryServer.getEntry(suffixDN) == null) {
      Entry suffixEntry = StaticUtils.createEntry(suffixDN);
      AddOperation addOperation =
          connection.processAdd(
              suffixEntry.getDN(),
              suffixEntry.getObjectClasses(),
              suffixEntry.getUserAttributes(),
              suffixEntry.getOperationalAttributes());
      assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS);
      assertNotNull(DirectoryServer.getEntry(suffixEntry.getDN()));
    }

    // Add base entry.
    DN baseDN = DN.decode(BASE);
    if (DirectoryServer.getEntry(baseDN) == null) {
      Entry baseEntry = StaticUtils.createEntry(baseDN);
      AddOperation addOperation =
          connection.processAdd(
              baseEntry.getDN(),
              baseEntry.getObjectClasses(),
              baseEntry.getUserAttributes(),
              baseEntry.getOperationalAttributes());
      assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS);
      assertNotNull(DirectoryServer.getEntry(baseEntry.getDN()));
    }

    // Add test entry.
    Entry testEntry =
        TestCaseUtils.makeEntry(
            "dn: uid=rogasawara," + BASE,
            "objectclass: top",
            "objectclass: person",
            "objectclass: organizationalPerson",
            "objectclass: inetOrgPerson",
            "uid: rogasawara",
            "userpassword: password",
            "mail: [email protected]",
            "givenname: Rodney",
            "sn: Ogasawara",
            "cn: Rodney Ogasawara",
            "title: Sales, Director");
    AddOperation addOperation =
        connection.processAdd(
            testEntry.getDN(),
            testEntry.getObjectClasses(),
            testEntry.getUserAttributes(),
            testEntry.getOperationalAttributes());
    assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS);
    assertNotNull(DirectoryServer.getEntry(testEntry.getDN()));
  }
  /**
   * Tests the use of the StartTLS extended operation to communicate with the server in conjunction
   * with SASL EXTERNAL authentication and using a client trust store to validate the server
   * certificate.
   *
   * @throws Exception If an unexpected problem occurs.
   */
  @Test()
  public void testStartTLSExternalAuthTrustStore() throws Exception {
    TestCaseUtils.initializeTestBackend(true);

    Entry e =
        TestCaseUtils.makeEntry(
            "dn: cn=Test User,o=test",
            "objectClass: top",
            "objectClass: person",
            "objectClass: organizationalPerson",
            "objectClass: inetOrgPerson",
            "cn: Test User",
            "givenName: Test",
            "sn: User");

    InternalClientConnection conn = InternalClientConnection.getRootConnection();
    AddOperation addOperation =
        conn.processAdd(
            e.getDN(), e.getObjectClasses(), e.getUserAttributes(), e.getOperationalAttributes());
    assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS);

    String keyStorePath =
        DirectoryServer.getInstanceRoot()
            + File.separator
            + "config"
            + File.separator
            + "client.keystore";
    String trustStorePath =
        DirectoryServer.getInstanceRoot()
            + File.separator
            + "config"
            + File.separator
            + "client.truststore";

    String[] args = {
      "--noPropertiesFile",
      "-h",
      "127.0.0.1",
      "-p",
      String.valueOf(TestCaseUtils.getServerLdapPort()),
      "-q",
      "-K",
      keyStorePath,
      "-W",
      "password",
      "-P",
      trustStorePath,
      "-r",
      "-b",
      "",
      "-s",
      "base",
      "(objectClass=*)"
    };

    assertEquals(LDAPSearch.mainSearch(args, false, null, System.err), 0);
  }
  /**
   * Performs a successful LDAP bind using CRAM-MD5 using the dn: form of the authentication ID
   * using a long password (longer than 64 bytes).
   *
   * @throws Exception If an unexpected problem occurs.
   */
  @Test()
  public void testLDAPBindSuccessWithDNAndLongPassword() throws Exception {
    TestCaseUtils.initializeTestBackend(true);

    String password = "******";

    Entry e =
        TestCaseUtils.makeEntry(
            "dn: uid=test.user,o=test",
            "objectClass: top",
            "objectClass: person",
            "objectClass: organizationalPerson",
            "objectClass: inetOrgPerson",
            "uid: test.user",
            "givenName: Test",
            "sn: User",
            "cn: Test User",
            "userPassword: "******"ds-pwp-password-policy-dn: cn=Clear UserPassword Policy,"
                + "cn=Password Policies,cn=config");

    InternalClientConnection conn = InternalClientConnection.getRootConnection();
    AddOperation addOperation =
        conn.processAdd(
            e.getDN(), e.getObjectClasses(),
            e.getUserAttributes(), e.getOperationalAttributes());
    assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS);

    String[] args = {
      "--noPropertiesFile",
      "-h",
      "127.0.0.1",
      "-p",
      String.valueOf(TestCaseUtils.getServerLdapPort()),
      "-o",
      "mech=CRAM-MD5",
      "-o",
      "authid=dn:uid=test.user,o=test",
      "-w",
      password,
      "-b",
      "",
      "-s",
      "base",
      "(objectClass=*)"
    };
    assertEquals(LDAPSearch.mainSearch(args, false, null, System.err), 0);
  }
Ejemplo n.º 5
0
  /**
   * Test the feature of clearing a JEReplicaDB used by a replication server. The clear feature is
   * used when a replication server receives a request to reset the generationId of a given domain.
   */
  @Test
  public void testClear() throws Exception {
    ReplicationServer replicationServer = null;
    JEReplicaDB replicaDB = null;
    try {
      TestCaseUtils.startServer();
      replicationServer = configureReplicationServer(100, 5000);
      replicaDB = newReplicaDB(replicationServer);

      CSN[] csns = generateCSNs(1, 0, 3);

      // Add the changes and check they are here
      replicaDB.add(new DeleteMsg(TEST_ROOT_DN, csns[0], "uid"));
      replicaDB.add(new DeleteMsg(TEST_ROOT_DN, csns[1], "uid"));
      replicaDB.add(new DeleteMsg(TEST_ROOT_DN, csns[2], "uid"));

      assertEquals(csns[0], replicaDB.getOldestCSN());
      assertEquals(csns[2], replicaDB.getNewestCSN());

      // Clear DB and check it is cleared.
      replicaDB.clear();

      assertEquals(null, replicaDB.getOldestCSN());
      assertEquals(null, replicaDB.getNewestCSN());
    } finally {
      shutdown(replicaDB);
      remove(replicationServer);
    }
  }
  /**
   * Tests whether the who am I? extended operation with an unauthenticated connection fails with
   * new setting of "ds-cfg-reject-unauthenticated-requests".
   *
   * @throws UnsupportedEncodingException If an unexpected problem occurs.
   * @throws IOException If an unexpected problem occurs.
   * @throws ClientException If an unexpected problem occurs.
   */
  @Test
  public void testUnauthWAINewCfg()
      throws UnsupportedEncodingException, IOException, ClientException {
    try {
      DirectoryServer.setRejectUnauthenticatedRequests(true);

      Socket s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort());
      LDAPReader reader = new LDAPReader(s);
      LDAPWriter writer = new LDAPWriter(s);
      AtomicInteger nextMessageID = new AtomicInteger(1);
      LDAPAuthenticationHandler authHandler =
          new LDAPAuthenticationHandler(reader, writer, "localhost", nextMessageID);
      ByteString authzID = null;
      try {
        authzID = authHandler.requestAuthorizationIdentity();
      } catch (LDAPException e) {
        assertNull(authzID);
      } finally {
        LDAPMessage unbindMessage =
            new LDAPMessage(nextMessageID.getAndIncrement(), new UnbindRequestProtocolOp());
        writer.writeMessage(unbindMessage);
        s.close();
      }
    } finally {
      DirectoryServer.setRejectUnauthenticatedRequests(false);
    }
  }
Ejemplo n.º 7
0
  /**
   * Once-only initialization.
   *
   * @throws Exception If an unexpected error occurred.
   */
  @BeforeClass
  public void setUp() throws Exception {
    // This test suite depends on having the schema available, so we'll
    // start the server.
    TestCaseUtils.startServer();

    // Initialize schema bits.
    OC_TOP = DirectoryServer.getObjectClass("top");
    OC_PERSON = DirectoryServer.getObjectClass("person");

    AT_OC = DirectoryServer.getObjectClassAttributeType();
    AT_CN = DirectoryServer.getAttributeType("cn");
    AT_SN = DirectoryServer.getAttributeType("sn");
    AT_DESCR = DirectoryServer.getAttributeType("description");
    AT_TELN = DirectoryServer.getAttributeType("telephonenumber");

    // Create a temporary file containing an attribute value.
    TEMP_FILE = File.createTempFile("tmp", "txt");
    OutputStream out = null;
    try {
      out = new FileOutputStream(TEMP_FILE);
      out.write(TEMP_FILE_STRING.getBytes("UTF-8"));
    } finally {
      if (out != null) {
        out.close();
      }
    }
  }
  /**
   * Tests the use of the StartTLS extended operation to communicate with the server in conjunction
   * with no authentication and using blind trust.
   *
   * @throws Exception If an unexpected problem occurs.
   */
  @Test
  public void testStartTLSNoAuthTrustAll() throws Exception {
    try {
      DirectoryServer.setRejectUnauthenticatedRequests(true);

      String[] argSearch = {
        "--noPropertiesFile",
        "-h",
        "127.0.0.1",
        "-p",
        String.valueOf(TestCaseUtils.getServerLdapPort()),
        "-D",
        "cn=directory manager",
        "-w",
        "password",
        "-q",
        "-X",
        "-b",
        "",
        "-s",
        "base",
        "(objectClass=*)"
      };
      assertEquals(LDAPSearch.mainSearch(argSearch, false, null, System.err), 0);
    } finally {
      DirectoryServer.setRejectUnauthenticatedRequests(false);
    }
  }
  /**
   * Tests whether the Who Am I? extended operation with an internal authenticated connection
   * succeeds with default setting of "ds-cfg-reject-unauthenticated-requests".
   *
   * @throws Exception If an unexpected problem occurs.
   */
  @Test()
  public void testAuthWAIDefCfg() throws Exception {
    DirectoryServer.setRejectUnauthenticatedRequests(false);

    Socket s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort());
    LDAPReader reader = new LDAPReader(s);
    LDAPWriter writer = new LDAPWriter(s);

    AtomicInteger nextMessageID = new AtomicInteger(1);
    LDAPAuthenticationHandler authHandler =
        new LDAPAuthenticationHandler(reader, writer, "localhost", nextMessageID);
    authHandler.doSimpleBind(
        3,
        ByteString.valueOf("cn=Directory Manager"),
        ByteString.valueOf("password"),
        new ArrayList<Control>(),
        new ArrayList<Control>());
    ByteString authzID = authHandler.requestAuthorizationIdentity();
    assertNotNull(authzID);

    LDAPMessage unbindMessage =
        new LDAPMessage(nextMessageID.getAndIncrement(), new UnbindRequestProtocolOp());
    writer.writeMessage(unbindMessage);
    s.close();
  }
  /**
   * Tests the use of the StartTLS extended operation to communicate with the server in conjunction
   * with no authentication and using a client trust store to validate the server certificate.
   */
  @Test()
  public void testStartTLSNoAuthTrustStore() {
    String trustStorePath =
        DirectoryServer.getInstanceRoot()
            + File.separator
            + "config"
            + File.separator
            + "client.truststore";

    String[] args = {
      "--noPropertiesFile",
      "-h",
      "127.0.0.1",
      "-p",
      String.valueOf(TestCaseUtils.getServerLdapPort()),
      "-q",
      "-P",
      trustStorePath,
      "-b",
      "",
      "-s",
      "base",
      "(objectClass=*)"
    };

    assertEquals(LDAPSearch.mainSearch(args, false, null, System.err), 0);
  }
Ejemplo n.º 11
0
  /**
   * Test entry.
   *
   * @throws Exception If the test failed unexpectedly.
   */
  @Test()
  public void testEntryToAndFromDatabase() throws Exception {
    // Make sure that the server is up and running.
    TestCaseUtils.startServer();

    // Convert the test LDIF string to a byte array
    byte[] originalLDIFBytes = StaticUtils.getBytes(ldifString);

    LDIFReader reader =
        new LDIFReader(new LDIFImportConfig(new ByteArrayInputStream(originalLDIFBytes)));

    Entry entryBefore, entryAfter;
    while ((entryBefore = reader.readEntry(false)) != null) {
      ByteString bytes = ID2Entry.entryToDatabase(entryBefore, new DataConfig(false, false, null));

      entryAfter = ID2Entry.entryFromDatabase(bytes, DirectoryServer.getDefaultCompressedSchema());

      // check DN and number of attributes
      assertEquals(entryBefore.getAttributes().size(), entryAfter.getAttributes().size());

      assertEquals(entryBefore.getDN(), entryAfter.getDN());

      // check the object classes were not changed
      for (String ocBefore : entryBefore.getObjectClasses().values()) {
        ObjectClass objectClass = DirectoryServer.getObjectClass(ocBefore.toLowerCase());
        if (objectClass == null) {
          objectClass = DirectoryServer.getDefaultObjectClass(ocBefore);
        }
        String ocAfter = entryAfter.getObjectClasses().get(objectClass);

        assertEquals(ocBefore, ocAfter);
      }

      // check the user attributes were not changed
      for (AttributeType attrType : entryBefore.getUserAttributes().keySet()) {
        List<Attribute> listBefore = entryBefore.getAttribute(attrType);
        List<Attribute> listAfter = entryAfter.getAttribute(attrType);

        assertTrue(listAfter != null);

        assertEquals(listBefore.size(), listAfter.size());

        for (Attribute attrBefore : listBefore) {
          boolean found = false;

          for (Attribute attrAfter : listAfter) {
            if (attrAfter.optionsEqual(attrBefore.getOptions())) {
              // Found the corresponding attribute

              assertEquals(attrBefore, attrAfter);
              found = true;
            }
          }

          assertTrue(found);
        }
      }
    }
    reader.close();
  }
  /**
   * Ensures that the Directory Server is running.
   *
   * @throws Exception If an unexpected problem occurs.
   */
  @BeforeClass()
  public void startServer() throws Exception {
    TestCaseUtils.startServer();

    entryDNType = DirectoryConfig.getAttributeType("entrydn", false);
    assertNotNull(entryDNType);
  }
  /**
   * Sets up tests.
   *
   * @throws Exception If the server could not be initialized.
   */
  @BeforeClass
  public void setUp() throws Exception {
    // This test suite depends on having the schema available, so
    // we'll start the server.
    TestCaseUtils.startServer();

    builder = BooleanPropertyDefinition.createBuilder(RootCfgDefn.getInstance(), "test-property");
  }
  /**
   * Tests the {@code getValidatedAuthorizationDN} method for a user that doesn't exist in the
   * directory data.
   *
   * @throws Exception If an unexpected problem occurs.
   */
  @Test(expectedExceptions = {DirectoryException.class})
  public void testGetValidatedAuthorizationNonExistingNormalUser() throws Exception {
    TestCaseUtils.initializeTestBackend(true);

    ProxiedAuthV1Control proxyControl = new ProxiedAuthV1Control(DN.decode("uid=test,o=test"));

    proxyControl.getAuthorizationEntry();
  }
 /**
  * Tests the {@code appliesToEntry} method.
  *
  * @param rule The rule for which to perform the test.
  * @param appliesToEntry Indicates whether the provided rule applies to a minimal "o=test" entry.
  * @throws Exception If an unexpected problem occurs.
  */
 @Test(dataProvider = "testRules")
 public void testAppliesToEntry(VirtualAttributeRule rule, boolean appliesToEntry)
     throws Exception {
   TestCaseUtils.initializeTestBackend(true);
   addGroups();
   assertEquals(
       rule.appliesToEntry(DirectoryConfig.getEntry(DN.decode("o=test"))), appliesToEntry);
   removeGroups();
 }
  /**
   * Tests the {@code getValidatedAuthorizationDN} method for a normal user that exists in the
   * directory data and doesn't have any restrictions on its use.
   *
   * @throws Exception If an unexpected problem occurs.
   */
  @Test()
  public void testGetValidatedAuthorizationExistingNormalUser() throws Exception {
    TestCaseUtils.initializeTestBackend(true);
    TestCaseUtils.addEntry(
        "dn: uid=test,o=test",
        "objectClass: top",
        "objectClass: person",
        "objectClass: organizationalPerson",
        "objectClass: inetOrgPerson",
        "uid: test",
        "givenName: Test",
        "sn: User",
        "cn: Test User");

    ProxiedAuthV1Control proxyControl = new ProxiedAuthV1Control(DN.decode("uid=test,o=test"));

    assertEquals(proxyControl.getAuthorizationEntry().getDN(), DN.decode("uid=test,o=test"));
  }
Ejemplo n.º 17
0
  @BeforeClass
  public void setUp() throws Exception {
    // The server must be running for these tests, so that
    // it can provide "getServerRoot()".
    TestCaseUtils.startServer();

    resourcePath =
        DirectoryServer.getInstanceRoot() + File.separator + "config" + File.separator + "MakeLDIF";
  }
  /**
   * Performs a failed LDAP bind using CRAM-MD5 using the dn: form of the authentication ID with the
   * DN of a user that doesn't exist.
   *
   * @throws Exception If an unexpected problem occurs.
   */
  @Test()
  public void testLDAPBindFailNoSuchUser() throws Exception {
    TestCaseUtils.initializeTestBackend(true);

    Entry e =
        TestCaseUtils.makeEntry(
            "dn: uid=test.user,o=test",
            "objectClass: top",
            "objectClass: person",
            "objectClass: organizationalPerson",
            "objectClass: inetOrgPerson",
            "uid: test.user",
            "givenName: Test",
            "sn: User",
            "cn: Test User",
            "userPassword: password");

    InternalClientConnection conn = InternalClientConnection.getRootConnection();
    AddOperation addOperation =
        conn.processAdd(
            e.getDN(), e.getObjectClasses(),
            e.getUserAttributes(), e.getOperationalAttributes());
    assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS);

    String[] args = {
      "--noPropertiesFile",
      "-h",
      "127.0.0.1",
      "-p",
      String.valueOf(TestCaseUtils.getServerLdapPort()),
      "-o",
      "mech=CRAM-MD5",
      "-o",
      "authid=dn:uid=doesntexist,o=test",
      "-w",
      "password",
      "-b",
      "",
      "-s",
      "base",
      "(objectClass=*)"
    };
    assertFalse(LDAPSearch.mainSearch(args, false, null, null) == 0);
  }
Ejemplo n.º 19
0
 private File createCleanDir() throws IOException {
   String buildRoot = System.getProperty(TestCaseUtils.PROPERTY_BUILD_ROOT);
   String path =
       System.getProperty(TestCaseUtils.PROPERTY_BUILD_DIR, buildRoot + File.separator + "build");
   path = path + File.separator + "unit-tests" + File.separator + "JEReplicaDB";
   final File testRoot = new File(path);
   TestCaseUtils.deleteDirectory(testRoot);
   testRoot.mkdirs();
   return testRoot;
 }
  /**
   * Tests the {@code getValidatedAuthorizationDN} method for a disabled user.
   *
   * @throws Exception If an unexpected problem occurs.
   */
  @Test(expectedExceptions = {DirectoryException.class})
  public void testGetValidatedAuthorizationDisabledUser() throws Exception {
    TestCaseUtils.initializeTestBackend(true);
    TestCaseUtils.addEntry(
        "dn: uid=test,o=test",
        "objectClass: top",
        "objectClass: person",
        "objectClass: organizationalPerson",
        "objectClass: inetOrgPerson",
        "uid: test",
        "givenName: Test",
        "sn: User",
        "cn: Test User",
        "ds-pwp-account-disabled: true");

    ProxiedAuthV1Control proxyControl = new ProxiedAuthV1Control(DN.decode("uid=test,o=test"));

    proxyControl.getAuthorizationEntry();
  }
  /**
   * Tests whether both authenticated and unauthenticated SEARCH requests will be allowed with the
   * new configuration settings for "ds-cfg-reject-unauthenticated-requests" .
   */
  @Test
  public void testSearchNewCfg() {
    try {
      DirectoryServer.setRejectUnauthenticatedRequests(true);

      String[] args = {
        "--noPropertiesFile",
        "-h",
        "127.0.0.1",
        "-p",
        String.valueOf(TestCaseUtils.getServerLdapPort()),
        "-b",
        "",
        "-s",
        "base",
        "(objectClass=*)"
      };

      assertFalse(LDAPSearch.mainSearch(args, false, null, null) == 0);

      String[] authArgs = {
        "--noPropertiesFile",
        "-h",
        "127.0.0.1",
        "-p",
        String.valueOf(TestCaseUtils.getServerLdapPort()),
        "-D",
        "cn=Directory Manager",
        "-w",
        "password",
        "-b",
        "",
        "-s",
        "base",
        "(objectClass=*)"
      };
      assertEquals(LDAPSearch.mainSearch(authArgs, false, null, System.err), 0);
    } finally {
      DirectoryServer.setRejectUnauthenticatedRequests(false);
    }
  }
Ejemplo n.º 22
0
  @Test
  public void testTrim() throws Exception {
    ReplicationServer replicationServer = null;
    JEReplicaDB replicaDB = null;
    try {
      TestCaseUtils.startServer();
      replicationServer = configureReplicationServer(100, 5000);
      replicaDB = newReplicaDB(replicationServer);

      CSN[] csns = generateCSNs(1, 0, 5);

      replicaDB.add(new DeleteMsg(TEST_ROOT_DN, csns[0], "uid"));
      replicaDB.add(new DeleteMsg(TEST_ROOT_DN, csns[1], "uid"));
      replicaDB.add(new DeleteMsg(TEST_ROOT_DN, csns[2], "uid"));
      DeleteMsg update4 = new DeleteMsg(TEST_ROOT_DN, csns[3], "uid");

      // --
      // Iterator tests with changes persisted
      assertFoundInOrder(replicaDB, csns[0], csns[1], csns[2]);
      assertNotFound(replicaDB, csns[4], AFTER_MATCHING_KEY);

      assertEquals(replicaDB.getOldestCSN(), csns[0]);
      assertEquals(replicaDB.getNewestCSN(), csns[2]);

      // --
      // Cursor tests with changes persisted
      replicaDB.add(update4);

      assertFoundInOrder(replicaDB, csns[0], csns[1], csns[2], csns[3]);
      // Test cursor from existing CSN
      assertFoundInOrder(replicaDB, csns[2], csns[3]);
      assertFoundInOrder(replicaDB, csns[3]);
      assertNotFound(replicaDB, csns[4], AFTER_MATCHING_KEY);

      replicaDB.purgeUpTo(new CSN(Long.MAX_VALUE, 0, 0));

      int count = 0;
      boolean purgeSucceeded = false;
      final CSN expectedNewestCSN = csns[3];
      do {
        Thread.sleep(10);

        final CSN oldestCSN = replicaDB.getOldestCSN();
        final CSN newestCSN = replicaDB.getNewestCSN();
        purgeSucceeded = oldestCSN.equals(expectedNewestCSN) && newestCSN.equals(expectedNewestCSN);
        count++;
      } while (!purgeSucceeded && count < 100);
      assertTrue(purgeSucceeded);
    } finally {
      shutdown(replicaDB);
      remove(replicationServer);
    }
  }
 /**
  * Utility method which is called by the testcase sending an ADD request.
  *
  * @param authentication The flag to set the authentication on and off.
  * @return The error code of operation performed.
  * @throws Exception If an unexpected problem occurs.
  */
 private int performAddOperation(boolean authentication) throws Exception {
   String filePath =
       TestCaseUtils.createTempFile(
           "dn: o=rejectTestCase,o=test",
           "objectclass: top",
           "objectclass: organization",
           "o: rejectTestCase",
           "description: Reject Test Case");
   String[] args = null;
   if (authentication)
     args =
         new String[] {
           "--noPropertiesFile",
           "-h",
           "127.0.0.1",
           "-p",
           String.valueOf(TestCaseUtils.getServerLdapPort()),
           "-D",
           "cn=directory manager",
           "-w",
           "password",
           "-a",
           "-f",
           filePath,
         };
   else
     args =
         new String[] {
           "--noPropertiesFile",
           "-h",
           "127.0.0.1",
           "-p",
           String.valueOf(TestCaseUtils.getServerLdapPort()),
           "-a",
           "-f",
           filePath,
         };
   return LDAPModify.mainModify(args, false, null, null);
 }
 /**
  * Adds a group to the server in which the "o=test" entry is a member.
  *
  * @throws Exception If an unexpected problem occurs.
  */
 private void addGroups() throws Exception {
   TestCaseUtils.addEntries(
       "dn: cn=Test Group,o=test",
       "objectClass: top",
       "objectClass: groupOfUniqueNames",
       "cn: Test Group",
       "uniqueMember: o=test",
       "",
       "dn: cn=Example Group,o=test",
       "objectClass: top",
       "objectClass: groupOfUniqueNames",
       "cn: Example Group",
       "uniqueMember: dc=example,dc=com");
 }
 /**
  * Utility method which is called by the testcase sending a MODRDN request.
  *
  * @param authentication The flag to set the authentication on and off.
  * @return The error code of operation performed.
  * @throws Exception If an unexpected problem occurs.
  */
 private int performModRdnOperation(boolean authentication) throws Exception {
   String path =
       TestCaseUtils.createTempFile(
           "dn: o=rejectTestCase,o=Test",
           "changetype: modrdn",
           "newrdn: o=mod_rejectTestCase",
           "deleteoldrdn: 0");
   String[] args = null;
   if (authentication)
     args =
         new String[] {
           "--noPropertiesFile",
           "-h",
           "127.0.0.1",
           "-p",
           String.valueOf(TestCaseUtils.getServerLdapPort()),
           "-D",
           "cn=directory manager",
           "-w",
           "password",
           "-f",
           path
         };
   else
     args =
         new String[] {
           "--noPropertiesFile",
           "-h",
           "127.0.0.1",
           "-p",
           String.valueOf(TestCaseUtils.getServerLdapPort()),
           "-f",
           path
         };
   return LDAPModify.mainModify(args, false, null, null);
 }
  /**
   * Tests the use of the StartTLS extended operation to communicate with the server in conjunction
   * with no authentication and using blind trust.
   */
  @Test()
  public void testStartTLSNoAuthTrustAll() {
    String[] args = {
      "--noPropertiesFile",
      "-h",
      "127.0.0.1",
      "-p",
      String.valueOf(TestCaseUtils.getServerLdapPort()),
      "-q",
      "-X",
      "-b",
      "",
      "-s",
      "base",
      "(objectClass=*)"
    };

    assertEquals(LDAPSearch.mainSearch(args, false, null, System.err), 0);
  }
  /**
   * Tests whether an unauthenticated SEARCH request will be allowed with the default configuration
   * settings for "ds-cfg-reject-unauthenticated-requests".
   */
  @Test()
  public void testUnauthSearchDefCfg() {
    DirectoryServer.setRejectUnauthenticatedRequests(false);

    String[] args = {
      "--noPropertiesFile",
      "-h",
      "127.0.0.1",
      "-p",
      String.valueOf(TestCaseUtils.getServerLdapPort()),
      "-b",
      "",
      "-s",
      "base",
      "(objectClass=*)"
    };

    assertEquals(LDAPSearch.mainSearch(args, false, null, System.err), 0);
  }
  /**
   * Make sure that the server is running.
   *
   * @throws Exception If an unexpected problem occurs.
   */
  @BeforeClass()
  public void startServer() throws Exception {
    TestCaseUtils.startServer();

    givenNameType = DirectoryServer.getAttributeType("givenname", false);
    assertNotNull(givenNameType);

    snType = DirectoryServer.getAttributeType("sn", false);
    assertNotNull(snType);

    aaccfJohnsonDN = DN.decode("uid=aaccf.johnson,dc=example,dc=com");
    aaronZimmermanDN = DN.decode("uid=aaron.zimmerman,dc=example,dc=com");
    albertSmithDN = DN.decode("uid=albert.smith,dc=example,dc=com");
    albertZimmermanDN = DN.decode("uid=albert.zimmerman,dc=example,dc=com");
    lowercaseMcGeeDN = DN.decode("uid=lowercase.mcgee,dc=example,dc=com");
    margaretJonesDN = DN.decode("uid=margaret.jones,dc=example,dc=com");
    maryJonesDN = DN.decode("uid=mary.jones,dc=example,dc=com");
    samZweckDN = DN.decode("uid=sam.zweck,dc=example,dc=com");
    zorroDN = DN.decode("uid=zorro,dc=example,dc=com");
  }
Ejemplo n.º 29
0
  /**
   * Tests the entry encoding and decoding process the version 1 encoding.
   *
   * @throws Exception If the test failed unexpectedly.
   */
  @Test()
  public void testEntryToAndFromDatabaseV1() throws Exception {
    // Make sure that the server is up and running.
    TestCaseUtils.startServer();

    // Convert the test LDIF string to a byte array
    byte[] originalLDIFBytes = StaticUtils.getBytes(ldifString);

    LDIFReader reader =
        new LDIFReader(new LDIFImportConfig(new ByteArrayInputStream(originalLDIFBytes)));

    Entry entryBefore, entryAfterV1;
    while ((entryBefore = reader.readEntry(false)) != null) {
      ByteStringBuilder bsb = new ByteStringBuilder();
      encodeV1(entryBefore, bsb);
      entryAfterV1 = Entry.decode(bsb.asReader());

      assertEquals(entryBefore, entryAfterV1);
    }
    reader.close();
  }
 /**
  * Performs a failed LDAP bind using CRAM-MD5 using the dn: form of the authentication ID with the
  * root DN (which has a stored password that's not reversible).
  *
  * @throws Exception If an unexpected problem occurs.
  */
 @Test()
 public void testLDAPBindFailIrreversiblePasswordWithRootDN() throws Exception {
   String[] args = {
     "--noPropertiesFile",
     "-h",
     "127.0.0.1",
     "-p",
     String.valueOf(TestCaseUtils.getServerLdapPort()),
     "-o",
     "mech=CRAM-MD5",
     "-o",
     "authid=dn:cn=Directory Manager",
     "-w",
     "password",
     "-b",
     "",
     "-s",
     "base",
     "(objectClass=*)"
   };
   assertFalse(LDAPSearch.mainSearch(args, false, null, null) == 0);
 }