Debian Codegraph @

dirsrvtests/tests/suites/acl/acl_test.py

raw
1 # --- BEGIN COPYRIGHT BLOCK ---
2 # Copyright (C) 2020 Red Hat, Inc.
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 pytest
10 from ldap.controls.simple import GetEffectiveRightsControl
11 from lib389.tasks import *
12 from lib389.utils import *
13 from lib389.schema import Schema
14 from lib389.idm.domain import Domain
15 from lib389.idm.user import UserAccount, UserAccounts, TEST_USER_PROPERTIES
16 from lib389.idm.organizationalunit import OrganizationalUnits
17 from lib389.idm.organizationalrole import OrganizationalRole, OrganizationalRoles
18 from test389.topologies import topology_m2
19 from lib389._constants import SUFFIX, DN_DM, DEFAULT_SUFFIX, PASSWORD
20
21 pytestmark = pytest.mark.tier1
22
23 logging.getLogger(__name__).setLevel(logging.DEBUG)
24 log = logging.getLogger(__name__)
25
26 TEST_REPL_DN = "cn=test_repl, %s" % SUFFIX
27
28 STAGING_CN = "staged user"
29 PRODUCTION_CN = "accounts"
30 EXCEPT_CN = "excepts"
31
32 STAGING_DN = "cn=%s,%s" % (STAGING_CN, SUFFIX)
33 PRODUCTION_DN = "cn=%s,%s" % (PRODUCTION_CN, SUFFIX)
34 PROD_EXCEPT_DN = "cn=%s,%s" % (EXCEPT_CN, PRODUCTION_DN)
35
36 STAGING_PATTERN = "cn=%s*,%s" % (STAGING_CN[:2], SUFFIX)
37 PRODUCTION_PATTERN = "cn=%s*,%s" % (PRODUCTION_CN[:2], SUFFIX)
38 BAD_STAGING_PATTERN = "cn=bad*,%s" % (SUFFIX)
39 BAD_PRODUCTION_PATTERN = "cn=bad*,%s" % (SUFFIX)
40
41 BIND_RDN = "bind_entry"
42 BIND_DN = "uid=%s,%s" % (BIND_RDN, SUFFIX)
43 BIND_PW = "password"
44
45 NEW_ACCOUNT = "new_account"
46 MAX_ACCOUNTS = 20
47
48 CONFIG_MODDN_ACI_ATTR = "nsslapd-moddn-aci"
49
50 SRC_ENTRY_CN = "tuser"
51 EXT_RDN = "01"
52 DST_ENTRY_CN = SRC_ENTRY_CN + EXT_RDN
53
54 SRC_ENTRY_DN = "cn=%s,%s" % (SRC_ENTRY_CN, SUFFIX)
55 DST_ENTRY_DN = "cn=%s,%s" % (DST_ENTRY_CN, SUFFIX)
56
57 TARGET_ATTR_SEARCH = 'description'
58
59
60 def add_attr(topology_m2, attr_name):
61 """Adds attribute to the schema"""
62
63 ATTR_VALUE = """(NAME '%s' \
64 DESC 'Attribute filteri-Multi-Valued' \
65 SYNTAX 1.3.6.1.4.1.1466.115.121.1.27)""" % attr_name
66 schema = Schema(topology_m2.ms["supplier1"])
67 schema.add('attributeTypes', ATTR_VALUE)
68
69
70 @pytest.fixture(params=["lang-ja", "binary", "phonetic"])
71 def aci_with_attr_subtype(request, topology_m2):
72 """Adds and deletes an ACI in the DEFAULT_SUFFIX"""
73
74 TARGET_ATTR = 'protectedOperation'
75 USER_ATTR = 'allowedToPerform'
76 SUBTYPE = request.param
77 suffix = Domain(topology_m2.ms["supplier1"], DEFAULT_SUFFIX)
78
79 log.info("========Executing test with '%s' subtype========" % SUBTYPE)
80 log.info(" Add a target attribute")
81 add_attr(topology_m2, TARGET_ATTR)
82
83 log.info(" Add a user attribute")
84 add_attr(topology_m2, USER_ATTR)
85
86 ACI_TARGET = '(targetattr=%s;%s)' % (TARGET_ATTR, SUBTYPE)
87 ACI_ALLOW = '(version 3.0; acl "test aci for subtypes"; allow (read) '
88 ACI_SUBJECT = 'userattr = "%s;%s#GROUPDN";)' % (USER_ATTR, SUBTYPE)
89 ACI_BODY = ACI_TARGET + ACI_ALLOW + ACI_SUBJECT
90
91 log.info("Add an ACI with attribute subtype")
92 suffix.add('aci', ACI_BODY)
93
94 def fin():
95 log.info("Finally, delete an ACI with the '%s' subtype" %
96 SUBTYPE)
97 suffix.remove('aci', ACI_BODY)
98
99 request.addfinalizer(fin)
100
101 return ACI_BODY
102
103
104 @pytest.fixture(scope="function")
105 def user_for_test(request, topology_m2):
106 """Create test users"""
107
108 # Get the first supplier
109 s1 = topology_m2.ms["supplier1"]
110
111 # Create a user for testing
112 log.info("Creating test user...")
113 users = UserAccounts(s1, DEFAULT_SUFFIX)
114 user1000 = users.create_test_user()
115 user1000.set("userPassword", PW_DM)
116
117 # Create an organizational unit 'Accounting'
118 log.info("Creating 'Accounting' organizational unit...")
119 ous = OrganizationalUnits(s1, DEFAULT_SUFFIX)
120 accounting = ous.create(properties={'ou': 'Accounting'})
121
122 # Create another user within the 'Accounting' unit
123 users = UserAccounts(s1, DEFAULT_SUFFIX, rdn='ou=Accounting')
124 user1 = users.create_test_user(uid=1, gid=1)
125
126 def fin():
127 """Deletes entries after the test."""
128 log.info("Deleting test entries post test execution...")
129 user1.delete()
130 user1000.delete()
131 accounting.delete()
132
133 request.addfinalizer(fin)
134
135 return user1
136
137
138 @pytest.mark.parametrize('subtype', (';lang-ja', None))
139 def test_aci_subtype_search(topology_m2, user_for_test, subtype):
140 """Test to verify the ACI subtype search functionality
141
142 :id: 83ac5e20-91e8-408e-a253-05787569a580
143 :parametrized: yes
144 :setup: MMR with two suppliers
145 :steps:
146 1. Set password for the test user.
147 2. Add an ACI with attribute subtype.
148 3. Set attributes for the test user.
149 4. Search for the added attribute.
150 :expectedresults:
151 1. Password for the test user is successfully set.
152 2. The ACI with the specified subtype (if any) is successfully added.
153 3. The attributes are successfully set for the test user.
154 4. If a subtype is defined:
155 - The search retrieves the attribute with the subtype.
156 - Attributes 'description' and 'description;binary' are not retrieved.
157 If no subtype is defined:
158 - The search retrieves the attributes 'description' and 'description;binary'.
159 - The attribute with the subtype is also retrieved.
160 """
161
162 TEST_VALUE = "test"
163 USER_SEARCH_DN = user_for_test.dn
164 aci_attr = TARGET_ATTR_SEARCH
165
166 if subtype is not None:
167 aci_attr += subtype
168
169 s1 = topology_m2.ms["supplier1"]
170
171 log.info("Setting password for the test user...")
172 users = UserAccounts(s1, DEFAULT_SUFFIX)
173 user1000 = users.get("test_user_1000")
174 user1000.set("userPassword", PW_DM)
175
176 ous = OrganizationalUnits(s1, DEFAULT_SUFFIX)
177 accounting = ous.get("Accounting")
178
179 # Construct the ACI body
180 ACI_TARGET = '(targetattr = "%s || objectclass")' % aci_attr
181 ACI_ALLOW = '(target = "ldap:///%s") (version 3.0; acl "Read Entries"; allow (read,compare,search) ' % user_for_test.dn
182 ACI_SUBJECT = 'userdn = "ldap:///%s";)' % user1000.dn
183 ACI_BODY = ACI_TARGET + ACI_ALLOW + ACI_SUBJECT
184
185 log.info("Adding an ACI with attribute subtype...")
186 accounting.add('aci', ACI_BODY)
187
188 # Add attributes that we'll search to the test entry
189 log.info("Setting attributes for the test user...")
190 user_for_test.add('description', TEST_VALUE)
191 user_for_test.add('description;binary', TEST_VALUE)
192 if subtype is not None:
193 user_for_test.add(aci_attr, TEST_VALUE)
194
195 conn = user1000.bind(PW_DM)
196
197 log.info("Searching for the added attribute...")
198 try:
199 entries = conn.search_s(USER_SEARCH_DN, ldap.SCOPE_BASE, '(objectclass=*)')
200 entry = str(entries[0])
201 assert f'{aci_attr}: {TEST_VALUE}' in entry
202
203 if subtype is not None:
204 assert f'description: {TEST_VALUE}' not in entry
205 assert f'description;binary: {TEST_VALUE}' not in entry
206 else:
207 assert f'description: {TEST_VALUE}' in entry
208 assert f'description;binary: {TEST_VALUE}' in entry
209
210 # Search specifically for the aci attribute
211 entries = conn.search_s(USER_SEARCH_DN, ldap.SCOPE_BASE, '(objectclass=*)', [aci_attr])
212 entry = str(entries[0])
213 assert f'{aci_attr}: {TEST_VALUE}' in entry
214
215 if subtype is not None:
216 assert f'description: {TEST_VALUE}' not in entry
217 assert f'description;binary: {TEST_VALUE}' not in entry
218 else:
219 assert f'description: {TEST_VALUE}' in entry
220 assert f'description;binary: {TEST_VALUE}' in entry
221
222 except ldap.LDAPError as e:
223 log.fatal('Search failed, error: ' + e.message['desc'])
224 assert False
225
226
227 def test_aci_attr_subtype_targetattr(topology_m2, aci_with_attr_subtype):
228 """Checks, that ACIs allow attribute subtypes in the targetattr keyword
229
230 :id: a99ccda0-5d0b-4d41-99cc-c5e207b3b687
231 :parametrized: yes
232 :setup: MMR with two suppliers,
233 Define two attributes in the schema - targetattr and userattr,
234 Add an ACI with attribute subtypes - "lang-ja", "binary", "phonetic"
235 one by one
236 :steps:
237 1. Search for the added attribute during setup
238 one by one for each subtypes "lang-ja", "binary", "phonetic"
239 :expectedresults:
240 1. Attributes should be found successfully
241 one by one for each subtypes "lang-ja", "binary", "phonetic"
242 """
243
244 log.info("Search for the added attribute")
245 try:
246 entries = topology_m2.ms["supplier1"].search_s(DEFAULT_SUFFIX,
247 ldap.SCOPE_BASE,
248 '(objectclass=*)', ['aci'])
249 entry = str(entries[0])
250 assert aci_with_attr_subtype in entry
251 log.info("The added attribute was found")
252
253 except ldap.LDAPError as e:
254 log.fatal('Search failed, error: ' + e.message['desc'])
255 assert False
256
257
258 def _bind_manager(topology_m2):
259 topology_m2.ms["supplier1"].log.info("Bind as %s " % DN_DM)
260 topology_m2.ms["supplier1"].simple_bind_s(DN_DM, PASSWORD)
261
262
263 def _bind_normal(topology_m2):
264 # bind as bind_entry
265 topology_m2.ms["supplier1"].log.info("Bind as %s" % BIND_DN)
266 topology_m2.ms["supplier1"].simple_bind_s(BIND_DN, BIND_PW)
267
268
269 def _moddn_aci_deny_tree(topology_m2, mod_type=None,
270 target_from=STAGING_DN, target_to=PROD_EXCEPT_DN):
271 """It denies the access moddn_to in cn=except,cn=accounts,SUFFIX"""
272
273 assert mod_type is not None
274
275 ACI_TARGET_FROM = ""
276 ACI_TARGET_TO = ""
277 if target_from:
278 ACI_TARGET_FROM = "(target_from = \"ldap:///%s\")" % (target_from)
279 if target_to:
280 ACI_TARGET_TO = "(target_to = \"ldap:///%s\")" % (target_to)
281
282 ACI_ALLOW = "(version 3.0; acl \"Deny MODDN to prod_except\"; deny (moddn)"
283 ACI_SUBJECT = " userdn = \"ldap:///%s\";)" % BIND_DN
284 ACI_BODY = ACI_TARGET_TO + ACI_TARGET_FROM + ACI_ALLOW + ACI_SUBJECT
285 # topology_m2.ms["supplier1"].modify_s(SUFFIX, mod)
286 topology_m2.ms["supplier1"].log.info("Add a DENY aci under %s " % PROD_EXCEPT_DN)
287 prod_except = OrganizationalRole(topology_m2.ms["supplier1"], PROD_EXCEPT_DN)
288 prod_except.set('aci', ACI_BODY, mod_type)
289
290
291 def _write_aci_staging(topology_m2, mod_type=None):
292 assert mod_type is not None
293
294 ACI_TARGET = "(targetattr= \"uid\")(target=\"ldap:///uid=*,%s\")" % STAGING_DN
295 ACI_ALLOW = "(version 3.0; acl \"write staging entries\"; allow (write)"
296 ACI_SUBJECT = " userdn = \"ldap:///%s\";)" % BIND_DN
297 ACI_BODY = ACI_TARGET + ACI_ALLOW + ACI_SUBJECT
298 suffix = Domain(topology_m2.ms["supplier1"], SUFFIX)
299 suffix.set('aci', ACI_BODY, mod_type)
300
301
302 def _write_aci_production(topology_m2, mod_type=None):
303 assert mod_type is not None
304
305 ACI_TARGET = "(targetattr= \"uid\")(target=\"ldap:///uid=*,%s\")" % PRODUCTION_DN
306 ACI_ALLOW = "(version 3.0; acl \"write production entries\"; allow (write)"
307 ACI_SUBJECT = " userdn = \"ldap:///%s\";)" % BIND_DN
308 ACI_BODY = ACI_TARGET + ACI_ALLOW + ACI_SUBJECT
309 suffix = Domain(topology_m2.ms["supplier1"], SUFFIX)
310 suffix.set('aci', ACI_BODY, mod_type)
311
312
313 def _moddn_aci_staging_to_production(topology_m2, mod_type=None,
314 target_from=STAGING_DN, target_to=PRODUCTION_DN):
315 assert mod_type is not None
316
317 ACI_TARGET_FROM = ""
318 ACI_TARGET_TO = ""
319 if target_from:
320 ACI_TARGET_FROM = "(target_from = \"ldap:///%s\")" % (target_from)
321 if target_to:
322 ACI_TARGET_TO = "(target_to = \"ldap:///%s\")" % (target_to)
323
324 ACI_ALLOW = "(version 3.0; acl \"MODDN from staging to production\"; allow (moddn)"
325 ACI_SUBJECT = " userdn = \"ldap:///%s\";)" % BIND_DN
326 ACI_BODY = ACI_TARGET_FROM + ACI_TARGET_TO + ACI_ALLOW + ACI_SUBJECT
327 suffix = Domain(topology_m2.ms["supplier1"], SUFFIX)
328 suffix.set('aci', ACI_BODY, mod_type)
329
330 _write_aci_staging(topology_m2, mod_type=mod_type)
331
332
333 def _moddn_aci_from_production_to_staging(topology_m2, mod_type=None):
334 assert mod_type is not None
335
336 ACI_TARGET = "(target_from = \"ldap:///%s\") (target_to = \"ldap:///%s\")" % (
337 PRODUCTION_DN, STAGING_DN)
338 ACI_ALLOW = "(version 3.0; acl \"MODDN from production to staging\"; allow (moddn)"
339 ACI_SUBJECT = " userdn = \"ldap:///%s\";)" % BIND_DN
340 ACI_BODY = ACI_TARGET + ACI_ALLOW + ACI_SUBJECT
341 suffix = Domain(topology_m2.ms["supplier1"], SUFFIX)
342 suffix.set('aci', ACI_BODY, mod_type)
343
344 _write_aci_production(topology_m2, mod_type=mod_type)
345
346
347 @pytest.fixture(scope="module")
348 def moddn_setup(topology_m2):
349 """Creates
350 - a staging DIT
351 - a production DIT
352 - add accounts in staging DIT
353 - enable ACL logging (commented for performance reason)
354 """
355
356 m1 = topology_m2.ms["supplier1"]
357 o_roles = OrganizationalRoles(m1, SUFFIX)
358
359 m1.log.info("\n\n######## INITIALIZATION ########\n")
360
361 # entry used to bind with
362 m1.log.info("Add {}".format(BIND_DN))
363 user = UserAccount(m1, BIND_DN)
364 user_props = TEST_USER_PROPERTIES.copy()
365 user_props.update({'sn': BIND_RDN,
366 'cn': BIND_RDN,
367 'uid': BIND_RDN,
368 'userpassword': BIND_PW})
369 user.create(properties=user_props, basedn=SUFFIX)
370
371 # Add anonymous read aci
372 ACI_TARGET = "(target = \"ldap:///%s\")(targetattr=\"*\")" % (SUFFIX)
373 ACI_ALLOW = "(version 3.0; acl \"Anonymous Read access\"; allow (read,search,compare)"
374 ACI_SUBJECT = " userdn = \"ldap:///anyone\";)"
375 ACI_BODY = ACI_TARGET + ACI_ALLOW + ACI_SUBJECT
376 suffix = Domain(m1, SUFFIX)
377 suffix.add('aci', ACI_BODY)
378
379 # DIT for staging
380 m1.log.info("Add {}".format(STAGING_DN))
381 o_roles.create(properties={'cn': STAGING_CN, 'description': "staging DIT"})
382
383 # DIT for production
384 m1.log.info("Add {}".format(PRODUCTION_DN))
385 o_roles.create(properties={'cn': PRODUCTION_CN, 'description': "production DIT"})
386
387 # DIT for production/except
388 m1.log.info("Add {}".format(PROD_EXCEPT_DN))
389 o_roles_prod = OrganizationalRoles(m1, PRODUCTION_DN)
390 o_roles_prod.create(properties={'cn': EXCEPT_CN, 'description': "production except DIT"})
391
392 # enable acl error logging
393 # mod = [(ldap.MOD_REPLACE, 'nsslapd-errorlog-level', '128')]
394 # m1.modify_s(DN_CONFIG, mod)
395 # topology_m2.ms["supplier2"].modify_s(DN_CONFIG, mod)
396
397 # add dummy entries in the staging DIT
398 staging_users = UserAccounts(m1, SUFFIX, rdn="cn={}".format(STAGING_CN))
399 user_props = TEST_USER_PROPERTIES.copy()
400 for cpt in range(MAX_ACCOUNTS):
401 name = "{}{}".format(NEW_ACCOUNT, cpt)
402 user_props.update({'sn': name, 'cn': name, 'uid': name})
403 staging_users.create(properties=user_props)
404
405
406 def test_mode_default_add_deny(topology_m2, moddn_setup):
407 """Tests that the ADD operation fails (no ADD aci on production)
408
409 :id: 301d41d3-b8d8-44c5-8eb9-c2d2816b5a4f
410 :setup: MMR with two suppliers,
411 M1 - staging DIT
412 M2 - production DIT
413 add test accounts in staging DIT
414 :steps:
415 1. Add an entry in production
416 :expectedresults:
417 1. It should fail due to INSUFFICIENT_ACCESS
418 """
419
420 topology_m2.ms["supplier1"].log.info("\n\n######## mode moddn_aci : ADD (should fail) ########\n")
421
422 _bind_normal(topology_m2)
423
424 #
425 # First try to add an entry in production => INSUFFICIENT_ACCESS
426 #
427 try:
428 topology_m2.ms["supplier1"].log.info("Try to add %s" % PRODUCTION_DN)
429 name = "%s%d" % (NEW_ACCOUNT, 0)
430 topology_m2.ms["supplier1"].add_s(Entry(("uid=%s,%s" % (name, PRODUCTION_DN), {
431 'objectclass': "top person".split(),
432 'sn': name,
433 'cn': name,
434 'uid': name})))
435 assert 0 # this is an error, we should not be allowed to add an entry in production
436 except Exception as e:
437 topology_m2.ms["supplier1"].log.info("Exception (expected): %s" % type(e).__name__)
438 assert isinstance(e, ldap.INSUFFICIENT_ACCESS)
439
440
441 def test_mode_default_delete_deny(topology_m2, moddn_setup):
442 """Tests that the DEL operation fails (no 'delete' aci on production)
443
444 :id: 5dcb2213-3875-489a-8cb5-ace057120ad6
445 :setup: MMR with two suppliers,
446 M1 - staging DIT
447 M2 - production DIT
448 add test accounts in staging DIT
449 :steps:
450 1. Delete an entry in staging
451 :expectedresults:
452 1. It should fail due to INSUFFICIENT_ACCESS
453 """
454
455 topology_m2.ms["supplier1"].log.info("\n\n######## DELETE (should fail) ########\n")
456
457 _bind_normal(topology_m2)
458 #
459 # Second try to delete an entry in staging => INSUFFICIENT_ACCESS
460 #
461 try:
462 topology_m2.ms["supplier1"].log.info("Try to delete %s" % STAGING_DN)
463 name = "%s%d" % (NEW_ACCOUNT, 0)
464 topology_m2.ms["supplier1"].delete_s("uid=%s,%s" % (name, STAGING_DN))
465 assert 0 # this is an error, we should not be allowed to add an entry in production
466 except Exception as e:
467 topology_m2.ms["supplier1"].log.info("Exception (expected): %s" % type(e).__name__)
468 assert isinstance(e, ldap.INSUFFICIENT_ACCESS)
469
470
471 @pytest.mark.parametrize("index,tfrom,tto,failure",
472 [(0, STAGING_DN, PRODUCTION_DN, False),
473 (1, STAGING_DN, PRODUCTION_DN, False),
474 (2, STAGING_DN, BAD_PRODUCTION_PATTERN, True),
475 (3, STAGING_PATTERN, PRODUCTION_DN, False),
476 (4, BAD_STAGING_PATTERN, PRODUCTION_DN, True),
477 (5, STAGING_PATTERN, PRODUCTION_PATTERN, False),
478 (6, None, PRODUCTION_PATTERN, False),
479 (7, STAGING_PATTERN, None, False),
480 (8, None, None, False)])
481 def test_moddn_staging_prod(topology_m2, moddn_setup,
482 index, tfrom, tto, failure):
483 """This test case MOVE entry NEW_ACCOUNT0 from staging to prod
484 target_to/target_from: equality filter
485
486 :id: cbafdd68-64d6-431f-9f22-6fbf9ed23ca0
487 :parametrized: yes
488 :setup: MMR with two suppliers,
489 M1 - staging DIT
490 M2 - production DIT
491 add test accounts in staging DIT
492 :steps:
493 1. Try to modify DN with moddn for each value of
494 STAGING_DN -> PRODUCTION_DN
495 2. Try to modify DN with moddn for each value of
496 STAGING_DN -> PRODUCTION_DN with appropriate ACI
497 :expectedresults:
498 1. It should fail due to INSUFFICIENT_ACCESS
499 2. It should pass due to appropriate ACI
500 """
501
502 topology_m2.ms["supplier1"].log.info("\n\n######## MOVE staging -> Prod (%s) ########\n" % index)
503 _bind_normal(topology_m2)
504
505 old_rdn = "uid=%s%s" % (NEW_ACCOUNT, index)
506 old_dn = "%s,%s" % (old_rdn, STAGING_DN)
507 new_rdn = old_rdn
508 new_superior = PRODUCTION_DN
509
510 #
511 # Try to rename without the appropriate ACI => INSUFFICIENT_ACCESS
512 #
513 try:
514 topology_m2.ms["supplier1"].log.info("Try to MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
515 topology_m2.ms["supplier1"].rename_s(old_dn, new_rdn, newsuperior=new_superior)
516 assert 0
517 except AssertionError:
518 topology_m2.ms["supplier1"].log.info(
519 "Exception (not really expected exception but that is fine as it fails to rename)")
520 except Exception as e:
521 topology_m2.ms["supplier1"].log.info("Exception (expected): %s" % type(e).__name__)
522 assert isinstance(e, ldap.INSUFFICIENT_ACCESS)
523
524 # successful MOD with the ACI
525 topology_m2.ms["supplier1"].log.info("\n\n######## MOVE to and from equality filter ########\n")
526 _bind_manager(topology_m2)
527 _moddn_aci_staging_to_production(topology_m2, mod_type=ldap.MOD_ADD,
528 target_from=tfrom, target_to=tto)
529 _bind_normal(topology_m2)
530
531 try:
532 topology_m2.ms["supplier1"].log.info("Try to MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
533 topology_m2.ms["supplier1"].rename_s(old_dn, new_rdn, newsuperior=new_superior)
534 except Exception as e:
535 topology_m2.ms["supplier1"].log.info("Exception (expected): %s" % type(e).__name__)
536 if failure:
537 assert isinstance(e, ldap.INSUFFICIENT_ACCESS)
538
539 # successful MOD with the both ACI
540 _bind_manager(topology_m2)
541 _moddn_aci_staging_to_production(topology_m2, mod_type=ldap.MOD_DELETE,
542 target_from=tfrom, target_to=tto)
543 _bind_normal(topology_m2)
544
545
546 def test_moddn_staging_prod_9(topology_m2, moddn_setup):
547 """Test with nsslapd-moddn-aci set to off so that MODDN requires an 'add' aci.
548
549 :id: 222dd7e8-7ff1-40b8-ad26-6f8e42fbfcd9
550 :setup: MMR with two suppliers,
551 M1 - staging DIT
552 M2 - production DIT
553 add test accounts in staging DIT
554 :steps:
555 1. Try to modify DN with moddn STAGING_DN -> PRODUCTION_DN
556 2. Add the moddn aci that will not be evaluated because of the config flag
557 3. Try to do modDN
558 4. Remove the moddn aci
559 5. Add the 'add' right to the production DN
560 6. Try to modify DN with moddn with 'add' right
561 7. Enable the moddn right
562 8. Try to rename without the appropriate ACI
563 9. Add the 'add' right to the production DN
564 10. Try to rename without the appropriate ACI
565 11. Remove the moddn aci
566 :expectedresults:
567 1. It should fail due to INSUFFICIENT_ACCESS
568 2. It should pass
569 3. It should fail due to INSUFFICIENT_ACCESS
570 4. It should pass
571 5. It should pass
572 6. It should pass
573 7. It should pass
574 8. It should fail due to INSUFFICIENT_ACCESS
575 9. It should pass
576 10. It should fail due to INSUFFICIENT_ACCESS
577 11. It should pass
578 """
579 topology_m2.ms["supplier1"].log.info("\n\n######## MOVE staging -> Prod (9) ########\n")
580
581 _bind_normal(topology_m2)
582 old_rdn = "uid=%s9" % NEW_ACCOUNT
583 old_dn = "%s,%s" % (old_rdn, STAGING_DN)
584 new_rdn = old_rdn
585 new_superior = PRODUCTION_DN
586 prod = OrganizationalRole(topology_m2.ms["supplier1"], PRODUCTION_DN)
587
588 #
589 # Try to rename without the appropriate ACI => INSUFFICIENT_ACCESS
590 #
591 try:
592 topology_m2.ms["supplier1"].log.info("Try to MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
593 topology_m2.ms["supplier1"].rename_s(old_dn, new_rdn, newsuperior=new_superior)
594 assert 0
595 except AssertionError:
596 topology_m2.ms["supplier1"].log.info(
597 "Exception (not really expected exception but that is fine as it fails to rename)")
598 except Exception as e:
599 topology_m2.ms["supplier1"].log.info("Exception (expected): %s" % type(e).__name__)
600 assert isinstance(e, ldap.INSUFFICIENT_ACCESS)
601
602 #############
603 # Now do tests with no support of moddn aci
604 #############
605 topology_m2.ms["supplier1"].log.info("Disable the moddn right")
606 _bind_manager(topology_m2)
607 topology_m2.ms["supplier1"].config.set(CONFIG_MODDN_ACI_ATTR, 'off')
608
609 # Add the moddn aci that will not be evaluated because of the config flag
610 topology_m2.ms["supplier1"].log.info("\n\n######## MOVE to and from equality filter ########\n")
611 _bind_manager(topology_m2)
612 _moddn_aci_staging_to_production(topology_m2, mod_type=ldap.MOD_ADD,
613 target_from=STAGING_DN, target_to=PRODUCTION_DN)
614 _bind_normal(topology_m2)
615
616 # It will fail because it will test the ADD right
617 try:
618 topology_m2.ms["supplier1"].log.info("Try to MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
619 topology_m2.ms["supplier1"].rename_s(old_dn, new_rdn, newsuperior=new_superior)
620 assert 0
621 except AssertionError:
622 topology_m2.ms["supplier1"].log.info(
623 "Exception (not really expected exception but that is fine as it fails to rename)")
624 except Exception as e:
625 topology_m2.ms["supplier1"].log.info("Exception (expected): %s" % type(e).__name__)
626 assert isinstance(e, ldap.INSUFFICIENT_ACCESS)
627
628 # remove the moddn aci
629 _bind_manager(topology_m2)
630 _moddn_aci_staging_to_production(topology_m2, mod_type=ldap.MOD_DELETE,
631 target_from=STAGING_DN, target_to=PRODUCTION_DN)
632 _bind_normal(topology_m2)
633
634 #
635 # add the 'add' right to the production DN
636 # Then do a successful moddn
637 #
638 ACI_ALLOW = "(version 3.0; acl \"ADD rights to allow moddn\"; allow (add)"
639 ACI_SUBJECT = " userdn = \"ldap:///%s\";)" % BIND_DN
640 ACI_BODY = ACI_ALLOW + ACI_SUBJECT
641
642 _bind_manager(topology_m2)
643 prod.add('aci', ACI_BODY)
644 _write_aci_staging(topology_m2, mod_type=ldap.MOD_ADD)
645 _bind_normal(topology_m2)
646
647 topology_m2.ms["supplier1"].log.info("Try to MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
648 topology_m2.ms["supplier1"].rename_s(old_dn, new_rdn, newsuperior=new_superior)
649
650 _bind_manager(topology_m2)
651 prod.remove('aci', ACI_BODY)
652 _write_aci_staging(topology_m2, mod_type=ldap.MOD_DELETE)
653 _bind_normal(topology_m2)
654
655 #############
656 # Now do tests with support of moddn aci
657 #############
658 topology_m2.ms["supplier1"].log.info("Enable the moddn right")
659 _bind_manager(topology_m2)
660 topology_m2.ms["supplier1"].config.set(CONFIG_MODDN_ACI_ATTR, 'on')
661
662 topology_m2.ms["supplier1"].log.info("\n\n######## MOVE staging -> Prod (10) ########\n")
663
664 _bind_normal(topology_m2)
665 old_rdn = "uid=%s10" % NEW_ACCOUNT
666 old_dn = "%s,%s" % (old_rdn, STAGING_DN)
667 new_rdn = old_rdn
668 new_superior = PRODUCTION_DN
669
670 #
671 # Try to rename without the appropriate ACI => INSUFFICIENT_ACCESS
672 #
673 try:
674 topology_m2.ms["supplier1"].log.info("Try to MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
675 topology_m2.ms["supplier1"].rename_s(old_dn, new_rdn, newsuperior=new_superior)
676 assert 0
677 except AssertionError:
678 topology_m2.ms["supplier1"].log.info(
679 "Exception (not really expected exception but that is fine as it fails to rename)")
680 except Exception as e:
681 topology_m2.ms["supplier1"].log.info("Exception (expected): %s" % type(e).__name__)
682 assert isinstance(e, ldap.INSUFFICIENT_ACCESS)
683
684 #
685 # add the 'add' right to the production DN
686 # Then do a failing moddn
687 #
688 ACI_ALLOW = "(version 3.0; acl \"ADD rights to allow moddn\"; allow (add)"
689 ACI_SUBJECT = " userdn = \"ldap:///%s\";)" % BIND_DN
690 ACI_BODY = ACI_ALLOW + ACI_SUBJECT
691
692 _bind_manager(topology_m2)
693 prod.add('aci', ACI_BODY)
694 _write_aci_staging(topology_m2, mod_type=ldap.MOD_ADD)
695 _bind_normal(topology_m2)
696
697 try:
698 topology_m2.ms["supplier1"].log.info("Try to MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
699 topology_m2.ms["supplier1"].rename_s(old_dn, new_rdn, newsuperior=new_superior)
700 assert 0
701 except AssertionError:
702 topology_m2.ms["supplier1"].log.info(
703 "Exception (not really expected exception but that is fine as it fails to rename)")
704 except Exception as e:
705 topology_m2.ms["supplier1"].log.info("Exception (expected): %s" % type(e).__name__)
706 assert isinstance(e, ldap.INSUFFICIENT_ACCESS)
707
708 _bind_manager(topology_m2)
709 prod.remove('aci', ACI_BODY)
710 _write_aci_staging(topology_m2, mod_type=ldap.MOD_DELETE)
711 _bind_normal(topology_m2)
712
713 # Add the moddn aci that will be evaluated because of the config flag
714 topology_m2.ms["supplier1"].log.info("\n\n######## MOVE to and from equality filter ########\n")
715 _bind_manager(topology_m2)
716 _moddn_aci_staging_to_production(topology_m2, mod_type=ldap.MOD_ADD,
717 target_from=STAGING_DN, target_to=PRODUCTION_DN)
718 _bind_normal(topology_m2)
719
720 topology_m2.ms["supplier1"].log.info("Try to MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
721 topology_m2.ms["supplier1"].rename_s(old_dn, new_rdn, newsuperior=new_superior)
722
723 # remove the moddn aci
724 _bind_manager(topology_m2)
725 _moddn_aci_staging_to_production(topology_m2, mod_type=ldap.MOD_DELETE,
726 target_from=STAGING_DN, target_to=PRODUCTION_DN)
727 _bind_normal(topology_m2)
728
729
730 def test_moddn_prod_staging(topology_m2, moddn_setup):
731 """This test checks that we can move ACCOUNT11 from staging to prod
732 but not move back ACCOUNT11 from prod to staging
733
734 :id: 2b061e92-483f-4399-9f56-8d1c1898b043
735 :setup: MMR with two suppliers,
736 M1 - staging DIT
737 M2 - production DIT
738 add test accounts in staging DIT
739 :steps:
740 1. Try to rename without the appropriate ACI
741 2. Try to MOD with the ACI from stage to production
742 3. Try to move back the entry to staging from production
743 :expectedresults:
744 1. It should fail due to INSUFFICIENT_ACCESS
745 2. It should pass
746 3. It should fail due to INSUFFICIENT_ACCESS
747 """
748
749 topology_m2.ms["supplier1"].log.info("\n\n######## MOVE staging -> Prod (11) ########\n")
750
751 _bind_normal(topology_m2)
752
753 old_rdn = "uid=%s11" % NEW_ACCOUNT
754 old_dn = "%s,%s" % (old_rdn, STAGING_DN)
755 new_rdn = old_rdn
756 new_superior = PRODUCTION_DN
757
758 #
759 # Try to rename without the appropriate ACI => INSUFFICIENT_ACCESS
760 #
761 try:
762 topology_m2.ms["supplier1"].log.info("Try to MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
763 topology_m2.ms["supplier1"].rename_s(old_dn, new_rdn, newsuperior=new_superior)
764 assert 0
765 except AssertionError:
766 topology_m2.ms["supplier1"].log.info(
767 "Exception (not really expected exception but that is fine as it fails to rename)")
768 except Exception as e:
769 topology_m2.ms["supplier1"].log.info("Exception (expected): %s" % type(e).__name__)
770 assert isinstance(e, ldap.INSUFFICIENT_ACCESS)
771
772 # successful MOD with the ACI
773 topology_m2.ms["supplier1"].log.info("\n\n######## MOVE to and from equality filter ########\n")
774 _bind_manager(topology_m2)
775 _moddn_aci_staging_to_production(topology_m2, mod_type=ldap.MOD_ADD,
776 target_from=STAGING_DN, target_to=PRODUCTION_DN)
777 _bind_normal(topology_m2)
778
779 topology_m2.ms["supplier1"].log.info("Try to MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
780 topology_m2.ms["supplier1"].rename_s(old_dn, new_rdn, newsuperior=new_superior)
781
782 # Now check we can not move back the entry to staging
783 old_rdn = "uid=%s11" % NEW_ACCOUNT
784 old_dn = "%s,%s" % (old_rdn, PRODUCTION_DN)
785 new_rdn = old_rdn
786 new_superior = STAGING_DN
787
788 # add the write right because we want to check the moddn
789 _bind_manager(topology_m2)
790 _write_aci_production(topology_m2, mod_type=ldap.MOD_ADD)
791 _bind_normal(topology_m2)
792
793 try:
794 topology_m2.ms["supplier1"].log.info("Try to move back MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
795 topology_m2.ms["supplier1"].rename_s(old_dn, new_rdn, newsuperior=new_superior)
796 assert 0
797 except AssertionError:
798 topology_m2.ms["supplier1"].log.info(
799 "Exception (not really expected exception but that is fine as it fails to rename)")
800 except Exception as e:
801 topology_m2.ms["supplier1"].log.info("Exception (expected): %s" % type(e).__name__)
802 assert isinstance(e, ldap.INSUFFICIENT_ACCESS)
803
804 _bind_manager(topology_m2)
805 _write_aci_production(topology_m2, mod_type=ldap.MOD_DELETE)
806 _bind_normal(topology_m2)
807
808 # successful MOD with the both ACI
809 _bind_manager(topology_m2)
810 _moddn_aci_staging_to_production(topology_m2, mod_type=ldap.MOD_DELETE,
811 target_from=STAGING_DN, target_to=PRODUCTION_DN)
812 _bind_normal(topology_m2)
813
814
815 def test_check_repl_M2_to_M1(topology_m2, moddn_setup):
816 """Checks that replication is still working M2->M1, using ACCOUNT12
817
818 :id: 08ac131d-34b7-443f-aacd-23025bbd7de1
819 :setup: MMR with two suppliers,
820 M1 - staging DIT
821 M2 - production DIT
822 add test accounts in staging DIT
823 :steps:
824 1. Add an entry in M2
825 2. Search entry on M1
826 :expectedresults:
827 1. It should pass
828 2. It should pass
829 """
830
831 topology_m2.ms["supplier1"].log.info("Bind as %s (M2)" % DN_DM)
832 topology_m2.ms["supplier2"].simple_bind_s(DN_DM, PASSWORD)
833
834 rdn = "uid=%s12" % NEW_ACCOUNT
835 dn = "%s,%s" % (rdn, STAGING_DN)
836 new_account = UserAccount(topology_m2.ms["supplier2"], dn)
837
838 # First wait for the ACCOUNT19 entry being replicated on M2
839 loop = 0
840 while loop <= 10:
841 try:
842 ent = topology_m2.ms["supplier2"].getEntry(dn, ldap.SCOPE_BASE, "(objectclass=*)")
843 break
844 except ldap.NO_SUCH_OBJECT:
845 time.sleep(1)
846 loop += 1
847 assert loop <= 10
848
849 attribute = 'description'
850 tested_value = b'Hello world'
851 topology_m2.ms["supplier1"].log.info("Update (M2) %s (%s)" % (dn, attribute))
852 new_account.add(attribute, tested_value)
853
854 loop = 0
855 while loop <= 10:
856 ent = topology_m2.ms["supplier1"].getEntry(dn, ldap.SCOPE_BASE, "(objectclass=*)")
857 assert ent is not None
858 if ent.hasAttr(attribute) and (ent.getValue(attribute) == tested_value):
859 break
860
861 time.sleep(1)
862 loop += 1
863 assert loop < 10
864 topology_m2.ms["supplier1"].log.info("Update %s (%s) replicated on M1" % (dn, attribute))
865
866
867 def test_moddn_staging_prod_except(topology_m2, moddn_setup):
868 """This test case MOVE entry NEW_ACCOUNT13 from staging to prod
869 but fails to move entry NEW_ACCOUNT14 from staging to prod_except
870
871 :id: 02d34f4c-8574-428d-b43f-31227426392c
872 :setup: MMR with two suppliers,
873 M1 - staging DIT
874 M2 - production DIT
875 add test accounts in staging DIT
876 :steps:
877 1. Try to move entry staging -> Prod
878 without the appropriate ACI
879 2. Do MOD with the appropriate ACI
880 3. Try to move an entry under Prod/Except from stage
881 4. Try to do MOD with appropriate ACI
882 :expectedresults:
883 1. It should fail due to INSUFFICIENT_ACCESS
884 2. It should pass
885 3. It should fail due to INSUFFICIENT_ACCESS
886 4. It should pass
887 """
888
889 topology_m2.ms["supplier1"].log.info("\n\n######## MOVE staging -> Prod (13) ########\n")
890 _bind_normal(topology_m2)
891
892 old_rdn = "uid=%s13" % NEW_ACCOUNT
893 old_dn = "%s,%s" % (old_rdn, STAGING_DN)
894 new_rdn = old_rdn
895 new_superior = PRODUCTION_DN
896
897 #
898 # Try to rename without the appropriate ACI => INSUFFICIENT_ACCESS
899 #
900 try:
901 topology_m2.ms["supplier1"].log.info("Try to MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
902 topology_m2.ms["supplier1"].rename_s(old_dn, new_rdn, newsuperior=new_superior)
903 assert 0
904 except AssertionError:
905 topology_m2.ms["supplier1"].log.info(
906 "Exception (not really expected exception but that is fine as it fails to rename)")
907 except Exception as e:
908 topology_m2.ms["supplier1"].log.info("Exception (expected): %s" % type(e).__name__)
909 assert isinstance(e, ldap.INSUFFICIENT_ACCESS)
910
911 # successful MOD with the ACI
912 topology_m2.ms["supplier1"].log.info("\n\n######## MOVE to and from equality filter ########\n")
913 _bind_manager(topology_m2)
914 _moddn_aci_staging_to_production(topology_m2, mod_type=ldap.MOD_ADD,
915 target_from=STAGING_DN, target_to=PRODUCTION_DN)
916 _moddn_aci_deny_tree(topology_m2, mod_type=ldap.MOD_ADD)
917 _bind_normal(topology_m2)
918
919 topology_m2.ms["supplier1"].log.info("Try to MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
920 topology_m2.ms["supplier1"].rename_s(old_dn, new_rdn, newsuperior=new_superior)
921
922 #
923 # Now try to move an entry under except
924 #
925 topology_m2.ms["supplier1"].log.info("\n\n######## MOVE staging -> Prod/Except (14) ########\n")
926 old_rdn = "uid=%s14" % NEW_ACCOUNT
927 old_dn = "%s,%s" % (old_rdn, STAGING_DN)
928 new_rdn = old_rdn
929 new_superior = PROD_EXCEPT_DN
930 try:
931 topology_m2.ms["supplier1"].log.info("Try to MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
932 topology_m2.ms["supplier1"].rename_s(old_dn, new_rdn, newsuperior=new_superior)
933 assert 0
934 except AssertionError:
935 topology_m2.ms["supplier1"].log.info(
936 "Exception (not really expected exception but that is fine as it fails to rename)")
937 except Exception as e:
938 topology_m2.ms["supplier1"].log.info("Exception (expected): %s" % type(e).__name__)
939 assert isinstance(e, ldap.INSUFFICIENT_ACCESS)
940
941 # successful MOD with the both ACI
942 _bind_manager(topology_m2)
943 _moddn_aci_staging_to_production(topology_m2, mod_type=ldap.MOD_DELETE,
944 target_from=STAGING_DN, target_to=PRODUCTION_DN)
945 _moddn_aci_deny_tree(topology_m2, mod_type=ldap.MOD_DELETE)
946 _bind_normal(topology_m2)
947
948
949 def test_mode_default_ger_no_moddn(topology_m2, moddn_setup):
950 """mode moddn_aci : Check Get Effective Rights Controls for entries
951
952 :id: f4785d73-3b14-49c0-b981-d6ff96fa3496
953 :setup: MMR with two suppliers,
954 M1 - staging DIT
955 M2 - production DIT
956 add test accounts in staging DIT
957 :steps:
958 1. Search for GER controls on M1
959 2. Check 'n' is not in the entryLevelRights
960 :expectedresults:
961 1. It should pass
962 2. It should pass
963 """
964
965 topology_m2.ms["supplier1"].log.info("\n\n######## mode moddn_aci : GER no moddn ########\n")
966 request_ctrl = GetEffectiveRightsControl(criticality=True,
967 authzId=ensure_bytes("dn: " + BIND_DN))
968 msg_id = topology_m2.ms["supplier1"].search_ext(PRODUCTION_DN,
969 ldap.SCOPE_SUBTREE,
970 "objectclass=*",
971 serverctrls=[request_ctrl])
972 rtype, rdata, rmsgid, response_ctrl = topology_m2.ms["supplier1"].result3(msg_id)
973 # ger={}
974 value = ''
975 for dn, attrs in rdata:
976 topology_m2.ms["supplier1"].log.info("dn: %s" % dn)
977 value = attrs['entryLevelRights'][0]
978
979 topology_m2.ms["supplier1"].log.info("######## entryLevelRights: %r" % value)
980 assert b'n' not in value
981
982
983 def test_mode_default_ger_with_moddn(topology_m2, moddn_setup):
984 """This test case adds the moddn aci and check ger contains 'n'
985
986 :id: a752a461-432d-483a-89c0-dfb34045a969
987 :setup: MMR with two suppliers,
988 M1 - staging DIT
989 M2 - production DIT
990 add test accounts in staging DIT
991 :steps:
992 1. Add moddn ACI on M2
993 2. Search for GER controls on M1
994 3. Check entryLevelRights value for entries
995 4. Check 'n' is in the entryLevelRights
996 :expectedresults:
997 1. It should pass
998 2. It should pass
999 3. It should pass
1000 4. It should pass
1001 """
1002
1003 topology_m2.ms["supplier1"].log.info("\n\n######## mode moddn_aci: GER with moddn ########\n")
1004
1005 # successful MOD with the ACI
1006 _bind_manager(topology_m2)
1007 _moddn_aci_staging_to_production(topology_m2, mod_type=ldap.MOD_ADD,
1008 target_from=STAGING_DN, target_to=PRODUCTION_DN)
1009 _bind_normal(topology_m2)
1010
1011 request_ctrl = GetEffectiveRightsControl(criticality=True,
1012 authzId=ensure_bytes("dn: " + BIND_DN))
1013 msg_id = topology_m2.ms["supplier1"].search_ext(PRODUCTION_DN,
1014 ldap.SCOPE_SUBTREE,
1015 "objectclass=*",
1016 serverctrls=[request_ctrl])
1017 rtype, rdata, rmsgid, response_ctrl = topology_m2.ms["supplier1"].result3(msg_id)
1018 # ger={}
1019 value = ''
1020 for dn, attrs in rdata:
1021 topology_m2.ms["supplier1"].log.info("dn: %s" % dn)
1022 value = attrs['entryLevelRights'][0]
1023
1024 topology_m2.ms["supplier1"].log.info("######## entryLevelRights: %r" % value)
1025 assert b'n' in value
1026
1027 # successful MOD with the both ACI
1028 _bind_manager(topology_m2)
1029 _moddn_aci_staging_to_production(topology_m2, mod_type=ldap.MOD_DELETE,
1030 target_from=STAGING_DN, target_to=PRODUCTION_DN)
1031 _bind_normal(topology_m2)
1032
1033
1034 def test_mode_legacy_ger_no_moddn1(topology_m2, moddn_setup):
1035 """This test checks mode legacy : GER no moddn
1036
1037 :id: e783e05b-d0d0-4fd4-9572-258a81b7bd24
1038 :setup: MMR with two suppliers,
1039 M1 - staging DIT
1040 M2 - production DIT
1041 add test accounts in staging DIT
1042 :steps:
1043 1. Disable ACI checks - set nsslapd-moddn-aci: off
1044 2. Search for GER controls on M1
1045 3. Check entryLevelRights value for entries
1046 4. Check 'n' is not in the entryLevelRights
1047 :expectedresults:
1048 1. It should pass
1049 2. It should pass
1050 3. It should pass
1051 4. It should pass
1052 """
1053
1054 topology_m2.ms["supplier1"].log.info("\n\n######## Disable the moddn aci mod ########\n")
1055 _bind_manager(topology_m2)
1056 topology_m2.ms["supplier1"].config.set(CONFIG_MODDN_ACI_ATTR, 'off')
1057
1058 topology_m2.ms["supplier1"].log.info("\n\n######## mode legacy 1: GER no moddn ########\n")
1059 request_ctrl = GetEffectiveRightsControl(criticality=True, authzId=ensure_bytes("dn: " + BIND_DN))
1060 msg_id = topology_m2.ms["supplier1"].search_ext(PRODUCTION_DN,
1061 ldap.SCOPE_SUBTREE,
1062 "objectclass=*",
1063 serverctrls=[request_ctrl])
1064 rtype, rdata, rmsgid, response_ctrl = topology_m2.ms["supplier1"].result3(msg_id)
1065 # ger={}
1066 value = ''
1067 for dn, attrs in rdata:
1068 topology_m2.ms["supplier1"].log.info("dn: %s" % dn)
1069 value = attrs['entryLevelRights'][0]
1070
1071 topology_m2.ms["supplier1"].log.info("######## entryLevelRights: %r" % value)
1072 assert b'n' not in value
1073
1074
1075 def test_mode_legacy_ger_no_moddn2(topology_m2, moddn_setup):
1076 """This test checks mode legacy : GER no moddn
1077
1078 :id: af87e024-1744-4f1d-a2d3-ea2687e2351d
1079 :setup: MMR with two suppliers,
1080 M1 - staging DIT
1081 M2 - production DIT
1082 add test accounts in staging DIT
1083 :steps:
1084 1. Disable ACI checks - set nsslapd-moddn-aci: off
1085 2. Add moddn ACI on M1
1086 3. Search for GER controls on M1
1087 4. Check entryLevelRights value for entries
1088 5. Check 'n' is not in the entryLevelRights
1089 :expectedresults:
1090 1. It should pass
1091 2. It should pass
1092 3. It should pass
1093 4. It should be pass
1094 5. It should pass
1095 """
1096
1097 topology_m2.ms["supplier1"].log.info("\n\n######## Disable the moddn aci mod ########\n")
1098 _bind_manager(topology_m2)
1099 topology_m2.ms["supplier1"].config.set(CONFIG_MODDN_ACI_ATTR, 'off')
1100
1101 topology_m2.ms["supplier1"].log.info("\n\n######## mode legacy 2: GER no moddn ########\n")
1102 # successful MOD with the ACI
1103 _bind_manager(topology_m2)
1104 _moddn_aci_staging_to_production(topology_m2, mod_type=ldap.MOD_ADD,
1105 target_from=STAGING_DN, target_to=PRODUCTION_DN)
1106 _bind_normal(topology_m2)
1107
1108 request_ctrl = GetEffectiveRightsControl(criticality=True,
1109 authzId=ensure_bytes("dn: " + BIND_DN))
1110 msg_id = topology_m2.ms["supplier1"].search_ext(PRODUCTION_DN,
1111 ldap.SCOPE_SUBTREE,
1112 "objectclass=*",
1113 serverctrls=[request_ctrl])
1114 rtype, rdata, rmsgid, response_ctrl = topology_m2.ms["supplier1"].result3(msg_id)
1115 # ger={}
1116 value = ''
1117 for dn, attrs in rdata:
1118 topology_m2.ms["supplier1"].log.info("dn: %s" % dn)
1119 value = attrs['entryLevelRights'][0]
1120
1121 topology_m2.ms["supplier1"].log.info("######## entryLevelRights: %r" % value)
1122 assert b'n' not in value
1123
1124 # successful MOD with the both ACI
1125 _bind_manager(topology_m2)
1126 _moddn_aci_staging_to_production(topology_m2, mod_type=ldap.MOD_DELETE,
1127 target_from=STAGING_DN, target_to=PRODUCTION_DN)
1128 _bind_normal(topology_m2)
1129
1130
1131 def test_mode_legacy_ger_with_moddn(topology_m2, moddn_setup):
1132 """This test checks mode legacy : GER with moddn
1133
1134 :id: 37c1e537-1b5d-4fab-b62a-50cd8c5b3493
1135 :setup: MMR with two suppliers,
1136 M1 - staging DIT
1137 M2 - production DIT
1138 add test accounts in staging DIT
1139 :steps:
1140 1. Disable ACI checks - set nsslapd-moddn-aci: off
1141 2. Add moddn ACI on M1
1142 3. Search for GER controls on M1
1143 4. Check entryLevelRights value for entries
1144 5. Check 'n' is in the entryLevelRights
1145 6. Try MOD with the both ACI
1146 :expectedresults:
1147 1. It should pass
1148 2. It should pass
1149 3. It should pass
1150 4. It should pass
1151 5. It should pass
1152 6. It should pass
1153 """
1154
1155 suffix = Domain(topology_m2.ms["supplier1"], SUFFIX)
1156
1157 topology_m2.ms["supplier1"].log.info("\n\n######## Disable the moddn aci mod ########\n")
1158 _bind_manager(topology_m2)
1159 topology_m2.ms["supplier1"].config.set(CONFIG_MODDN_ACI_ATTR, 'off')
1160
1161 topology_m2.ms["supplier1"].log.info("\n\n######## mode legacy : GER with moddn ########\n")
1162
1163 # being allowed to read/write the RDN attribute use to allow the RDN
1164 ACI_TARGET = "(target = \"ldap:///%s\")(targetattr=\"uid\")" % (PRODUCTION_DN)
1165 ACI_ALLOW = "(version 3.0; acl \"MODDN production changing the RDN attribute\"; allow (read,search,write)"
1166 ACI_SUBJECT = " userdn = \"ldap:///%s\";)" % BIND_DN
1167 ACI_BODY = ACI_TARGET + ACI_ALLOW + ACI_SUBJECT
1168
1169 # successful MOD with the ACI
1170 _bind_manager(topology_m2)
1171 suffix.add('aci', ACI_BODY)
1172 _bind_normal(topology_m2)
1173
1174 request_ctrl = GetEffectiveRightsControl(criticality=True, authzId=ensure_bytes("dn: " + BIND_DN))
1175 msg_id = topology_m2.ms["supplier1"].search_ext(PRODUCTION_DN,
1176 ldap.SCOPE_SUBTREE,
1177 "objectclass=*",
1178 serverctrls=[request_ctrl])
1179 rtype, rdata, rmsgid, response_ctrl = topology_m2.ms["supplier1"].result3(msg_id)
1180 # ger={}
1181 value = ''
1182 for dn, attrs in rdata:
1183 topology_m2.ms["supplier1"].log.info("dn: %s" % dn)
1184 value = attrs['entryLevelRights'][0]
1185
1186 topology_m2.ms["supplier1"].log.info("######## entryLevelRights: %r" % value)
1187 assert b'n' in value
1188
1189 # successful MOD with the both ACI
1190 _bind_manager(topology_m2)
1191 suffix.remove('aci', ACI_BODY)
1192 # _bind_normal(topology_m2)
1193
1194
1195 @pytest.fixture(scope="module")
1196 def rdn_write_setup(topology_m2):
1197 topology_m2.ms["supplier1"].log.info("\n\n######## Add entry tuser ########\n")
1198 user = UserAccount(topology_m2.ms["supplier1"], SRC_ENTRY_DN)
1199 user_props = TEST_USER_PROPERTIES.copy()
1200 user_props.update({'sn': SRC_ENTRY_CN,
1201 'cn': SRC_ENTRY_CN,
1202 'userpassword': BIND_PW})
1203 user.create(properties=user_props, basedn=SUFFIX)
1204
1205
1206 def test_rdn_write_get_ger(topology_m2, rdn_write_setup):
1207 """This test checks GER rights for anonymous
1208
1209 :id: d5d85f87-b53d-4f50-8fa6-a9e55c75419b
1210 :setup: MMR with two suppliers,
1211 Add entry tuser
1212 :steps:
1213 1. Search for GER controls on M1
1214 2. Check entryLevelRights value for entries
1215 3. Check 'n' is not in the entryLevelRights
1216 :expectedresults:
1217 1. It should pass
1218 2. It should be pass
1219 3. It should pass
1220 """
1221
1222 ANONYMOUS_DN = ""
1223 topology_m2.ms["supplier1"].log.info("\n\n######## GER rights for anonymous ########\n")
1224 request_ctrl = GetEffectiveRightsControl(criticality=True,
1225 authzId=ensure_bytes("dn:" + ANONYMOUS_DN))
1226 msg_id = topology_m2.ms["supplier1"].search_ext(SUFFIX,
1227 ldap.SCOPE_SUBTREE,
1228 "objectclass=*",
1229 serverctrls=[request_ctrl])
1230 rtype, rdata, rmsgid, response_ctrl = topology_m2.ms["supplier1"].result3(msg_id)
1231 value = ''
1232 for dn, attrs in rdata:
1233 topology_m2.ms["supplier1"].log.info("dn: %s" % dn)
1234 for value in attrs['entryLevelRights']:
1235 topology_m2.ms["supplier1"].log.info("######## entryLevelRights: %r" % value)
1236 assert b'n' not in value
1237
1238
1239 def test_rdn_write_modrdn_anonymous(topology_m2, rdn_write_setup):
1240 """Tests anonymous user for modrdn
1241
1242 :id: fc07be23-3341-44ab-a53c-c68c5f9569c7
1243 :setup: MMR with two suppliers,
1244 Add entry tuser
1245 :steps:
1246 1. Bind as anonymous user
1247 2. Try to perform MODRDN operation (SRC_ENTRY_DN -> DST_ENTRY_CN)
1248 3. Try to search DST_ENTRY_CN
1249 :expectedresults:
1250 1. It should pass
1251 2. It should fails with INSUFFICIENT_ACCESS
1252 3. It should fails with NO_SUCH_OBJECT
1253 """
1254
1255 ANONYMOUS_DN = ""
1256 topology_m2.ms["supplier1"].close()
1257 topology_m2.ms["supplier1"].binddn = ANONYMOUS_DN
1258 topology_m2.ms["supplier1"].open()
1259 msg_id = topology_m2.ms["supplier1"].search_ext("", ldap.SCOPE_BASE, "objectclass=*")
1260 rtype, rdata, rmsgid, response_ctrl = topology_m2.ms["supplier1"].result3(msg_id)
1261 for dn, attrs in rdata:
1262 topology_m2.ms["supplier1"].log.info("dn: %s" % dn)
1263 for attr in attrs:
1264 topology_m2.ms["supplier1"].log.info("######## %r: %r" % (attr, attrs[attr]))
1265
1266 try:
1267 topology_m2.ms["supplier1"].rename_s(SRC_ENTRY_DN, "cn=%s" % DST_ENTRY_CN, delold=True)
1268 except Exception as e:
1269 topology_m2.ms["supplier1"].log.info("Exception (expected): %s" % type(e).__name__)
1270 isinstance(e, ldap.INSUFFICIENT_ACCESS)
1271
1272 try:
1273 topology_m2.ms["supplier1"].getEntry(DST_ENTRY_DN, ldap.SCOPE_BASE, "objectclass=*")
1274 assert False
1275 except Exception as e:
1276 topology_m2.ms["supplier1"].log.info("The entry was not renamed (expected)")
1277 isinstance(e, ldap.NO_SUCH_OBJECT)
1278
1279 _bind_manager(topology_m2)
1280
1281
1282 if __name__ == '__main__':
1283 # Run isolated
1284 # -s for DEBUG mode
1285 CURRENT_FILE = os.path.realpath(__file__)
1286 pytest.main("-s %s" % CURRENT_FILE)