1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.directory.server.core.subtree;
21
22 import org.apache.directory.server.core.DirectoryService;
23 import org.apache.directory.server.core.integ.CiRunner;
24 import static org.apache.directory.server.core.integ.IntegrationUtils.getSystemContext;
25 import org.apache.directory.shared.ldap.constants.SchemaConstants;
26 import org.apache.directory.shared.ldap.exception.LdapNoSuchAttributeException;
27 import org.apache.directory.shared.ldap.message.SubentriesControl;
28 import static org.junit.Assert.assertEquals;
29 import static org.junit.Assert.assertTrue;
30 import static org.junit.Assert.assertFalse;
31 import static org.junit.Assert.assertNull;
32 import static org.junit.Assert.assertNotNull;
33 import static org.junit.Assert.fail;
34 import org.junit.Ignore;
35 import org.junit.Test;
36 import org.junit.runner.RunWith;
37
38 import javax.naming.NamingEnumeration;
39 import javax.naming.directory.Attribute;
40 import javax.naming.directory.Attributes;
41 import javax.naming.directory.BasicAttribute;
42 import javax.naming.directory.BasicAttributes;
43 import javax.naming.directory.DirContext;
44 import javax.naming.directory.ModificationItem;
45 import javax.naming.directory.SearchControls;
46 import javax.naming.directory.SearchResult;
47 import javax.naming.ldap.Control;
48 import javax.naming.ldap.LdapContext;
49 import java.util.HashMap;
50 import java.util.Map;
51
52
53
54
55
56
57
58
59 @RunWith ( CiRunner.class )
60 @Ignore
61 public class SubentryServiceIT
62 {
63 public static DirectoryService service;
64
65
66 public Attributes getTestEntry( String cn )
67 {
68 Attributes subentry = new BasicAttributes( true );
69 Attribute objectClass = new BasicAttribute( "objectClass" );
70 objectClass.add( "top" );
71 objectClass.add( "person" );
72 subentry.put( objectClass );
73 subentry.put( "cn", cn );
74 subentry.put( "sn", "testentry" );
75 return subentry;
76 }
77
78
79 public Attributes getTestSubentry()
80 {
81 Attributes subentry = new BasicAttributes( true );
82 Attribute objectClass = new BasicAttribute( "objectClass" );
83 objectClass.add( "top" );
84 objectClass.add( SchemaConstants.SUBENTRY_OC );
85 objectClass.add( "collectiveAttributeSubentry" );
86 subentry.put( objectClass );
87 subentry.put( "subtreeSpecification", "{ base \"ou=configuration\" }" );
88 subentry.put( "c-o", "Test Org" );
89 subentry.put( "cn", "testsubentry" );
90 return subentry;
91 }
92
93
94 public Attributes getTestSubentryWithExclusion()
95 {
96 Attributes subentry = new BasicAttributes( true );
97 Attribute objectClass = new BasicAttribute( "objectClass" );
98 objectClass.add( "top" );
99 objectClass.add( SchemaConstants.SUBENTRY_OC );
100 objectClass.add( "collectiveAttributeSubentry" );
101 subentry.put( objectClass );
102 String spec = "{ base \"ou=configuration\", specificExclusions { chopBefore:\"cn=unmarked\" } }";
103 subentry.put( "subtreeSpecification", spec );
104 subentry.put( "c-o", "Test Org" );
105 subentry.put( "cn", "testsubentry" );
106 return subentry;
107 }
108
109
110 public void addAdministrativeRole( String role ) throws Exception
111 {
112 LdapContext sysRoot = getSystemContext( service );
113 Attribute attribute = new BasicAttribute( "administrativeRole" );
114 attribute.add( role );
115 ModificationItem item = new ModificationItem( DirContext.ADD_ATTRIBUTE, attribute );
116 sysRoot.modifyAttributes( "", new ModificationItem[]
117 { item } );
118 }
119
120
121 public Map<String, Attributes> getAllEntries() throws Exception
122 {
123 LdapContext sysRoot = getSystemContext( service );
124 Map<String, Attributes> resultMap = new HashMap<String, Attributes>();
125 SearchControls controls = new SearchControls();
126 controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
127 controls.setReturningAttributes( new String[]
128 { "+", "*" } );
129 NamingEnumeration<SearchResult> results = sysRoot.search( "", "(objectClass=*)", controls );
130
131 while ( results.hasMore() )
132 {
133 SearchResult result = results.next();
134 resultMap.put( result.getName(), result.getAttributes() );
135 }
136
137 return resultMap;
138 }
139
140
141 @Test
142 public void testEntryAdd() throws Exception
143 {
144 LdapContext sysRoot = getSystemContext( service );
145 addAdministrativeRole( "collectiveArributeSpecificArea" );
146 sysRoot.createSubcontext( "cn=testsubentry", getTestSubentry() );
147 sysRoot.createSubcontext( "cn=unmarked", getTestEntry( "unmarked" ) );
148 sysRoot.createSubcontext( "cn=marked,ou=configuration", getTestEntry( "marked" ) );
149 Map<String, Attributes> results = getAllEntries();
150
151
152
153
154
155 Attributes marked = results.get( "cn=marked,ou=configuration,ou=system" );
156 Attribute collectiveAttributeSubentries = marked.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT );
157 assertNotNull( "ou=marked,ou=configuration,ou=system should be marked", collectiveAttributeSubentries );
158 assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", collectiveAttributeSubentries.get() );
159 assertEquals( 1, collectiveAttributeSubentries.size() );
160
161
162
163
164
165 Attributes unmarked = results.get( "cn=unmarked,ou=system" );
166 assertNull( "cn=unmarked,ou=system should not be marked", unmarked
167 .get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
168 }
169
170
171 @Test
172 public void testSubentryAdd() throws Exception
173 {
174 LdapContext sysRoot = getSystemContext( service );
175 try
176 {
177 sysRoot.createSubcontext( "cn=testsubentry", getTestSubentry() );
178 fail( "should never get here: cannot create subentry under regular entries" );
179 }
180 catch ( LdapNoSuchAttributeException e )
181 {
182 }
183
184 addAdministrativeRole( "collectiveArributeSpecificArea" );
185 sysRoot.createSubcontext( "cn=testsubentry", getTestSubentry() );
186 Map<String, Attributes> results = getAllEntries();
187
188
189
190
191
192 Attributes configuration = results.get( "ou=configuration,ou=system" );
193 Attribute collectiveAttributeSubentries = configuration.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT );
194 assertNotNull( "ou=configuration,ou=system should be marked", collectiveAttributeSubentries );
195 assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", collectiveAttributeSubentries.get() );
196 assertEquals( 1, collectiveAttributeSubentries.size() );
197
198 Attributes interceptors = results.get( "ou=interceptors,ou=configuration,ou=system" );
199 collectiveAttributeSubentries = interceptors.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT );
200 assertNotNull( "ou=interceptors,ou=configuration,ou=system should be marked", collectiveAttributeSubentries );
201 assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", collectiveAttributeSubentries.get() );
202 assertEquals( 1, collectiveAttributeSubentries.size() );
203
204 Attributes partitions = results.get( "ou=partitions,ou=configuration,ou=system" );
205 collectiveAttributeSubentries = partitions.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT );
206 assertNotNull( "ou=partitions,ou=configuration,ou=system should be marked", collectiveAttributeSubentries );
207 assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", collectiveAttributeSubentries.get() );
208 assertEquals( 1, collectiveAttributeSubentries.size() );
209
210 Attributes services = results.get( "ou=services,ou=configuration,ou=system" );
211 collectiveAttributeSubentries = services.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT );
212 assertNotNull( "ou=services,ou=configuration,ou=system should be marked", collectiveAttributeSubentries );
213 assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", collectiveAttributeSubentries.get() );
214 assertEquals( 1, collectiveAttributeSubentries.size() );
215
216
217
218
219
220 Attributes system = results.get( "ou=system" );
221 assertNull( "ou=system should not be marked", system.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
222
223 Attributes users = results.get( "ou=users,ou=system" );
224 assertNull( "ou=users,ou=system should not be marked", users.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
225
226 Attributes groups = results.get( "ou=groups,ou=system" );
227 assertNull( "ou=groups,ou=system should not be marked", groups.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
228
229 Attributes admin = results.get( "uid=admin,ou=system" );
230 assertNull( "uid=admin,ou=system should not be marked", admin.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
231
232 Attributes sysPrefRoot = results.get( "prefNodeName=sysPrefRoot,ou=system" );
233 assertNull( "prefNode=sysPrefRoot,ou=system should not be marked", sysPrefRoot
234 .get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
235
236 }
237
238
239 @Test
240 public void testSubentryModify() throws Exception
241 {
242 LdapContext sysRoot = getSystemContext( service );
243 addAdministrativeRole( "collectiveArributeSpecificArea" );
244 sysRoot.createSubcontext( "cn=testsubentry", getTestSubentry() );
245 Map<String, Attributes> results = getAllEntries();
246
247
248
249
250
251 Attributes configuration = results.get( "ou=configuration,ou=system" );
252 Attribute collectiveAttributeSubentries = configuration.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT );
253 assertNotNull( "ou=configuration,ou=system should be marked", collectiveAttributeSubentries );
254 assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", collectiveAttributeSubentries.get() );
255 assertEquals( 1, collectiveAttributeSubentries.size() );
256
257 Attributes interceptors = results.get( "ou=interceptors,ou=configuration,ou=system" );
258 collectiveAttributeSubentries = interceptors.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT );
259 assertNotNull( "ou=interceptors,ou=configuration,ou=system should be marked", collectiveAttributeSubentries );
260 assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", collectiveAttributeSubentries.get() );
261 assertEquals( 1, collectiveAttributeSubentries.size() );
262
263 Attributes partitions = results.get( "ou=partitions,ou=configuration,ou=system" );
264 collectiveAttributeSubentries = partitions.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT );
265 assertNotNull( "ou=partitions,ou=configuration,ou=system should be marked", collectiveAttributeSubentries );
266 assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", collectiveAttributeSubentries.get() );
267 assertEquals( 1, collectiveAttributeSubentries.size() );
268
269 Attributes services = results.get( "ou=services,ou=configuration,ou=system" );
270 collectiveAttributeSubentries = services.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT );
271 assertNotNull( "ou=services,ou=configuration,ou=system should be marked", collectiveAttributeSubentries );
272 assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", collectiveAttributeSubentries.get() );
273 assertEquals( 1, collectiveAttributeSubentries.size() );
274
275
276
277
278
279 Attributes system = results.get( "ou=system" );
280 assertNull( "ou=system should not be marked", system.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
281
282 Attributes users = results.get( "ou=users,ou=system" );
283 assertNull( "ou=users,ou=system should not be marked", users.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
284
285 Attributes groups = results.get( "ou=groups,ou=system" );
286 assertNull( "ou=groups,ou=system should not be marked", groups.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
287
288 Attributes admin = results.get( "uid=admin,ou=system" );
289 assertNull( "uid=admin,ou=system should not be marked", admin.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
290
291 Attributes sysPrefRoot = results.get( "prefNodeName=sysPrefRoot,ou=system" );
292 assertNull( "prefNode=sysPrefRoot,ou=system should not be marked", sysPrefRoot
293 .get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
294
295
296
297
298
299 Attribute subtreeSpecification = new BasicAttribute( "subtreeSpecification" );
300 subtreeSpecification.add( "{ base \"ou=configuration\", specificExclusions { chopBefore:\"ou=services\" } }" );
301 ModificationItem item = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, subtreeSpecification );
302 sysRoot.modifyAttributes( "cn=testsubentry", new ModificationItem[]
303 { item } );
304 results = getAllEntries();
305
306
307
308
309
310 configuration = results.get( "ou=configuration,ou=system" );
311 collectiveAttributeSubentries = configuration.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT );
312 assertNotNull( "ou=configuration,ou=system should be marked", collectiveAttributeSubentries );
313 assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", collectiveAttributeSubentries.get() );
314 assertEquals( 1, collectiveAttributeSubentries.size() );
315
316 interceptors = results.get( "ou=interceptors,ou=configuration,ou=system" );
317 collectiveAttributeSubentries = interceptors.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT );
318 assertNotNull( "ou=interceptors,ou=configuration,ou=system should be marked", collectiveAttributeSubentries );
319 assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", collectiveAttributeSubentries.get() );
320 assertEquals( 1, collectiveAttributeSubentries.size() );
321
322 partitions = results.get( "ou=partitions,ou=configuration,ou=system" );
323 collectiveAttributeSubentries = partitions.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT );
324 assertNotNull( "ou=partitions,ou=configuration,ou=system should be marked", collectiveAttributeSubentries );
325 assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", collectiveAttributeSubentries.get() );
326 assertEquals( 1, collectiveAttributeSubentries.size() );
327
328
329
330
331
332 system = results.get( "ou=system" );
333 assertNull( "ou=system should not be marked", system.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
334
335 users = results.get( "ou=users,ou=system" );
336 assertNull( "ou=users,ou=system should not be marked", users.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
337
338 groups = results.get( "ou=groups,ou=system" );
339 assertNull( "ou=groups,ou=system should not be marked", groups.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
340
341 admin = results.get( "uid=admin,ou=system" );
342 assertNull( "uid=admin,ou=system should not be marked", admin.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
343
344 sysPrefRoot = results.get( "prefNodeName=sysPrefRoot,ou=system" );
345 assertNull( "prefNode=sysPrefRoot,ou=system should not be marked", sysPrefRoot
346 .get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
347
348 services = results.get( "ou=services,ou=configuration,ou=system" );
349 collectiveAttributeSubentries = services.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT );
350 if ( collectiveAttributeSubentries != null )
351 {
352 assertEquals( "ou=services,ou=configuration,ou=system should not be marked", 0, collectiveAttributeSubentries.size() );
353 }
354 }
355
356
357 @Test
358 public void testSubentryModify2() throws Exception
359 {
360 LdapContext sysRoot = getSystemContext( service );
361 addAdministrativeRole( "collectiveArributeSpecificArea" );
362 sysRoot.createSubcontext( "cn=testsubentry", getTestSubentry() );
363 Map<String, Attributes> results = getAllEntries();
364
365
366
367
368
369 Attributes configuration = results.get( "ou=configuration,ou=system" );
370 Attribute collectiveAttributeSubentries = configuration.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT );
371 assertNotNull( "ou=configuration,ou=system should be marked", collectiveAttributeSubentries );
372 assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", collectiveAttributeSubentries.get() );
373 assertEquals( 1, collectiveAttributeSubentries.size() );
374
375 Attributes interceptors = results.get( "ou=interceptors,ou=configuration,ou=system" );
376 collectiveAttributeSubentries = interceptors.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT );
377 assertNotNull( "ou=interceptors,ou=configuration,ou=system should be marked", collectiveAttributeSubentries );
378 assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", collectiveAttributeSubentries.get() );
379 assertEquals( 1, collectiveAttributeSubentries.size() );
380
381 Attributes partitions = results.get( "ou=partitions,ou=configuration,ou=system" );
382 collectiveAttributeSubentries = partitions.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT );
383 assertNotNull( "ou=partitions,ou=configuration,ou=system should be marked", collectiveAttributeSubentries );
384 assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", collectiveAttributeSubentries.get() );
385 assertEquals( 1, collectiveAttributeSubentries.size() );
386
387 Attributes services = results.get( "ou=services,ou=configuration,ou=system" );
388 collectiveAttributeSubentries = services.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT );
389 assertNotNull( "ou=services,ou=configuration,ou=system should be marked", collectiveAttributeSubentries );
390 assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", collectiveAttributeSubentries.get() );
391 assertEquals( 1, collectiveAttributeSubentries.size() );
392
393
394
395
396
397 Attributes system = results.get( "ou=system" );
398 assertNull( "ou=system should not be marked", system.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
399
400 Attributes users = results.get( "ou=users,ou=system" );
401 assertNull( "ou=users,ou=system should not be marked", users.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
402
403 Attributes groups = results.get( "ou=groups,ou=system" );
404 assertNull( "ou=groups,ou=system should not be marked", groups.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
405
406 Attributes admin = results.get( "uid=admin,ou=system" );
407 assertNull( "uid=admin,ou=system should not be marked", admin.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
408
409 Attributes sysPrefRoot = results.get( "prefNodeName=sysPrefRoot,ou=system" );
410 assertNull( "prefNode=sysPrefRoot,ou=system should not be marked", sysPrefRoot
411 .get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
412
413
414
415
416
417 Attributes changes = new BasicAttributes( true );
418 changes.put( "subtreeSpecification",
419 "{ base \"ou=configuration\", specificExclusions { chopBefore:\"ou=services\" } }" );
420 sysRoot.modifyAttributes( "cn=testsubentry", DirContext.REPLACE_ATTRIBUTE, changes );
421 results = getAllEntries();
422
423
424
425
426
427 configuration = results.get( "ou=configuration,ou=system" );
428 collectiveAttributeSubentries = configuration.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT );
429 assertNotNull( "ou=configuration,ou=system should be marked", collectiveAttributeSubentries );
430 assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", collectiveAttributeSubentries.get() );
431 assertEquals( 1, collectiveAttributeSubentries.size() );
432
433 interceptors = results.get( "ou=interceptors,ou=configuration,ou=system" );
434 collectiveAttributeSubentries = interceptors.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT );
435 assertNotNull( "ou=interceptors,ou=configuration,ou=system should be marked", collectiveAttributeSubentries );
436 assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", collectiveAttributeSubentries.get() );
437 assertEquals( 1, collectiveAttributeSubentries.size() );
438
439 partitions = results.get( "ou=partitions,ou=configuration,ou=system" );
440 collectiveAttributeSubentries = partitions.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT );
441 assertNotNull( "ou=partitions,ou=configuration,ou=system should be marked", collectiveAttributeSubentries );
442 assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", collectiveAttributeSubentries.get() );
443 assertEquals( 1, collectiveAttributeSubentries.size() );
444
445
446
447
448
449 system = results.get( "ou=system" );
450 assertNull( "ou=system should not be marked", system.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
451
452 users = results.get( "ou=users,ou=system" );
453 assertNull( "ou=users,ou=system should not be marked", users.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
454
455 groups = results.get( "ou=groups,ou=system" );
456 assertNull( "ou=groups,ou=system should not be marked", groups.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
457
458 admin = results.get( "uid=admin,ou=system" );
459 assertNull( "uid=admin,ou=system should not be marked", admin.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
460
461 sysPrefRoot = results.get( "prefNodeName=sysPrefRoot,ou=system" );
462 assertNull( "prefNode=sysPrefRoot,ou=system should not be marked", sysPrefRoot
463 .get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
464
465 services = results.get( "ou=services,ou=configuration,ou=system" );
466 collectiveAttributeSubentries = services.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT );
467 if ( collectiveAttributeSubentries != null )
468 {
469 assertEquals( "ou=services,ou=configuration,ou=system should not be marked", 0, collectiveAttributeSubentries.size() );
470 }
471 }
472
473
474 @Test
475 public void testSubentryDelete() throws Exception
476 {
477 LdapContext sysRoot = getSystemContext( service );
478 addAdministrativeRole( "collectiveArributeSpecificArea" );
479 sysRoot.createSubcontext( "cn=testsubentry", getTestSubentry() );
480 sysRoot.destroySubcontext( "cn=testsubentry" );
481
482 Map<String, Attributes> results = getAllEntries();
483
484
485
486
487
488 Attributes configuration = results.get( "ou=configuration,ou=system" );
489 Attribute collectiveAttributeSubentries = configuration.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT );
490 if ( collectiveAttributeSubentries != null )
491 {
492 assertEquals( "ou=configuration,ou=system should not be marked", 0, collectiveAttributeSubentries.size() );
493 }
494
495 Attributes interceptors = results.get( "ou=interceptors,ou=configuration,ou=system" );
496 collectiveAttributeSubentries = interceptors.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT );
497 if ( collectiveAttributeSubentries != null )
498 {
499 assertEquals( "ou=interceptors,ou=configuration,ou=system should not be marked", 0, collectiveAttributeSubentries
500 .size() );
501 }
502
503 Attributes partitions = results.get( "ou=partitions,ou=configuration,ou=system" );
504 collectiveAttributeSubentries = partitions.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT );
505 if ( collectiveAttributeSubentries != null )
506 {
507 assertEquals( "ou=partitions,ou=configuration,ou=system should not be marked", 0, collectiveAttributeSubentries.size() );
508 }
509
510 Attributes services = results.get( "ou=services,ou=configuration,ou=system" );
511 collectiveAttributeSubentries = services.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT );
512 if ( collectiveAttributeSubentries != null )
513 {
514 assertEquals( "ou=services,ou=configuration,ou=system should not be marked", 0, collectiveAttributeSubentries.size() );
515 }
516
517 Attributes system = results.get( "ou=system" );
518 assertNull( "ou=system should not be marked", system.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
519
520 Attributes users = results.get( "ou=users,ou=system" );
521 assertNull( "ou=users,ou=system should not be marked", users.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
522
523 Attributes admin = results.get( "uid=admin,ou=system" );
524 assertNull( "uid=admin,ou=system should not be marked", admin.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
525
526 Attributes sysPrefRoot = results.get( "prefNodeName=sysPrefRoot,ou=system" );
527 assertNull( "prefNode=sysPrefRoot,ou=system should not be marked", sysPrefRoot
528 .get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
529
530 }
531
532
533 @Test
534 public void testSubentryModifyRdn() throws Exception
535 {
536 LdapContext sysRoot = getSystemContext( service );
537 addAdministrativeRole( "collectiveArributeSpecificArea" );
538 sysRoot.createSubcontext( "cn=testsubentry", getTestSubentry() );
539 sysRoot.rename( "cn=testsubentry", "cn=newname" );
540 Map<String, Attributes> results = getAllEntries();
541
542
543
544
545
546 Attributes configuration = results.get( "ou=configuration,ou=system" );
547 Attribute collectiveAttributeSubentries = configuration.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT );
548 assertNotNull( "ou=configuration,ou=system should be marked", collectiveAttributeSubentries );
549 assertEquals( "2.5.4.3=newname,2.5.4.11=system", collectiveAttributeSubentries.get() );
550 assertEquals( 1, collectiveAttributeSubentries.size() );
551
552 Attributes interceptors = results.get( "ou=interceptors,ou=configuration,ou=system" );
553 collectiveAttributeSubentries = interceptors.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT );
554 assertNotNull( "ou=interceptors,ou=configuration,ou=system should be marked", collectiveAttributeSubentries );
555 assertEquals( "2.5.4.3=newname,2.5.4.11=system", collectiveAttributeSubentries.get() );
556 assertEquals( 1, collectiveAttributeSubentries.size() );
557
558 Attributes partitions = results.get( "ou=partitions,ou=configuration,ou=system" );
559 collectiveAttributeSubentries = partitions.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT );
560 assertNotNull( "ou=partitions,ou=configuration,ou=system should be marked", collectiveAttributeSubentries );
561 assertEquals( "2.5.4.3=newname,2.5.4.11=system", collectiveAttributeSubentries.get() );
562 assertEquals( 1, collectiveAttributeSubentries.size() );
563
564 Attributes services = results.get( "ou=services,ou=configuration,ou=system" );
565 collectiveAttributeSubentries = services.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT );
566 assertNotNull( "ou=services,ou=configuration,ou=system should be marked", collectiveAttributeSubentries );
567 assertEquals( "2.5.4.3=newname,2.5.4.11=system", collectiveAttributeSubentries.get() );
568 assertEquals( 1, collectiveAttributeSubentries.size() );
569
570
571
572
573
574 Attributes system = results.get( "ou=system" );
575 assertNull( "ou=system should not be marked", system.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
576
577 Attributes users = results.get( "ou=users,ou=system" );
578 assertNull( "ou=users,ou=system should not be marked", users.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
579
580 Attributes groups = results.get( "ou=groups,ou=system" );
581 assertNull( "ou=groups,ou=system should not be marked", groups.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
582
583 Attributes admin = results.get( "uid=admin,ou=system" );
584 assertNull( "uid=admin,ou=system should not be marked", admin.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
585
586 Attributes sysPrefRoot = results.get( "prefNodeName=sysPrefRoot,ou=system" );
587 assertNull( "prefNode=sysPrefRoot,ou=system should not be marked", sysPrefRoot
588 .get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
589
590 }
591
592
593 @Test
594 @Ignore ( "Ignored until DIRSERVER-1223 is fixed" )
595 public void testEntryModifyRdn() throws Exception
596 {
597 LdapContext sysRoot = getSystemContext( service );
598 addAdministrativeRole( "collectiveArributeSpecificArea" );
599 sysRoot.createSubcontext( "cn=testsubentry", getTestSubentryWithExclusion() );
600 sysRoot.createSubcontext( "cn=unmarked,ou=configuration", getTestEntry( "unmarked" ) );
601 sysRoot.createSubcontext( "cn=marked,ou=configuration", getTestEntry( "marked" ) );
602 Map<String, Attributes> results = getAllEntries();
603
604
605
606
607
608 Attributes configuration = results.get( "ou=configuration,ou=system" );
609 Attribute collectiveAttributeSubentries = configuration.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT );
610 assertNotNull( "ou=configuration,ou=system should be marked", collectiveAttributeSubentries );
611 assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", collectiveAttributeSubentries.get() );
612 assertEquals( 1, collectiveAttributeSubentries.size() );
613
614 Attributes interceptors = results.get( "ou=interceptors,ou=configuration,ou=system" );
615 collectiveAttributeSubentries = interceptors.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT );
616 assertNotNull( "ou=interceptors,ou=configuration,ou=system should be marked", collectiveAttributeSubentries );
617 assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", collectiveAttributeSubentries.get() );
618 assertEquals( 1, collectiveAttributeSubentries.size() );
619
620 Attributes partitions = results.get( "ou=partitions,ou=configuration,ou=system" );
621 collectiveAttributeSubentries = partitions.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT );
622 assertNotNull( "ou=partitions,ou=configuration,ou=system should be marked", collectiveAttributeSubentries );
623 assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", collectiveAttributeSubentries.get() );
624 assertEquals( 1, collectiveAttributeSubentries.size() );
625
626 Attributes services = results.get( "ou=services,ou=configuration,ou=system" );
627 collectiveAttributeSubentries = services.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT );
628 assertNotNull( "ou=services,ou=configuration,ou=system should be marked", collectiveAttributeSubentries );
629 assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", collectiveAttributeSubentries.get() );
630 assertEquals( 1, collectiveAttributeSubentries.size() );
631
632 Attributes marked = results.get( "cn=marked,ou=configuration,ou=system" );
633 collectiveAttributeSubentries = marked.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT );
634 assertNotNull( "cn=marked,ou=configuration,ou=system should be marked", collectiveAttributeSubentries );
635 assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", collectiveAttributeSubentries.get() );
636 assertEquals( 1, collectiveAttributeSubentries.size() );
637
638
639
640
641
642 Attributes system = results.get( "ou=system" );
643 assertNull( "ou=system should not be marked", system.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
644
645 Attributes users = results.get( "ou=users,ou=system" );
646 assertNull( "ou=users,ou=system should not be marked", users.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
647
648 Attributes groups = results.get( "ou=groups,ou=system" );
649 assertNull( "ou=groups,ou=system should not be marked", groups.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
650
651 Attributes admin = results.get( "uid=admin,ou=system" );
652 assertNull( "uid=admin,ou=system should not be marked", admin.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
653
654 Attributes sysPrefRoot = results.get( "prefNodeName=sysPrefRoot,ou=system" );
655 assertNull( "prefNode=sysPrefRoot,ou=system should not be marked", sysPrefRoot
656 .get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
657
658 Attributes unmarked = results.get( "cn=unmarked,ou=configuration,ou=system" );
659 assertNull( "cn=unmarked,ou=configuration,ou=system should not be marked", unmarked
660 .get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
661
662
663
664
665
666 sysRoot.destroySubcontext( "cn=unmarked,ou=configuration" );
667 sysRoot.rename( "cn=marked,ou=configuration", "cn=unmarked,ou=configuration" );
668 results = getAllEntries();
669
670 unmarked = results.get( "cn=unmarked,ou=configuration,ou=system" );
671 assertNull( "cn=unmarked,ou=configuration,ou=system should not be marked", unmarked
672 .get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
673 assertNull( results.get( "cn=marked,ou=configuration,ou=system" ) );
674
675
676
677
678
679 sysRoot.rename( "cn=unmarked,ou=configuration", "cn=marked,ou=configuration" );
680 results = getAllEntries();
681 assertNull( results.get( "cn=unmarked,ou=configuration,ou=system" ) );
682 marked = results.get( "cn=marked,ou=configuration,ou=system" );
683 assertNotNull( marked );
684 collectiveAttributeSubentries = marked.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT );
685 assertNotNull( "cn=marked,ou=configuration,ou=system should be marked", collectiveAttributeSubentries );
686 assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", collectiveAttributeSubentries.get() );
687 assertEquals( 1, collectiveAttributeSubentries.size() );
688 }
689
690
691 @Test
692 @Ignore ( "Ignored until DIRSERVER-1223 is fixed" )
693 public void testEntryMoveWithRdnChange() throws Exception
694 {
695 LdapContext sysRoot = getSystemContext( service );
696 addAdministrativeRole( "collectiveArributeSpecificArea" );
697 sysRoot.createSubcontext( "cn=testsubentry", getTestSubentryWithExclusion() );
698 sysRoot.createSubcontext( "cn=unmarked", getTestEntry( "unmarked" ) );
699 sysRoot.createSubcontext( "cn=marked,ou=configuration", getTestEntry( "marked" ) );
700 Map<String, Attributes> results = getAllEntries();
701
702
703
704
705
706 Attributes configuration = results.get( "ou=configuration,ou=system" );
707 Attribute collectiveAttributeSubentries = configuration.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT );
708 assertNotNull( "ou=configuration,ou=system should be marked", collectiveAttributeSubentries );
709 assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", collectiveAttributeSubentries.get() );
710 assertEquals( 1, collectiveAttributeSubentries.size() );
711
712 Attributes interceptors = results.get( "ou=interceptors,ou=configuration,ou=system" );
713 collectiveAttributeSubentries = interceptors.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT );
714 assertNotNull( "ou=interceptors,ou=configuration,ou=system should be marked", collectiveAttributeSubentries );
715 assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", collectiveAttributeSubentries.get() );
716 assertEquals( 1, collectiveAttributeSubentries.size() );
717
718 Attributes partitions = results.get( "ou=partitions,ou=configuration,ou=system" );
719 collectiveAttributeSubentries = partitions.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT );
720 assertNotNull( "ou=partitions,ou=configuration,ou=system should be marked", collectiveAttributeSubentries );
721 assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", collectiveAttributeSubentries.get() );
722 assertEquals( 1, collectiveAttributeSubentries.size() );
723
724 Attributes services = results.get( "ou=services,ou=configuration,ou=system" );
725 collectiveAttributeSubentries = services.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT );
726 assertNotNull( "ou=services,ou=configuration,ou=system should be marked", collectiveAttributeSubentries );
727 assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", collectiveAttributeSubentries.get() );
728 assertEquals( 1, collectiveAttributeSubentries.size() );
729
730 Attributes marked = results.get( "cn=marked,ou=configuration,ou=system" );
731 collectiveAttributeSubentries = marked.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT );
732 assertNotNull( "cn=marked,ou=configuration,ou=system should be marked", collectiveAttributeSubentries );
733 assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", collectiveAttributeSubentries.get() );
734 assertEquals( 1, collectiveAttributeSubentries.size() );
735
736
737
738
739
740 Attributes system = results.get( "ou=system" );
741 assertNull( "ou=system should not be marked", system.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
742
743 Attributes users = results.get( "ou=users,ou=system" );
744 assertNull( "ou=users,ou=system should not be marked", users.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
745
746 Attributes groups = results.get( "ou=groups,ou=system" );
747 assertNull( "ou=groups,ou=system should not be marked", groups.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
748
749 Attributes admin = results.get( "uid=admin,ou=system" );
750 assertNull( "uid=admin,ou=system should not be marked", admin.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
751
752 Attributes sysPrefRoot = results.get( "prefNodeName=sysPrefRoot,ou=system" );
753 assertNull( "prefNode=sysPrefRoot,ou=system should not be marked", sysPrefRoot
754 .get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
755
756 Attributes unmarked = results.get( "cn=unmarked,ou=system" );
757 assertNull( "cn=unmarked,ou=system should not be marked", unmarked
758 .get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
759
760
761
762
763
764 sysRoot.destroySubcontext( "cn=unmarked" );
765 sysRoot.rename( "cn=marked,ou=configuration", "cn=unmarked" );
766 results = getAllEntries();
767
768 unmarked = results.get( "cn=unmarked,ou=system" );
769 assertNull( "cn=unmarked,ou=system should not be marked", unmarked
770 .get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
771 assertNull( results.get( "cn=marked,ou=configuration,ou=system" ) );
772
773
774
775
776
777 sysRoot.rename( "cn=unmarked", "cn=marked,ou=configuration" );
778 results = getAllEntries();
779 assertNull( results.get( "cn=unmarked,ou=system" ) );
780 marked = results.get( "cn=marked,ou=configuration,ou=system" );
781 assertNotNull( marked );
782 collectiveAttributeSubentries = marked.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT );
783 assertNotNull( "cn=marked,ou=configuration,ou=system should be marked", collectiveAttributeSubentries );
784 assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", collectiveAttributeSubentries.get() );
785 assertEquals( 1, collectiveAttributeSubentries.size() );
786 }
787
788
789 @Test
790 @Ignore ( "Ignored until DIRSERVER-1223 is fixed" )
791 public void testEntryMove() throws Exception
792 {
793 LdapContext sysRoot = getSystemContext( service );
794 addAdministrativeRole( "collectiveArributeSpecificArea" );
795 sysRoot.createSubcontext( "cn=testsubentry", getTestSubentryWithExclusion() );
796 sysRoot.createSubcontext( "cn=unmarked", getTestEntry( "unmarked" ) );
797 sysRoot.createSubcontext( "cn=marked,ou=configuration", getTestEntry( "marked" ) );
798 Map<String, Attributes> results = getAllEntries();
799
800
801
802
803
804 Attributes configuration = results.get( "ou=configuration,ou=system" );
805 Attribute collectiveAttributeSubentries = configuration.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT );
806 assertNotNull( "ou=configuration,ou=system should be marked", collectiveAttributeSubentries );
807 assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", collectiveAttributeSubentries.get() );
808 assertEquals( 1, collectiveAttributeSubentries.size() );
809
810 Attributes interceptors = results.get( "ou=interceptors,ou=configuration,ou=system" );
811 collectiveAttributeSubentries = interceptors.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT );
812 assertNotNull( "ou=interceptors,ou=configuration,ou=system should be marked", collectiveAttributeSubentries );
813 assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", collectiveAttributeSubentries.get() );
814 assertEquals( 1, collectiveAttributeSubentries.size() );
815
816 Attributes partitions = results.get( "ou=partitions,ou=configuration,ou=system" );
817 collectiveAttributeSubentries = partitions.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT );
818 assertNotNull( "ou=partitions,ou=configuration,ou=system should be marked", collectiveAttributeSubentries );
819 assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", collectiveAttributeSubentries.get() );
820 assertEquals( 1, collectiveAttributeSubentries.size() );
821
822 Attributes services = results.get( "ou=services,ou=configuration,ou=system" );
823 collectiveAttributeSubentries = services.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT );
824 assertNotNull( "ou=services,ou=configuration,ou=system should be marked", collectiveAttributeSubentries );
825 assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", collectiveAttributeSubentries.get() );
826 assertEquals( 1, collectiveAttributeSubentries.size() );
827
828 Attributes marked = results.get( "cn=marked,ou=configuration,ou=system" );
829 collectiveAttributeSubentries = marked.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT );
830 assertNotNull( "cn=marked,ou=configuration,ou=system should be marked", collectiveAttributeSubentries );
831 assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", collectiveAttributeSubentries.get() );
832 assertEquals( 1, collectiveAttributeSubentries.size() );
833
834
835
836
837
838 Attributes system = results.get( "ou=system" );
839 assertNull( "ou=system should not be marked", system.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
840
841 Attributes users = results.get( "ou=users,ou=system" );
842 assertNull( "ou=users,ou=system should not be marked", users.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
843
844 Attributes groups = results.get( "ou=groups,ou=system" );
845 assertNull( "ou=groups,ou=system should not be marked", groups.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
846
847 Attributes admin = results.get( "uid=admin,ou=system" );
848 assertNull( "uid=admin,ou=system should not be marked", admin.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
849
850 Attributes sysPrefRoot = results.get( "prefNodeName=sysPrefRoot,ou=system" );
851 assertNull( "prefNode=sysPrefRoot,ou=system should not be marked", sysPrefRoot
852 .get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
853
854 Attributes unmarked = results.get( "cn=unmarked,ou=system" );
855 assertNull( "cn=unmarked,ou=system should not be marked", unmarked
856 .get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
857
858
859
860
861
862 sysRoot.destroySubcontext( "cn=unmarked" );
863 sysRoot.rename( "cn=marked,ou=configuration", "cn=marked,ou=services,ou=configuration" );
864 results = getAllEntries();
865
866 unmarked = results.get( "cn=unmarked,ou=system" );
867 assertNull( "cn=unmarked,ou=system should not be marked", unmarked );
868 assertNull( results.get( "cn=marked,ou=configuration,ou=system" ) );
869
870 marked = results.get( "cn=marked,ou=services,ou=configuration,ou=system" );
871 assertNotNull( marked );
872 collectiveAttributeSubentries = marked.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT );
873 assertNotNull( "cn=marked,ou=services,ou=configuration should be marked", collectiveAttributeSubentries );
874 assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", collectiveAttributeSubentries.get() );
875 assertEquals( 1, collectiveAttributeSubentries.size() );
876 }
877
878
879 @Test
880 @Ignore ( "Ignored until DIRSERVER-1223 is fixed" )
881 public void testSubentriesControl() throws Exception
882 {
883 LdapContext sysRoot = getSystemContext( service );
884 addAdministrativeRole( "collectiveArributeSpecificArea" );
885 sysRoot.createSubcontext( "cn=testsubentry", getTestSubentryWithExclusion() );
886 SearchControls searchControls = new SearchControls();
887 searchControls.setSearchScope( SearchControls.SUBTREE_SCOPE );
888
889
890 Map<String, SearchResult> entries = new HashMap<String, SearchResult>();
891 NamingEnumeration<SearchResult> list = sysRoot.search( "", "(objectClass=*)", searchControls );
892
893 while ( list.hasMore() )
894 {
895 SearchResult result = ( SearchResult ) list.next();
896 entries.put( result.getName(), result );
897 }
898
899 assertTrue( entries.size() > 1 );
900 assertNull( entries.get( "cn=testsubentry,ou=system" ) );
901
902
903
904 SubentriesControl ctl = new SubentriesControl();
905 ctl.setVisibility( true );
906 sysRoot.setRequestControls( new Control[] { ctl } );
907 list = sysRoot.search( "", "(objectClass=*)", searchControls );
908 SearchResult result = ( SearchResult ) list.next();
909 assertFalse( list.hasMore() );
910 assertEquals( "cn=testsubentry,ou=system", result.getName() );
911 }
912
913
914 @Test
915 @Ignore ( "Ignored until DIRSERVER-1223 is fixed" )
916 public void testBaseScopeSearchSubentryVisibilityWithoutTheControl() throws Exception
917 {
918 LdapContext sysRoot = getSystemContext( service );
919 addAdministrativeRole( "collectiveArributeSpecificArea" );
920 sysRoot.createSubcontext( "cn=testsubentry", getTestSubentryWithExclusion() );
921 SearchControls searchControls = new SearchControls();
922 searchControls.setSearchScope( SearchControls.OBJECT_SCOPE );
923
924 Map<String, SearchResult> entries = new HashMap<String, SearchResult>();
925 NamingEnumeration<SearchResult> list = sysRoot.search( "cn=testsubentry", "(objectClass=subentry)", searchControls );
926
927 while ( list.hasMore() )
928 {
929 SearchResult result = list.next();
930 entries.put( result.getName(), result );
931 }
932
933 assertEquals( 1, entries.size() );
934 assertNotNull( entries.get( "cn=testsubentry,ou=system" ) );
935 }
936 }