Debian Codegraph @

dirsrvtests/tests/suites/betxns/betxn_test.py

raw
1 # --- BEGIN COPYRIGHT BLOCK ---
2 # Copyright (C) 2016 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 import ldap
11 import os
12 from lib389.tasks import *
13 from lib389.utils import *
14 from test389.topologies import topology_st
15 from lib389.plugins import (SevenBitCheckPlugin, AttributeUniquenessPlugin,
16 MemberOfPlugin, ManagedEntriesPlugin,
17 ReferentialIntegrityPlugin, MEPTemplates,
18 MEPConfigs, LinkedAttributesPlugin,
19 LinkedAttributesConfigs, AutoMembershipPlugin, AutoMembershipDefinitions,
20 RetroChangelogPlugin)
21 from lib389.plugins import MemberOfPlugin
22 from lib389.idm.user import UserAccounts, TEST_USER_PROPERTIES, nsUserAccounts
23 from lib389.idm.organizationalunit import OrganizationalUnits
24 from lib389.idm.group import Groups, Group
25 from lib389.idm.domain import Domain
26 from lib389._constants import DEFAULT_SUFFIX
27
28 pytestmark = pytest.mark.tier1
29
30 logging.getLogger(__name__).setLevel(logging.DEBUG)
31 log = logging.getLogger(__name__)
32 USER_PASSWORD = 'password'
33
34 def retry_if_busy(f):
35 for x in range(1000):
36 try:
37 return f()
38 except ldap.BUSY:
39 time.sleep(0.02)
40
41 log.error("Too many retries!")
42 assert False
43
44
45 def test_betxt_7bit(topology_st):
46 """Test that the 7-bit plugin correctly rejects an invalid update
47
48 :id: 9e2ab27b-eda9-4cd9-9968-a1a8513210fd
49
50 :setup: Standalone instance and enabled dynamic plugins
51
52 :steps: 1. Enable PLUGIN_7_BIT_CHECK to "ON"
53 2. Add test user
54 3. Try to Modify test user's RDN to have 8 bit RDN
55 4. Execute search operation for new 8 bit RDN
56 5. Remove the test user for cleanup
57
58 :expectedresults:
59 1. PLUGIN_7_BIT_CHECK should be ON
60 2. Test users should be added
61 3. Modify RDN for test user should FAIL
62 4. Search operation should FAIL
63 5. Test user should be removed
64 """
65
66 log.info('Running test_betxt_7bit...')
67
68 BAD_RDN = u'uid=Fu\u00c4\u00e8'
69
70 sevenbc = SevenBitCheckPlugin(topology_st.standalone)
71 sevenbc.enable()
72 topology_st.standalone.restart()
73
74 users = UserAccounts(topology_st.standalone, basedn=DEFAULT_SUFFIX)
75 user = users.create(properties=TEST_USER_PROPERTIES)
76
77 # Attempt a modrdn, this should fail
78 with pytest.raises(ldap.LDAPError):
79 user.rename(BAD_RDN)
80
81 # Make sure the operation did not succeed, attempt to search for the new RDN
82 with pytest.raises(ldap.LDAPError):
83 users.get(u'Fu\u00c4\u00e8')
84
85 # Make sure original entry is present
86 user_check = users.get("testuser")
87 assert user_check.dn.lower() == user.dn.lower()
88
89 # Cleanup - remove the user
90 user.delete()
91
92 log.info('test_betxt_7bit: PASSED')
93
94
95
96 @pytest.mark.parametrize('unique_attribute, uid_values, sn_values',
97 [('uid', ['testuser2', 'testuser1'], 'user2'),
98 ('sn', 'testuser2', ['user1', 'user2'])])
99 def test_betxn_attr_uniqueness(topology_st, unique_attribute, uid_values, sn_values):
100 """Test that we can not add two entries that have the same attr value that is
101 defined by the plugin
102
103 :id: 42aeb41c-fbb5-4bc6-a97b-56274034d29f
104
105 :setup: Standalone instance and enabled dynamic plugins
106
107 :steps: 1. Enable PLUGIN_ATTR_UNIQUENESS plugin as "ON"
108 2. Add a test user
109 3. Restart server to ensure persistence
110 4. Add another test user having duplicate uid/sn as previous one
111 5. Verify duplicate entry doesn't exist using .exists()
112 6. Verify duplicate entry doesn't exist using search with NO_SUCH_OBJECT
113 7. Cleanup - disable PLUGIN_ATTR_UNIQUENESS plugin as "OFF"
114 8. Cleanup - remove test user entry
115
116 :expectedresults:
117 1. PLUGIN_ATTR_UNIQUENESS plugin should be ON
118 2. Test user should be added
119 3. Server restart should succeed
120 4. Add operation should FAIL
121 5. Duplicate entry should not exist
122 6. Search for duplicate entry should raise NO_SUCH_OBJECT
123 7. PLUGIN_ATTR_UNIQUENESS plugin should be "OFF"
124 8. Test user entry should be removed
125 """
126
127 attruniq = AttributeUniquenessPlugin(topology_st.standalone, dn="cn=attruniq,cn=plugins,cn=config")
128 attruniq.create(properties={'cn': 'attruniq'})
129 attruniq.add_unique_attribute(unique_attribute)
130 attruniq.add_unique_subtree(DEFAULT_SUFFIX)
131 attruniq.enable_all_subtrees()
132 attruniq.enable()
133 topology_st.standalone.restart()
134
135 users = UserAccounts(topology_st.standalone, basedn=DEFAULT_SUFFIX)
136 user1 = users.create(properties={
137 'uid': 'testuser1',
138 'cn': 'testuser1',
139 'sn': 'user1',
140 'uidNumber': '1001',
141 'gidNumber': '2001',
142 'homeDirectory': '/home/testuser1'
143 })
144
145 # Restart server to ensure persistence
146 topology_st.standalone.restart()
147
148 with pytest.raises(ldap.LDAPError):
149 users.create(properties={
150 'uid': uid_values,
151 'cn': 'testuser2',
152 'sn': sn_values,
153 'uidNumber': '1002',
154 'gidNumber': '2002',
155 'homeDirectory': '/home/testuser2'
156 })
157
158 # Verify with .exists() that duplicate entry doesn't exist
159 try:
160 duplicate_user = users.get('testuser2')
161 assert not duplicate_user.exists(), "Duplicate user should not exist after failed creation"
162 except ldap.NO_SUCH_OBJECT:
163 # This is expected - the duplicate user should not exist
164 pass
165
166 # Search and expect NO_SUCH_OBJECT exception
167 with pytest.raises(ldap.NO_SUCH_OBJECT):
168 users.get('testuser2')
169
170 # Clean up for the next test
171 attruniq.disable()
172 attruniq.delete()
173 user1.delete()
174
175 log.info('test_betxn_attr_uniqueness: PASSED')
176
177
178 def test_betxn_memberof(topology_st):
179 """Test PLUGIN_MEMBER_OF plugin
180
181 :id: 70d0b96e-b693-4bf7-bbf5-102a66ac5993
182
183 :setup: Standalone instance and enabled dynamic plugins
184
185 :steps: 1. Enable and configure memberOf plugin
186 2. Set memberofgroupattr="member" and memberofAutoAddOC="referral"
187 3. Add two test groups - group1 and group2
188 4. Add group2 to group1
189 5. Add group1 to group2
190
191 :expectedresults:
192 1. memberOf plugin plugin should be ON
193 2. Set memberofgroupattr="member" and memberofAutoAddOC="referral" should PASS
194 3. Add operation should PASS
195 4. Add operation should FAIL
196 5. Add operation should FAIL
197 """
198
199 memberof = MemberOfPlugin(topology_st.standalone)
200 memberof.enable()
201 memberof.set_autoaddoc('referral')
202 if (memberof.get_memberofdeferredupdate() and memberof.get_memberofdeferredupdate().lower() == "on"):
203 singleTXN = False
204 else:
205 singleTXN = True
206 topology_st.standalone.restart()
207
208 groups = Groups(topology_st.standalone, DEFAULT_SUFFIX)
209 group1 = groups.create(properties={'cn': 'group1'})
210 group2 = groups.create(properties={'cn': 'group2'})
211
212 # We may need to mod groups to not have nsMemberOf ... ?
213 if not ds_is_older('1.3.7'):
214 group1.remove('objectClass', 'nsMemberOf')
215 group2.remove('objectClass', 'nsMemberOf')
216
217 # Add group2 to group1 - it should fail with objectclass violation
218 if singleTXN:
219 with pytest.raises(ldap.OBJECT_CLASS_VIOLATION):
220 group1.add_member(group2.dn)
221
222 # verify entry cache reflects the current/correct state of group1
223 assert not group1.is_member(group2.dn)
224 else:
225 group1.add_member(group2.dn)
226
227 # verify entry cache reflects the current/correct state of group1
228 assert group1.is_member(group2.dn)
229
230 # Done
231 log.info('test_betxn_memberof: PASSED')
232
233
234 def test_betxn_modrdn_memberof_cache_corruption(topology_st):
235 """Test modrdn operations and memberOf be txn post op failures
236
237 :id: 70d0b96e-b693-4bf7-bbf5-102a66ac5994
238
239 :setup: Standalone instance
240
241 :steps: 1. Enable and configure memberOf plugin
242 2. Set memberofgroupattr="member" and memberofAutoAddOC="nsContainer"
243 3. Create group and user outside of memberOf plugin scope
244 4. Do modrdn to move group into scope
245 5. Do modrdn to move group into scope (again)
246
247 :expectedresults:
248 1. memberOf plugin plugin should be ON
249 2. Set memberofgroupattr="member" and memberofAutoAddOC="nsContainer" should PASS
250 3. Creating group and user should PASS
251 4. Modrdn should fail with objectclass violation
252 5. Second modrdn should also fail with objectclass violation
253 """
254
255 peoplebase = 'ou=people,%s' % DEFAULT_SUFFIX
256 memberof = MemberOfPlugin(topology_st.standalone)
257 memberof.enable()
258 memberof.set_autoaddoc('nsContainer') # Bad OC
259 memberof.set('memberOfEntryScope', peoplebase)
260 memberof.set('memberOfAllBackends', 'on')
261 if (memberof.get_memberofdeferredupdate() and memberof.get_memberofdeferredupdate().lower() == "on"):
262 singleTXN = False
263 else:
264 singleTXN = True
265 topology_st.standalone.restart()
266
267 groups = Groups(topology_st.standalone, DEFAULT_SUFFIX)
268 group = groups.create(properties={
269 'cn': 'group',
270 })
271
272 # Create user and add it to group
273 users = UserAccounts(topology_st.standalone, basedn=DEFAULT_SUFFIX)
274 user = users.ensure_state(properties=TEST_USER_PROPERTIES)
275 if not ds_is_older('1.3.7'):
276 user.remove('objectClass', 'nsMemberOf')
277
278 group.add_member(user.dn)
279
280 if singleTXN:
281 # Attempt modrdn that should fail, but the original entry should stay in the cache
282 with pytest.raises(ldap.OBJECT_CLASS_VIOLATION):
283 retry_if_busy(lambda: group.rename('cn=group_to_people', newsuperior=peoplebase))
284
285 # Should fail, but not with NO_SUCH_OBJECT as the original entry should still be in the cache
286 with pytest.raises(ldap.OBJECT_CLASS_VIOLATION):
287 retry_if_busy(lambda: group.rename('cn=group_to_people', newsuperior=peoplebase))
288 else:
289 retry_if_busy(lambda: group.rename('cn=group_to_people', newsuperior=peoplebase))
290 retry_if_busy(lambda: group.rename('cn=group_to_people', newsuperior=peoplebase))
291
292 # Done
293 log.info('test_betxn_modrdn_memberof: PASSED')
294
295
296 def test_ri_and_mep_cache_corruption(topology_st):
297 """Test RI plugin aborts change after MEP plugin fails.
298 This is really testing the entry cache for corruption
299
300 :id: 70d0b96e-b693-4bf7-bbf5-102a66ac5995
301
302 :setup: Standalone instance
303
304 :steps: 1. Enable and configure mep and ri plugins
305 2. Add user and add it to a group
306 3. Disable MEP plugin and remove MEP group
307 4. Delete user
308 5. Check that user is still a member of the group
309
310 :expectedresults:
311 1. Success
312 2. Success
313 3. Success
314 4. It fails with NO_SUCH_OBJECT
315 5. Success
316
317 """
318 # Add ACI so we can test that non-DM user can't delete managed entry
319 domain = Domain(topology_st.standalone, DEFAULT_SUFFIX)
320 ACI_TARGET = f"(target = \"ldap:///{DEFAULT_SUFFIX}\")"
321 ACI_TARGETATTR = "(targetattr = *)"
322 ACI_ALLOW = "(version 3.0; acl \"Admin Access\"; allow (all) "
323 ACI_SUBJECT = "(userdn = \"ldap:///anyone\");)"
324 ACI_BODY = ACI_TARGET + ACI_TARGETATTR + ACI_ALLOW + ACI_SUBJECT
325 domain.add('aci', ACI_BODY)
326
327 # Start plugins
328 topology_st.standalone.config.set('nsslapd-dynamic-plugins', 'on')
329 mep_plugin = ManagedEntriesPlugin(topology_st.standalone)
330 mep_plugin.enable()
331 ri_plugin = ReferentialIntegrityPlugin(topology_st.standalone)
332 ri_plugin.enable()
333
334 # Add our org units
335 ous = OrganizationalUnits(topology_st.standalone, DEFAULT_SUFFIX)
336 ou_people = ous.create(properties={'ou': 'managed_people'})
337 ou_groups = ous.create(properties={'ou': 'managed_groups'})
338
339 # Configure MEP
340 mep_templates = MEPTemplates(topology_st.standalone, DEFAULT_SUFFIX)
341 mep_template1 = mep_templates.create(properties={
342 'cn': 'MEP template',
343 'mepRDNAttr': 'cn',
344 'mepStaticAttr': 'objectclass: groupOfNames|objectclass: extensibleObject'.split('|'),
345 'mepMappedAttr': 'cn: $cn|uid: $cn|gidNumber: $uidNumber'.split('|')
346 })
347 mep_configs = MEPConfigs(topology_st.standalone)
348 mep_configs.create(properties={'cn': 'config',
349 'originScope': ou_people.dn,
350 'originFilter': 'objectclass=posixAccount',
351 'managedBase': ou_groups.dn,
352 'managedTemplate': mep_template1.dn})
353
354 # Add an entry that meets the MEP scope
355 users = UserAccounts(topology_st.standalone, DEFAULT_SUFFIX,
356 rdn='ou={}'.format(ou_people.rdn))
357 user = users.create(properties={
358 'uid': 'test-user1',
359 'cn': 'test-user',
360 'sn': 'test-user',
361 'uidNumber': '10011',
362 'gidNumber': '20011',
363 'homeDirectory': '/home/test-user1'
364 })
365 user.reset_password(USER_PASSWORD)
366 user_bound_conn = user.bind(USER_PASSWORD)
367
368 # Add group
369 groups = Groups(topology_st.standalone, DEFAULT_SUFFIX)
370 user_group = groups.ensure_state(properties={'cn': 'group', 'member': user.dn})
371
372 # Check if a managed group entry was created
373 mep_group = Group(topology_st.standalone, dn='cn={},{}'.format(user.rdn, ou_groups.dn))
374 if not mep_group.exists():
375 log.fatal("MEP group was not created for the user")
376 assert False
377
378 # Test MEP be txn pre op failure does not corrupt entry cache
379 # Should get the same exception for both rename attempts
380 # Try to remove the entry while bound as Admin (non-DM)
381 managed_groups_user_conn = Groups(user_bound_conn, ou_groups.dn, rdn=None)
382 managed_entry_user_conn = managed_groups_user_conn.get(user.rdn)
383 with pytest.raises(ldap.UNWILLING_TO_PERFORM):
384 managed_entry_user_conn.rename("cn=modrdn group")
385 with pytest.raises(ldap.UNWILLING_TO_PERFORM):
386 managed_entry_user_conn.rename("cn=modrdn group")
387
388 # Mess with MEP so it fails
389 mep_plugin.disable()
390 users_mep_group = UserAccounts(topology_st.standalone, mep_group.dn, rdn=None)
391 users_mep_group.create_test_user(1001)
392 mep_plugin.enable()
393
394 # Add another group to verify entry cache is not corrupted
395 test_group = groups.create(properties={'cn': 'test_group'})
396
397 # Try to delete user - it fails because managed entry can't be deleted
398 with pytest.raises(ldap.NOT_ALLOWED_ON_NONLEAF):
399 user.delete()
400
401 # Verify membership is intact
402 if not user_group.is_member(user.dn):
403 log.fatal("Member was incorrectly removed from the group!! Or so it seems")
404
405 # Restart server and test again in case this was a cache issue
406 topology_st.standalone.restart()
407 if user_group.is_member(user.dn):
408 log.info("The entry cache was corrupted")
409 assert False
410
411 assert False
412
413 # Verify test group is still found in entry cache by deleting it
414 test_group.delete()
415 user_group.delete()
416
417 # Success
418 log.info("Test PASSED")
419
420 def test_revert_cache(topology_st, request):
421 """Tests that reversion of the entry cache does not occur
422 during 'normal' failure (like schema violation) but only
423 when a plugin fails
424
425 :id: a2361285-b939-4da0-aa80-7fc54d12c981
426
427 :setup: Standalone instance
428
429 :steps:
430 1. Create a user account (with a homeDirectory)
431 2. Remove the error log file
432 3. Add a second value of homeDirectory
433 4. Check that error log does not contain entry cache reversion
434 5. Configure memberof to trigger a failure
435 6. Do a update the will fail in memberof plugin
436 7. Check that error log does contain entry cache reversion
437
438 :expectedresults:
439 1. Succeeds
440 2. Fails with OBJECT_CLASS_VIOLATION
441 3. Succeeds
442 4. Succeeds
443 5. Succeeds
444 6. Fails with OBJECT_CLASS_VIOLATION
445 7. Succeeds
446 """
447 # Create an test user entry
448 log.info('Create a user without nsMemberOF objectclass')
449 try:
450 users = UserAccounts(topology_st.standalone, DEFAULT_SUFFIX, rdn='ou=people')
451 user = users.create_test_user()
452 user.replace('objectclass', ['top', 'account', 'person', 'inetorgperson', 'posixAccount', 'organizationalPerson', 'nsAccount'])
453 except ldap.LDAPError as e:
454 log.fatal('Failed to create test user: error ' + e.args[0]['desc'])
455 assert False
456
457 # Remove the current error log file
458 topology_st.standalone.stop()
459 lpath = topology_st.standalone.ds_error_log._get_log_path()
460 os.unlink(lpath)
461 topology_st.standalone.start()
462
463 #
464 # Add a second value to 'homeDirectory'
465 # leads to ldap.OBJECT_CLASS_VIOLATION
466 # And check that the entry cache was not reverted
467 try:
468 topology_st.standalone.modify_s(user.dn, [(ldap.MOD_ADD, 'homeDirectory', ensure_bytes('/home/user_new'))])
469 assert False
470 except ldap.OBJECT_CLASS_VIOLATION:
471 pass
472 assert not topology_st.standalone.ds_error_log.match('.*WARN - flush_hash - Upon BETXN callback failure, entry cache is flushed during.*')
473
474 # Prepare memberof so that it will fail during a next update
475 # If memberof plugin can not add 'memberof' to the
476 # member entry, it retries after adding
477 # 'memberOfAutoAddOC' objectclass to the member.
478 # If it fails again the plugin fails with 'object
479 # violation'
480 # To trigger this failure, set 'memberOfAutoAddOC'
481 # to a value that does *not* allow 'memberof' attribute
482 memberof = MemberOfPlugin(topology_st.standalone)
483 memberof.enable()
484 memberof.replace('memberOfAutoAddOC', 'account')
485 memberof.replace('memberofentryscope', DEFAULT_SUFFIX)
486 topology_st.standalone.restart()
487
488 # Try to add the user to demo_group
489 # It should fail because user entry has not 'nsmemberof' objectclass
490 # As this is a BETXN plugin that fails it should revert the entry cache
491 try:
492 GROUP_DN = "cn=demo_group,ou=groups," + DEFAULT_SUFFIX
493 topology_st.standalone.modify_s(GROUP_DN,
494 [(ldap.MOD_REPLACE, 'member', ensure_bytes(user.dn))])
495 assert False
496 except ldap.OBJECT_CLASS_VIOLATION:
497 pass
498 assert topology_st.standalone.ds_error_log.match('.*WARN - flush_hash - Upon BETXN callback failure, entry cache is flushed during.*')
499
500 def fin():
501 user.delete()
502 memberof = MemberOfPlugin(topology_st.standalone)
503 memberof.replace('memberOfAutoAddOC', 'nsmemberof')
504
505 request.addfinalizer(fin)
506
507 @pytest.mark.flaky(max_runs=2, min_passes=1)
508 def test_revert_cache_noloop(topology_st, request):
509 """Tests that when an entry is reverted, if an update
510 hit the reverted entry then the retry loop is aborted
511 and the update gets err=51
512 NOTE: this test requires a dynamic so that the two updates
513 occurs about the same time. If the test becomes fragile it is
514 okay to make it flaky
515
516 :id: 88ef0ba5-8c66-49e6-99c9-9e3f6183917f
517
518 :setup: Standalone instance
519
520 :steps:
521 1. Create a user account (with a homeDirectory)
522 2. Remove the error log file
523 3. Configure memberof to trigger a failure
524 4. Do in a loop 3 parallel updates (they will fail in
525 memberof plugin) and an updated on the reverted entry
526 5. Check that error log does contain entry cache reversion
527
528 :expectedresults:
529 1. Succeeds
530 2. Success
531 3. Succeeds
532 4. Succeeds
533 5. Succeeds
534 """
535 # Create an test user entry
536 log.info('Create a user without nsMemberOF objectclass')
537 try:
538 users = UserAccounts(topology_st.standalone, DEFAULT_SUFFIX, rdn='ou=people')
539 user = users.create_test_user()
540 user.replace('objectclass', ['top', 'account', 'person', 'inetorgperson', 'posixAccount', 'organizationalPerson', 'nsAccount'])
541 except ldap.LDAPError as e:
542 log.fatal('Failed to create test user: error ' + e.args[0]['desc'])
543 assert False
544
545 # Remove the current error log file
546 topology_st.standalone.stop()
547 lpath = topology_st.standalone.ds_error_log._get_log_path()
548 os.unlink(lpath)
549 topology_st.standalone.start()
550
551 # Prepare memberof so that it will fail during a next update
552 # If memberof plugin can not add 'memberof' to the
553 # member entry, it retries after adding
554 # 'memberOfAutoAddOC' objectclass to the member.
555 # If it fails again the plugin fails with 'object
556 # violation'
557 # To trigger this failure, set 'memberOfAutoAddOC'
558 # to a value that does *not* allow 'memberof' attribute
559 memberof = MemberOfPlugin(topology_st.standalone)
560 memberof.enable()
561 memberof.replace('memberOfAutoAddOC', 'account')
562 memberof.replace('memberofentryscope', DEFAULT_SUFFIX)
563 topology_st.standalone.restart()
564
565 for i in range(50):
566 # Try to add the user to demo_group
567 # It should fail because user entry has not 'nsmemberof' objectclass
568 # As this is a BETXN plugin that fails it should revert the entry cache
569 try:
570 GROUP_DN = "cn=demo_group,ou=groups," + DEFAULT_SUFFIX
571 topology_st.standalone.modify(GROUP_DN,
572 [(ldap.MOD_REPLACE, 'member', ensure_bytes(user.dn))])
573 topology_st.standalone.modify(GROUP_DN,
574 [(ldap.MOD_REPLACE, 'member', ensure_bytes(user.dn))])
575 topology_st.standalone.modify(GROUP_DN,
576 [(ldap.MOD_REPLACE, 'member', ensure_bytes(user.dn))])
577 except ldap.OBJECT_CLASS_VIOLATION:
578 pass
579
580 user.replace('cn', ['new_value'])
581
582 # Check that both a betxn failed and a reverted entry was
583 # detected during an update
584 assert topology_st.standalone.ds_error_log.match('.*WARN - flush_hash - Upon BETXN callback failure, entry cache is flushed during.*')
585 assert topology_st.standalone.ds_error_log.match('.*cache_is_reverted_entry - Entry reverted.*')
586
587 def fin():
588 user.delete()
589 memberof = MemberOfPlugin(topology_st.standalone)
590 memberof.replace('memberOfAutoAddOC', 'nsmemberof')
591
592 request.addfinalizer(fin)
593
594
595 def test_linked_attributes_plugin(topology_st):
596 ''' Test that Linked Attributes Plugin does not allow to add a link entry
597 that does not exist
598
599 :id: 8ec17a8f-d331-4aff-ab80-1afbdf8d4404
600 :setup: Standalone instance
601 :steps:
602 1. Enable Linked Attributes plugin
603 2. Create a config entry for linked attributes plugin
604 3. Create a user with extensibleObject objectClass
605 4. Add a link entry to the user, but the linked entry does not exist
606 5. Cleanup the entry, disable the plugin
607 :expectedresults:
608 1. Success
609 2. Success
610 3. Success
611 4. Raises UNWILLING_TO_PERFORM error
612 5. Success
613 '''
614
615 # Enable Linked Attributes plugin
616 linkedattr = LinkedAttributesPlugin(topology_st.standalone)
617 linkedattr.enable()
618
619 # Add the linked attrs config entry
620 la_configs = LinkedAttributesConfigs(topology_st.standalone)
621 la_configs.create(properties={'cn': 'Manager Link',
622 'linkType': 'seeAlso',
623 'managedType': 'seeAlso'})
624
625 # Add an entry that has a link to an entry that does not exist
626 users = UserAccounts(topology_st.standalone, DEFAULT_SUFFIX)
627 manager = users.create_test_user(uid=999)
628 with pytest.raises(ldap.UNWILLING_TO_PERFORM):
629 manager.add('seeAlso', 'uid=user,dc=example,dc=com')
630
631 # Cleanup
632 manager.delete()
633 linkedattr.disable()
634 linkedattr.delete()
635
636
637 def test_incorrect_attribute_values(topology_st):
638 """Test that betxnplugins consistently reject entries with incompatible attribute values
639
640 This test is designed to verify that when new entry is repeatedly rejected by betxn plugins
641 due to incorrect attribute values, the operation consistently fails on UNWILLING TO PERFORM
642 rather than AlreadyExists caused by the entry not being removed from cache.
643
644 :id: 8ec17a8f-d331-4aff-ab80-1afbdf8d4405
645
646 :setup: Standalone instance with MemberOf, AutoMembership, and RetroChangelog plugins
647
648 :steps: 1. Enable MemberOf plugin with memberofAutoAddOC set to "account"
649 (an objectclass that does not allow memberof attribute)
650 2. Enable AutoMembership plugin
651 3. Enable RetroChangelog plugin
652 4. Create a group for auto-membership
653 5. Configure automember to automatically add users to the group
654 6. Attempt to create a test user (first attempt)
655 7. Attempt to create the same test user again (second attempt)
656 8. Verify both attempts fail with UNWILLING_TO_PERFORM
657 9. Cleanup created objects
658
659 :expectedresults:
660 1. MemberOf plugin should be enabled with incompatible autoAddOC
661 2. AutoMembership plugin should be enabled
662 3. RetroChangelog plugin should be enabled
663 4. Group creation should succeed
664 5. Automember configuration should succeed
665 6. First user creation should fail with UNWILLING_TO_PERFORM
666 7. Second user creation should also fail with UNWILLING_TO_PERFORM
667 (not ALREADY_EXISTS)
668 8. Error codes should be consistent across attempts
669 9. Cleanup should succeed
670 """
671
672 # Enable MemberOf plugin, set memberofAutoAddOC to account (OC that does not allow memberof)
673 memberof = MemberOfPlugin(topology_st.standalone)
674 memberof.set_autoaddoc('account')
675 memberof.enable()
676 topology_st.standalone.restart()
677
678 # Enable AutoMembership plugin
679 automemberplugin = AutoMembershipPlugin(topology_st.standalone)
680 automemberplugin.enable()
681 topology_st.standalone.restart()
682
683 # Enable RetroChangelog plugin
684 rcl = RetroChangelogPlugin(topology_st.standalone)
685 rcl.disable()
686 rcl.enable()
687 topology_st.standalone.restart()
688
689 user_name = 'test_user_1000'
690 group_name = 'group'
691
692 # Create group
693 groups = Groups(topology_st.standalone, DEFAULT_SUFFIX)
694 group = groups.create(properties={'cn': group_name})
695
696 # Create automember config entry
697 automember_prop = {
698 'cn': 'group cfg',
699 'autoMemberScope': DEFAULT_SUFFIX,
700 'autoMemberFilter': f'uid={user_name}',
701 'autoMemberDefaultGroup': f'cn={group_name},ou=groups,dc=example,dc=com',
702 'autoMemberGroupingAttr': 'member:dn',
703 }
704
705 automembers = AutoMembershipDefinitions(topology_st.standalone,
706 "cn=Auto Membership Plugin,cn=plugins,cn=config")
707 automember = automembers.create(properties=automember_prop)
708
709 users = nsUserAccounts(topology_st.standalone, DEFAULT_SUFFIX)
710
711 # first attempt to add the user
712 # should fail with UNWILLING_TO_PERFORM due to incompatible object class
713 with pytest.raises(ldap.UNWILLING_TO_PERFORM):
714 user = users.create_test_user()
715
716 # second attempt to add the user
717 # should also fail with UNWILLING_TO_PERFORM, not with AlreadyExists
718 with pytest.raises(ldap.UNWILLING_TO_PERFORM):
719 user = users.create_test_user()
720
721 # Cleanup
722 rcl.disable()
723 automemberplugin.disable()
724 memberof.disable()
725 group.delete()
726
727
728 if __name__ == '__main__':
729 # Run isolated
730 # -s for DEBUG mode
731 CURRENT_FILE = os.path.realpath(__file__)
732 pytest.main("-s %s" % CURRENT_FILE)