Debian Codegraph @

dirsrvtests/tests/suites/mapping_tree/mt_cursed_test.py

raw
1 # --- BEGIN COPYRIGHT BLOCK ---
2 # Copyright (C) 2020 William Brown <[email protected]>
3 # All rights reserved.
4 #
5 # License: GPL (version 3 or any later version).
6 # See LICENSE for details.
7 # --- END COPYRIGHT BLOCK ---
8
9 import ldap
10 import pytest
11 import time
12 from test389.topologies import topology_st
13 from lib389.backend import Backends, Backend
14 from lib389.mappingTree import MappingTrees
15 from lib389.idm.domain import Domain
16 from lib389.configurations.sample import create_base_domain
17 from lib389.utils import *
18 from lib389.config import LMDB_LDBMConfig
19
20 @pytest.fixture(scope="function")
21 def topology(topology_st):
22 if get_default_db_lib() == "mdb":
23 handler = LMDB_LDBMConfig(topology_st.standalone)
24 # Need at least 1500 dbis for 50 suffixes
25 maxdbi=5000
26 log.info(f'Set lmdb map max dbi to {maxdbi}.')
27 handler.replace('nsslapd-mdb-max-dbs', str(maxdbi))
28 topology_st.standalone.restart()
29 bes = Backends(topology_st.standalone)
30 bes.delete_all_dangerous()
31 mts = MappingTrees(topology_st.standalone)
32 assert len(mts.list()) == 0
33 return topology_st
34
35
36 def create_backend(inst, rdn, suffix):
37 # We only support dc= in this test.
38 assert suffix.startswith('dc=')
39 be1 = Backend(inst)
40 be1.create(properties={
41 'cn': rdn,
42 'nsslapd-suffix': suffix,
43 },
44 create_mapping_tree=False
45 )
46
47 # Now we temporarily make the MT for this node so we can add the base entry.
48 mts = MappingTrees(inst)
49 mt = mts.create(properties={
50 'cn': suffix,
51 'nsslapd-state': 'backend',
52 'nsslapd-backend': rdn,
53 })
54
55 # Create the domain entry
56 create_base_domain(inst, suffix)
57 # Now delete the mt
58 mt.delete()
59
60 return be1
61
62 def test_mapping_tree_inverted(topology):
63 """Test the results of an inverted parent suffix definition in the configuration.
64
65 For more details see:
66 https://www.port389.org/docs/389ds/design/mapping_tree_assembly.html
67
68 :id: 024c4960-3aac-4d05-bc51-963dfdeb16ca
69 :setup: Standalone instance (no backends)
70 :steps:
71 1. Add two backends without mapping trees.
72 2. Add the mapping trees with inverted parent-suffix definitions.
73 3. Attempt to search the definitions
74 :expectedresults:
75 1. Success
76 2. Success
77 3. The search suceed and can see validly arranged entries.
78 """
79 inst = topology.standalone
80 # First create two Backends, without mapping trees.
81 be1 = create_backend(inst, 'userRootA', 'dc=example,dc=com')
82 be2 = create_backend(inst, 'userRootB', 'dc=straya,dc=example,dc=com')
83 # Okay, now we create the mapping trees for these backends, and we *invert* them in the parent config setting
84 mts = MappingTrees(inst)
85 mtb = mts.create(properties={
86 'cn': 'dc=straya,dc=example,dc=com',
87 'nsslapd-state': 'backend',
88 'nsslapd-backend': 'userRootB',
89 })
90 mta = mts.create(properties={
91 'cn': 'dc=example,dc=com',
92 'nsslapd-state': 'backend',
93 'nsslapd-backend': 'userRootA',
94 'nsslapd-parent-suffix': 'dc=straya,dc=example,dc=com'
95 })
96
97 dc_ex = Domain(inst, dn='dc=example,dc=com')
98 assert dc_ex.exists()
99
100 dc_st = Domain(inst, dn='dc=straya,dc=example,dc=com')
101 assert dc_st.exists()
102
103 # Restart and check again
104 inst.restart()
105 assert dc_ex.exists()
106 assert dc_st.exists()
107
108
109 def test_mapping_tree_nonexist_parent(topology):
110 """Test a backend whos mapping tree definition has a non-existant parent-suffix
111
112 For more details see:
113 https://www.port389.org/docs/389ds/design/mapping_tree_assembly.html
114
115 :id: 7a9a09bd-7604-48f7-93cb-abff9e0d0131
116 :setup: Standalone instance (no backends)
117 :steps:
118 1. Add one backend without mapping tree
119 2. Configure the mapping tree with a non-existant parent suffix
120 3. Attempt to search the backend
121 :expectedresults:
122 1. Success
123 2. Success
124 3. The search suceed and can see validly entries.
125 """
126 inst = topology.standalone
127 be1 = create_backend(inst, 'userRootC', 'dc=test,dc=com')
128 mts = MappingTrees(inst)
129 mta = mts.create(properties={
130 'cn': 'dc=test,dc=com',
131 'nsslapd-state': 'backend',
132 'nsslapd-backend': 'userRootC',
133 'nsslapd-parent-suffix': 'dc=com'
134 })
135 # In this case the MT is never joined properly to the hierachy because the parent suffix
136 # doesn't exist. The config is effectively ignored. That means that it can't be searched!
137 dc_ex = Domain(inst, dn='dc=test,dc=com')
138 assert dc_ex.exists()
139 # Restart and check again.
140 inst.restart()
141 assert dc_ex.exists()
142
143
144 # Two same length (dc=example,dc=com dc=abcdefg,dc=abc)
145 def test_mapping_tree_same_length(topology):
146 """Test mapping tree with backends that have same lengths (dc=example,dc=com and dc=abcdefg,dc=abc)
147
148 :id: 7b9fcffe-e786-4895-b530-00215aaa7e84
149 :setup: Standalone instance (no backends)
150 :steps:
151 1. Add two backends without mapping trees
152 2. Create the mapping trees for these backends
153 3. Check that domains exist
154 4. Restart and check again
155 :expectedresults:
156 1. Success
157 2. Success
158 3. Success
159 4. Success
160 """
161 inst = topology.standalone
162 # First create two Backends, without mapping trees.
163 be1 = create_backend(inst, 'userRootA', 'dc=example,dc=com')
164 be2 = create_backend(inst, 'userRootB', 'dc=abcdefg,dc=hij')
165 # Okay, now we create the mapping trees for these backends
166 mts = MappingTrees(inst)
167 mtb = mts.create(properties={
168 'cn': 'dc=example,dc=com',
169 'nsslapd-state': 'backend',
170 'nsslapd-backend': 'userRootA',
171 })
172 mta = mts.create(properties={
173 'cn': 'dc=abcdefg,dc=hij',
174 'nsslapd-state': 'backend',
175 'nsslapd-backend': 'userRootB',
176 })
177
178 dc_ex = Domain(inst, dn='dc=example,dc=com')
179 assert dc_ex.exists()
180
181 dc_ab = Domain(inst, dn='dc=abcdefg,dc=hij')
182 assert dc_ab.exists()
183
184 # Restart and check again
185 inst.restart()
186 assert dc_ex.exists()
187 assert dc_ab.exists()
188
189 # Flipped DC comps (dc=exmaple,dc=com dc=com,dc=example)
190 def test_mapping_tree_flipped_components(topology):
191 """Test mapping tree with backends that have flipped DC components (dc=example,dc=com and dc=com,dc=example)
192
193 :id: 55264933-2a81-428b-aec9-c8f9a64400d1
194 :setup: Standalone instance (no backends)
195 :steps:
196 1. Add two backends without mapping trees
197 2. Create the mapping trees for these backends
198 3. Check that domains exist
199 4. Restart and check again
200 :expectedresults:
201 1. Success
202 2. Success
203 3. Success
204 4. Success
205 """
206 inst = topology.standalone
207 # First create two Backends, without mapping trees.
208 be1 = create_backend(inst, 'userRootA', 'dc=example,dc=com')
209 be2 = create_backend(inst, 'userRootB', 'dc=com,dc=example')
210 # Okay, now we create the mapping trees for these backends
211 mts = MappingTrees(inst)
212 mtb = mts.create(properties={
213 'cn': 'dc=example,dc=com',
214 'nsslapd-state': 'backend',
215 'nsslapd-backend': 'userRootA',
216 })
217 mta = mts.create(properties={
218 'cn': 'dc=com,dc=example',
219 'nsslapd-state': 'backend',
220 'nsslapd-backend': 'userRootB',
221 })
222
223 dc_ex = Domain(inst, dn='dc=example,dc=com')
224 assert dc_ex.exists()
225
226 dc_ab = Domain(inst, dn='dc=com,dc=example')
227 assert dc_ab.exists()
228
229 # Restart and check again
230 inst.restart()
231 assert dc_ex.exists()
232 assert dc_ab.exists()
233
234 # Weird nesting (dc=exmaple,dc=com, dc=com,dc=example, dc=com,dc=example,dc=com)
235 def test_mapping_tree_weird_nesting(topology):
236 """Test mapping tree with backends that have weired nesting (dc=exmaple,dc=com, dc=com,dc=example, dc=com,dc=example,dc=com)
237
238 :id: 02fbfaa5-15ef-43d2-a52f-c011e496e8cd
239 :setup: Standalone instance (no backends)
240 :steps:
241 1. Add 3 backends without mapping trees
242 2. Create the mapping trees for these backends
243 3. Check that domains exist
244 4. Restart and check again
245 :expectedresults:
246 1. Success
247 2. Success
248 3. Success
249 4. Success
250 """
251 inst = topology.standalone
252 # First create 3 Backends, without mapping trees.
253 be1 = create_backend(inst, 'userRootA', 'dc=example,dc=com')
254 be2 = create_backend(inst, 'userRootB', 'dc=com,dc=example')
255 be3 = create_backend(inst, 'userRootC', 'dc=com,dc=example,dc=com')
256 # Okay, now we create the mapping trees for these backends, and we *invert* them in the parent config setting
257 mts = MappingTrees(inst)
258 mtb = mts.create(properties={
259 'cn': 'dc=example,dc=com',
260 'nsslapd-state': 'backend',
261 'nsslapd-backend': 'userRootA',
262 })
263 mta = mts.create(properties={
264 'cn': 'dc=com,dc=example',
265 'nsslapd-state': 'backend',
266 'nsslapd-backend': 'userRootB',
267 })
268 mtc = mts.create(properties={
269 'cn': 'dc=com,dc=example,dc=com',
270 'nsslapd-state': 'backend',
271 'nsslapd-backend': 'userRootC',
272 })
273
274 dc_ex = Domain(inst, dn='dc=example,dc=com')
275 assert dc_ex.exists()
276
277 dc_ab = Domain(inst, dn='dc=com,dc=example')
278 assert dc_ab.exists()
279
280 dc_ec = Domain(inst, dn='dc=com,dc=example,dc=com')
281 assert dc_ec.exists()
282
283 # Restart and check again
284 inst.restart()
285 assert dc_ex.exists()
286 assert dc_ab.exists()
287 assert dc_ec.exists()
288
289 # Diff lens (dc=myserver, dc=a,dc=b,dc=c,dc=d, dc=example,dc=com)
290 def test_mapping_tree_mixed_length(topology):
291 """Test mapping tree with backends that have different lengths (dc=myserver, dc=a,dc=b,dc=c,dc=d, dc=example,dc=com)
292
293 :id: ce43abf2-335c-4327-a883-b20a40e5571c
294 :setup: Standalone instance (no backends)
295 :steps:
296 1. Add 5 backends without mapping trees
297 2. Create the mapping trees for these backends
298 3. Check that domains exist
299 4. Restart and check again
300 :expectedresults:
301 1. Success
302 2. Success
303 3. Success
304 4. Success
305 """
306 inst = topology.standalone
307 # First create 5 Backends, without mapping trees.
308 be1 = create_backend(inst, 'userRootA', 'dc=myserver')
309 be2 = create_backend(inst, 'userRootB', 'dc=m')
310 be3 = create_backend(inst, 'userRootC', 'dc=a,dc=b,dc=c,dc=d,dc=e')
311 be4 = create_backend(inst, 'userRootD', 'dc=example,dc=com')
312 be5 = create_backend(inst, 'userRootE', 'dc=myldap')
313
314 mts = MappingTrees(inst)
315 mts.create(properties={
316 'cn': 'dc=myserver',
317 'nsslapd-state': 'backend',
318 'nsslapd-backend': 'userRootA',
319 })
320 mts.create(properties={
321 'cn': 'dc=m',
322 'nsslapd-state': 'backend',
323 'nsslapd-backend': 'userRootB',
324 })
325 mts.create(properties={
326 'cn': 'dc=a,dc=b,dc=c,dc=d,dc=e',
327 'nsslapd-state': 'backend',
328 'nsslapd-backend': 'userRootC',
329 })
330 mts.create(properties={
331 'cn': 'dc=example,dc=com',
332 'nsslapd-state': 'backend',
333 'nsslapd-backend': 'userRootD',
334 })
335 mts.create(properties={
336 'cn': 'dc=myldap',
337 'nsslapd-state': 'backend',
338 'nsslapd-backend': 'userRootE',
339 })
340
341 dc_a = Domain(inst, dn='dc=myserver')
342 assert dc_a.exists()
343 dc_b = Domain(inst, dn='dc=m')
344 assert dc_b.exists()
345 dc_c = Domain(inst, dn='dc=a,dc=b,dc=c,dc=d,dc=e')
346 assert dc_c.exists()
347 dc_d = Domain(inst, dn='dc=example,dc=com')
348 assert dc_d.exists()
349 dc_e = Domain(inst, dn='dc=myldap')
350 assert dc_e.exists()
351
352 inst.restart()
353 assert dc_a.exists()
354 assert dc_b.exists()
355 assert dc_c.exists()
356 assert dc_d.exists()
357 assert dc_e.exists()
358
359 # 50 suffixes, shallow nest (dc=example,dc=com, then dc=00 -> dc=50)
360 def test_mapping_tree_many_shallow(topology):
361 """Test mapping tree with 50 backends, shallow nesting
362
363 :id: c15dc565-fa9d-41c9-91f9-24543079ce31
364 :setup: Standalone instance (no backends)
365 :steps:
366 1. Add 50 backends without mapping trees
367 2. Create the mapping trees for these backends
368 3. Check that domains exist
369 4. Restart and check again
370 :expectedresults:
371 1. Success
372 2. Success
373 3. Success
374 4. Success
375 """
376 inst = topology.standalone
377 dcs = [ ('dc=x%s,dc=example,dc=com' % x, 'userRoot%s' % x) for x in range(0,50) ]
378
379 for (dc, bename) in dcs:
380 create_backend(inst, bename, dc)
381
382 mts = MappingTrees(inst)
383 for (dc, bename) in dcs:
384 mts.create(properties={
385 'cn': dc,
386 'nsslapd-state': 'backend',
387 'nsslapd-backend': bename,
388 })
389
390 dc_asserts = [ Domain(inst, dn=dc[0]) for dc in dcs ]
391 for dc_a in dc_asserts:
392 assert dc_a.exists()
393 inst.restart()
394 for dc_a in dc_asserts:
395 assert dc_a.exists()
396
397 # 50 suffixes, deeper nesting (dc=example,dc=com, dc=00 -> dc=10 and dc=a,dc=b,dc=c,dc=d,dc=XX,dc=example,dc=com)
398 def test_mapping_tree_many_deep_nesting(topology):
399 """Test mapping tree with 50 backends, deep nesting (dc=example,dc=com, dc=00 -> dc=10 and dc=a,dc=b,dc=c,dc=d,dc=XX,dc=example,dc=com)
400
401 :id: 519e5fb7-e8d1-42fe-800c-ba157054a7d9
402 :setup: Standalone instance (no backends)
403 :steps:
404 1. Add 50 backends without mapping trees
405 2. Create the mapping trees for these backends
406 3. Check that domains exist
407 4. Restart and check again
408 :expectedresults:
409 1. Success
410 2. Success
411 3. Success
412 4. Success
413 """
414 inst = topology.standalone
415 be_count = 0
416 dcs = []
417 for x in range(0, 10):
418 dcs.append(('dc=x%s,dc=example,dc=com' % x, 'userRoot%s' % be_count))
419 be_count += 1
420
421 # Now add some children.
422 for x in range(0,10):
423 dcs.append(('dc=nest,dc=x%s,dc=example,dc=com' % x, 'userRoot%s' % be_count))
424 be_count += 1
425
426 # Now add nested children
427 for x in range(0,10):
428 for y in range(0,5):
429 dcs.append(('dc=y%s,dc=nest,dc=x%s,dc=example,dc=com' % (y, x), 'userRoot%s' % be_count))
430 be_count += 1
431
432 for (dc, bename) in dcs:
433 create_backend(inst, bename, dc)
434
435 mts = MappingTrees(inst)
436 for (dc, bename) in dcs:
437 mts.create(properties={
438 'cn': dc,
439 'nsslapd-state': 'backend',
440 'nsslapd-backend': bename,
441 })
442
443 dc_asserts = [ Domain(inst, dn=dc[0]) for dc in dcs ]
444 for dc_a in dc_asserts:
445 assert dc_a.exists()
446 inst.restart()
447 for dc_a in dc_asserts:
448 assert dc_a.exists()
449