mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Ludovic Poitou
03.00.2016 926e18c1f9944d6504df5d627525f922fc5eac0c
Fixed tests names and added a test to verify Virtual Attribute provided Password Policy on Add operation.
1 files modified
108 ■■■■■ changed files
opendj-server-legacy/src/test/java/org/opends/server/extensions/UserDefinedVirtualAttributeProviderTestCase.java 108 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/extensions/UserDefinedVirtualAttributeProviderTestCase.java
@@ -50,12 +50,6 @@
  /** The attribute type for the description attribute. */
  private AttributeType descriptionType;
  /** The attribute type for the ds-privilege-name attribute. */
  private AttributeType privNameType;
  /** The attribute type for the ds-pwp-password-policy-dn attribute. */
  private AttributeType pwPolicyDNType;
  /**
   * Ensures that the Directory Server is running.
@@ -69,8 +63,6 @@
    TestCaseUtils.startServer();
    descriptionType = CoreSchema.getDescriptionAttributeType();
    pwPolicyDNType = DirectoryServer.getSchema().getAttributeType("ds-pwp-password-policy-dn");
    privNameType = DirectoryServer.getSchema().getAttributeType("ds-privilege-name");
  }
@@ -583,25 +575,10 @@
  }
  /**
   * Tests to ensure that the user-defined virtual attribute provider can be
   * used to grant a privilege to a user.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Test
  public void testVirtualPrivilege()
         throws Exception
  private void testSetupVirtualPasswordPolicyDN(String policyDN, String ruleDN) throws Exception
  {
    TestCaseUtils.initializeTestBackend(true);
    String policyDN = "cn=Test Policy,cn=Password Policies,cn=config";
    String ruleDN   = "cn=User-Defined Test,cn=Virtual Attributes,cn=config";
    String userDN   = "uid=test.user,o=test";
    TestCaseUtils.addEntries(
      "dn: cn=Test Policy,cn=Password Policies,cn=config",
            "dn: " + policyDN,
      "objectClass: top",
      "objectClass: ds-cfg-password-policy",
      "cn: Test Policy",
@@ -641,8 +618,29 @@
      "ds-cfg-enabled: true",
      "ds-cfg-attribute-type: ds-pwp-password-policy-dn",
      "ds-cfg-conflict-behavior: merge-real-and-virtual",
      "ds-cfg-value: " + policyDN,
      "",
            "ds-cfg-value: " + policyDN);
  }
  /**
   * Tests to ensure that the user-defined virtual attribute provider can be
   * used to apply a custom password policy for a user.  The custom password
   * policy will reject passwords shorter than six characters, whereas the
   * default policy will not.
   */
  @Test
  public void testVirtualPasswordPolicyDN() throws Exception
  {
    TestCaseUtils.initializeTestBackend(true);
    String policyDN = "cn=Test Policy,cn=Password Policies,cn=config";
    String ruleDN   = "cn=User-Defined Test,cn=Virtual Attributes,cn=config";
    String userDN   = "uid=test.user,o=test";
    testSetupVirtualPasswordPolicyDN(policyDN, ruleDN);
    try
    {
      assertEquals(TestCaseUtils.addEntryOperation(
      "dn: " + userDN,
      "objectClass: top",
      "objectClass: person",
@@ -652,10 +650,9 @@
      "givenName: Test",
      "sn: User",
      "cn: Test User",
      "userPassword: testtest");
              "userPassword: testtest"),
              ResultCode.SUCCESS);
    try
    {
      String path1 =
          TestCaseUtils.createTempFile("dn: " + userDN,
              "changetype: modify", "replace: userPassword",
@@ -681,7 +678,6 @@
      assertEquals(LDAPModify.mainModify(args2, false, null, null), 0);
      assertEquals(LDAPModify.mainModify(args1, false, null, null), 0);
    }
    finally
    {
@@ -696,18 +692,52 @@
  }
  /**
   * Tests to ensure that the user-defined virtual attribute provider can be used to apply a custom password
   * policy for a user. The custom password policy will reject passwords shorter than six characters,
   * whereas the default policy will not. This test verifies that adding a user with a short password fails.
   */
  @Test
  public void testVirtualPasswordPolicyDNForAdd() throws Exception
  {
    TestCaseUtils.initializeTestBackend(true);
    String policyDN = "cn=Test Policy,cn=Password Policies,cn=config";
    String ruleDN   = "cn=User-Defined Test,cn=Virtual Attributes,cn=config";
    testSetupVirtualPasswordPolicyDN(policyDN, ruleDN);
    try {
      assertEquals(TestCaseUtils.addEntryOperation(
              "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: test"
      ), ResultCode.CONSTRAINT_VIOLATION);
    }
    finally {
      InternalClientConnection conn = getRootConnection();
      DeleteOperation deleteOperation = conn.processDelete(DN.valueOf(ruleDN));
      assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS);
      deleteOperation = conn.processDelete(DN.valueOf(policyDN));
      assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS);
    }
  }
  /**
   * Tests to ensure that the user-defined virtual attribute provider can be
   * used to apply a custom password policy for a user.  The custom password
   * policy will reject passwords shorter than six characters, whereas the
   * default policy will not.
   *
   * @throws  Exception  If an unexpected problem occurs.
   * used to grant a privilege to a user.
   */
  @Test
  public void testVirtualPasswordPolicyDN()
         throws Exception
  public void testVirtualPrivilege() throws Exception
  {
    TestCaseUtils.initializeTestBackend(true);
@@ -738,7 +768,6 @@
      "cn: Test User",
      "userPassword: password");
    try
    {
      String path1 =
@@ -766,7 +795,6 @@
      assertEquals(LDAPModify.mainModify(args2, false, null, null), 0);
      assertEquals(LDAPModify.mainModify(args1, false, null, null), 0);
    }
    finally
    {