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

Valery Kharseko
29.50.2024 d4504ff2f15951c610675e691d8bcd48986e3f89
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
 * The contents of this file are subject to the terms of the Common Development and
 * Distribution License (the License). You may not use this file except in compliance with the
 * License.
 *
 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
 * specific language governing permission and limitations under the License.
 *
 * When distributing Covered Software, include this CDDL Header Notice in each file and include
 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
 * Header, with the fields enclosed by brackets [] replaced by your own identifying
 * information: "Portions Copyright [year] [name of copyright owner]".
 *
 * Copyright 2024 3A Systems, LLC.
 */
package org.opends.server.extensions;
 
import org.opends.server.TestCaseUtils;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
 
import static org.testng.Assert.*;
 
/**
 * A set of test cases for the governing structure rule virtual attribute
 * provider.
 */
public class Issue425TestCase
       extends ExtensionsTestCase
{
 
  /**
   * Ensures that the Directory Server is running.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @BeforeClass
  public void startServer()
         throws Exception
  {
    TestCaseUtils.startServer();
    TestCaseUtils.initializeTestBackend(true);
    TestCaseUtils.clearBackend("userRoot", "dc=example,dc=com");
 
    int resultCode = TestCaseUtils.applyModifications(true,
    "dn: cn=schema",
    "changetype: modify",
    "add: nameForms",
    "nameForms: ( 1.3.6.1.1.2.1\n" +
            "          NAME 'domainNameForm'\n" +
            "          OC domain\n" +
            "          MUST dc\n" +
            "          X-ORIGIN 'RFC2377' )",
    "nameForms: ( 1.3.6.1.4.1.56521.999.2.7.2\n" +
            "          NAME 'ouForm'\n" +
            "          OC organizationalUnit\n" +
            "          MUST ou\n" +
            "          X-ORIGIN 'fake name form' )",
    "-",
    "add: ditStructureRules",
    "dITStructureRules: ( 20\n" +
            "          NAME 'rootSuffixStructure'\n" +
            "          FORM domainNameForm )",
    "dITStructureRules: ( 21\n" +
            "          NAME 'ouStructure'\n" +
            "          FORM ouForm\n" +
            "          SUP 20 )"
    );
    assertEquals(resultCode, 0);
  }
 
    @Test
    public void test()
            throws Exception {
      TestCaseUtils.addEntry(
              "dn: ou=Accounts,dc=example,dc=com",
              "objectClass: organizationalunit",
              "objectClass: top",
              "ou: People"
      );
      //add OC subentry without DSR (warning level)
      TestCaseUtils.addEntry(
              "dn: cn=test-subentry,ou=Accounts,dc=example,dc=com",
              "objectClass: top",
              "objectClass: extensibleObject",
              "objectClass: subentry",
              "objectClass: collectiveAttributeSubentry",
              "subtreeSpecification: {}",
              "cn: test-subentry"
      );
      //add OC subentry without DSR (warning level)
      TestCaseUtils.addEntry(
              "dn: o=test-subentry2,ou=Accounts,dc=example,dc=com",
              "objectClass: top",
              "objectClass: extensibleObject",
              "objectClass: subentry",
              "objectClass: collectiveAttributeSubentry",
              "subtreeSpecification: {}",
              "cn: test-subentry2"
      );
 
      int resultCode = TestCaseUtils.applyModifications(true,
              "dn: cn=schema",
              "changetype: modify",
              "add: nameForms",
              "nameForms: ( 2.5.15.16\n"+
                      "          NAME 'subentryNameForm'\n"+
                      "          DESC 'X.501, cl. 14.2.2: the Subentry name form'\n"+
                      "          OC subentry\n"+
                      "          MUST cn )",
              "-",
              "add: ditStructureRules",
              "dITStructureRules: ( 177\n"+
                      "          NAME 'subentryStructure'\n"+
                      "          FORM subentryNameForm\n"+
                      "          SUP ( 20 21 ) )"
      );
      assertEquals(resultCode, 0);
 
      //add OC subentry with DSR: RDN OC subentry MUST cn
      TestCaseUtils.addEntry(
              "dn: cn=test-subentry-ok,ou=Accounts,dc=example,dc=com",
              "objectClass: top",
              "objectClass: extensibleObject",
              "objectClass: subentry",
              "objectClass: collectiveAttributeSubentry",
              "subtreeSpecification: {}",
              "cn: test-subentry-ok"
      );
 
      //add OC subentry with DSR violation: RDN OC subentry MUST cn
      assertThrows(new ThrowingRunnable() {
                     @Override
                     public void run() throws Throwable {
                       TestCaseUtils.addEntry(
                               "dn: o=test-subentry-error,ou=Accounts,dc=example,dc=com",
                               "objectClass: top",
                               "objectClass: extensibleObject",
                               "objectClass: subentry",
                               "objectClass: collectiveAttributeSubentry",
                               "subtreeSpecification: {}",
                               "cn: test-subentry-error"
                       );
                     }
                   }
      );
    }
}