Debian Codegraph @

dirsrvtests/tests/suites/plugins/acceptance_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 '''
10 Created on Dec 09, 2014
11
12 @author: mreynolds
13 '''
14 import logging
15 import threading
16 from ldap.syncrepl import SyncreplConsumer
17 from ldap.ldapobject import ReconnectLDAPObject
18 import subprocess
19 import pytest
20 from lib389.utils import *
21 from lib389.plugins import *
22 from lib389._constants import *
23 from lib389.dseldif import DSEldif
24 from lib389.idm.user import UserAccounts
25 from lib389.idm.group import Groups
26 from lib389.idm.organizationalunit import OrganizationalUnits
27 from lib389.idm.domain import Domain
28 from test389.topologies import create_topology, topology_i2 as topo
29
30 pytestmark = pytest.mark.tier1
31
32 log = logging.getLogger(__name__)
33
34 USER_DN = 'uid=test_user_1001,ou=people,dc=example,dc=com'
35 USER_PW = 'password'
36 GROUP_DN = 'cn=group,' + DEFAULT_SUFFIX
37 CONFIG_AREA = 'nsslapd-pluginConfigArea'
38
39 if ds_is_older('1.3.7'):
40 MEMBER_ATTR = 'member'
41 else:
42 MEMBER_ATTR = 'memberOf'
43
44 '''
45 Functional tests for each plugin
46
47 Test:
48 plugin restarts (test when on and off)
49 plugin config validation
50 plugin dependencies
51 plugin functionality (including plugin tasks)
52 '''
53
54
55 def check_dependency(inst, plugin, online=True):
56 """Set the "account usability" plugin to depend on this plugin.
57 This plugin is generic, always enabled, and perfect for our testing
58 """
59
60 acct_usability = AccountUsabilityPlugin(inst)
61 acct_usability.replace('nsslapd-plugin-depends-on-named', plugin.rdn)
62
63 if online:
64 with pytest.raises(ldap.UNWILLING_TO_PERFORM):
65 plugin.disable()
66 # Now undo the change
67 acct_usability.remove('nsslapd-plugin-depends-on-named', plugin.rdn)
68 else:
69 plugin.disable()
70 with pytest.raises((subprocess.CalledProcessError, ValueError)):
71 inst.restart()
72 dse_ldif = DSEldif(inst)
73 dse_ldif.delete(acct_usability.dn, 'nsslapd-plugin-depends-on-named')
74 dse_ldif.replace(plugin.dn, 'nsslapd-pluginEnabled', 'on')
75 inst.start()
76
77
78 def test_acctpolicy(topo, args=None):
79 """Test Account policy basic functionality
80
81 :id: 9b87493b-0493-46f9-8364-6099d0e5d829
82 :setup: Standalone Instance
83 :steps:
84 1. Enable the plugin
85 2. Restart the instance
86 3. Add a config entry for 'lastLoginTime'
87 4. Add a user
88 5. Bind as the user
89 6. Check testLastLoginTime was added to the user
90 7. Replace 'stateattrname': 'testLastLoginTime'
91 8. Bind as the user
92 9. Check testLastLoginTime was added to the user
93 10. Check nsslapd-plugin-depends-on-named for the plugin
94 11. Clean up
95 :expectedresults:
96 1. Success
97 2. Success
98 3. Success
99 4. Success
100 5. Success
101 6. Success
102 7. Success
103 8. Success
104 9. Success
105 10. Success
106 11. Success
107 """
108
109 inst = topo[0]
110
111 # stop the plugin, and start it
112 plugin = AccountPolicyPlugin(inst)
113 plugin.disable()
114 plugin.enable()
115
116 if args == "restart":
117 return True
118
119 # If args is None then we run the test suite as pytest standalone and it's not dynamic
120 if args is None:
121 inst.restart()
122
123 log.info('Testing {}'.format(PLUGIN_ACCT_POLICY))
124
125 ############################################################################
126 # Configure plugin
127 ############################################################################
128 # Add the config entry
129 ap_configs = AccountPolicyConfigs(inst)
130 try:
131 ap_config = ap_configs.create(properties={'cn': 'config',
132 'alwaysrecordlogin': 'yes',
133 'stateattrname': 'lastLoginTime'})
134 except ldap.ALREADY_EXISTS:
135 ap_config = ap_configs.get('config')
136 ap_config.replace_many(('alwaysrecordlogin', 'yes'),
137 ('stateattrname', 'lastLoginTime'))
138
139 ############################################################################
140 # Test plugin
141 ############################################################################
142 # Add an entry
143 users = UserAccounts(inst, DEFAULT_SUFFIX)
144 user = users.create_test_user(1000, 2000)
145 user.add('objectclass', 'extensibleObject')
146 user.replace('userPassword', USER_PW)
147
148 # Bind as user
149 user.bind(USER_PW)
150 time.sleep(1)
151
152 # Check lastLoginTime of USER1
153 entries = inst.search_s(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, 'lastLoginTime=*')
154 assert entries
155
156 ############################################################################
157 # Change config - change the stateAttrName to a new attribute
158 ############################################################################
159 test_attribute = "( 2.16.840.1.113719.1.1.4.1.35999 \
160 NAME 'testLastLoginTime' DESC 'Test Last login time' \
161 SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 SINGLE-VALUE USAGE \
162 directoryOperation X-ORIGIN 'dirsrvtests' )"
163 Schema(inst).add('attributetypes', test_attribute)
164 ap_config.replace('stateattrname', 'testLastLoginTime')
165 time.sleep(1)
166
167 ############################################################################
168 # Test plugin
169 ############################################################################
170 # login as user
171 user.bind(USER_PW)
172 time.sleep(1)
173
174 # Check testLastLoginTime was added to USER1
175 entries = inst.search_s(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, '(testLastLoginTime=*)')
176 assert entries
177
178 ############################################################################
179 # Test plugin dependency
180 ############################################################################
181 check_dependency(inst, plugin, online=isinstance(args, str))
182
183 ############################################################################
184 # Cleanup
185 ############################################################################
186 user.delete()
187
188 ############################################################################
189 # Test passed
190 ############################################################################
191 log.info('test_acctpolicy: PASS\n')
192
193 return
194
195
196 def test_attruniq(topo, args=None):
197 """Test Attribute uniqueness basic functionality
198
199 :id: 9b87493b-0493-46f9-8364-6099d0e5d801
200 :setup: Standalone Instance
201 :steps:
202 1. Enable the plugin
203 2. Restart the instance
204 3. Add a user: with 'mail' and 'mailAlternateAddress' attributes
205 4. Replace 'uniqueness-attribute-name': 'cn'
206 5. Try to add a user with the same 'cn'
207 6. Replace 'uniqueness-attribute-name': 'mail'
208 7. Try to add a user with the same 'mail'
209 8. Add 'uniqueness-attribute-name': 'mailAlternateAddress'
210 9. Try to add a user with the same 'mailAlternateAddress'
211 10. Check nsslapd-plugin-depends-on-named for the plugin
212 11. Clean up
213 :expectedresults:
214 1. Success
215 2. Success
216 3. Success
217 4. Success
218 5. Should fail
219 6. Success
220 7. Should fail
221 8. Success
222 9. Should fail
223 10. Success
224 11. Success
225 """
226
227 inst = topo[0]
228
229 # stop the plugin, and start it
230 plugin = AttributeUniquenessPlugin(inst, dn="cn=attribute uniqueness,cn=plugins,cn=config")
231 plugin.disable()
232 plugin.enable()
233
234 if args == "restart":
235 return
236
237 # If args is None then we run the test suite as pytest standalone and it's not dynamic
238 if args is None:
239 inst.restart()
240
241 log.info('Testing {}'.format(PLUGIN_ATTR_UNIQUENESS))
242 user1_dict = {'objectclass': 'extensibleObject',
243 'uid': 'testuser1',
244 'cn': 'testuser1',
245 'sn': 'user1',
246 'uidNumber': '1001',
247 'gidNumber': '2001',
248 'mail': '[email protected]',
249 'mailAlternateAddress': '[email protected]',
250 'homeDirectory': '/home/testuser1',
251 'userpassword': 'password'}
252 user2_dict = {'objectclass': 'extensibleObject',
253 'uid': 'testuser2',
254 'cn': 'testuser2',
255 'sn': 'user2',
256 'uidNumber': '1000',
257 'gidNumber': '2000',
258 'homeDirectory': '/home/testuser2',
259 'userpassword': 'password'}
260
261 ############################################################################
262 # Configure plugin
263 ############################################################################
264 plugin.replace('uniqueness-attribute-name', 'cn')
265 if args is None:
266 inst.restart()
267
268 ############################################################################
269 # Test plugin
270 ############################################################################
271 # Add an entry
272 users = UserAccounts(inst, DEFAULT_SUFFIX)
273 user1 = users.create(properties=user1_dict)
274
275 # Add an entry with a duplicate "cn"
276 with pytest.raises(ldap.CONSTRAINT_VIOLATION):
277 user2_dict['cn'] = 'testuser1'
278 users.create(properties=user2_dict)
279
280 ############################################################################
281 # Change config to use "mail" instead of "uid"
282 ############################################################################
283
284 plugin.replace('uniqueness-attribute-name', 'mail')
285
286 ############################################################################
287 # Test plugin - Add an entry, that has a duplicate "mail" value
288 ############################################################################
289 with pytest.raises(ldap.CONSTRAINT_VIOLATION):
290 user2_dict['mail'] = '[email protected]'
291 users.create(properties=user2_dict)
292
293 ############################################################################
294 # Reconfigure plugin for mail and mailAlternateAddress
295 ############################################################################
296 plugin.add('uniqueness-attribute-name', 'mailAlternateAddress')
297
298 ############################################################################
299 # Test plugin - Add an entry, that has a duplicate "mail" value
300 ############################################################################
301 with pytest.raises(ldap.CONSTRAINT_VIOLATION):
302 user2_dict['mail'] = '[email protected]'
303 users.create(properties=user2_dict)
304
305 ############################################################################
306 # Test plugin - Add an entry, that has a duplicate "mailAlternateAddress" value
307 ############################################################################
308 with pytest.raises(ldap.CONSTRAINT_VIOLATION):
309 user2_dict['mailAlternateAddress'] = '[email protected]'
310 users.create(properties=user2_dict)
311
312 ############################################################################
313 # Test plugin - Add an entry, that has a duplicate "mail" value conflicting mailAlternateAddress
314 ############################################################################
315 with pytest.raises(ldap.CONSTRAINT_VIOLATION):
316 user2_dict['mail'] = '[email protected]'
317 users.create(properties=user2_dict)
318
319 ############################################################################
320 # Test plugin - Add an entry, that has a duplicate "mailAlternateAddress" conflicting mail
321 ############################################################################
322 with pytest.raises(ldap.CONSTRAINT_VIOLATION):
323 user2_dict['mailAlternateAddress'] = '[email protected]'
324 users.create(properties=user2_dict)
325
326 ############################################################################
327 # Test plugin dependency
328 ############################################################################
329 check_dependency(inst, plugin, online=isinstance(args, str))
330
331 ############################################################################
332 # Cleanup
333 ############################################################################
334 user1.delete()
335
336 ############################################################################
337 # Test passed
338 ############################################################################
339 log.info('test_attruniq: PASS\n')
340 return
341
342
343 def test_automember(topo, args=None):
344 """Test Auto Membership basic functionality
345
346 :id: 9b87493b-0493-46f9-8364-6099d0e5d802
347 :setup: Standalone Instance
348 :steps:
349 1. Enable the plugin
350 2. Restart the instance
351 3. Add a group
352 4. Add two Organisation Units entries
353 5. Add a config entry for the group and one branch
354 6. Add a user that should get added to the group
355 7. Check the entry is in group
356 8. Set groupattr to 'uniquemember:dn' and scope to branch2
357 9. Add a user that should get added to the group
358 10. Check the group
359 11. Disable plugin and restart
360 12. Add an entry that should be picked up by automember
361 13. Verify that the entry is not picked up by automember (yet)
362 14. Check the group - uniquemember should not exist
363 15. Enable plugin and restart
364 16. Verify the fixup task worked
365 17. Check nsslapd-plugin-depends-on-named for the plugin
366 18. Clean up
367 :expectedresults:
368 1. Success
369 2. Success
370 3. Success
371 4. Success
372 5. Success
373 6. Success
374 7. Success
375 8. Success
376 9. Success
377 10. Success
378 11. Success
379 12. Success
380 13. Success
381 14. Success
382 15. Success
383 16. Success
384 17. Success
385 18. Success
386 """
387
388 inst = topo[0]
389
390 # stop the plugin, and start it
391 plugin = AutoMembershipPlugin(inst)
392 plugin.disable()
393 plugin.enable()
394
395 if args == "restart":
396 return
397
398 # If args is None then we run the test suite as pytest standalone and it's not dynamic
399 if args is None:
400 inst.restart()
401
402 log.info('Testing ' + PLUGIN_AUTOMEMBER + '...')
403
404 ############################################################################
405 # Configure plugin
406 ############################################################################
407
408 # Add the automember group
409 groups = Groups(inst, DEFAULT_SUFFIX)
410 group = groups.create(properties={'cn': 'group'})
411
412 ous = OrganizationalUnits(inst, DEFAULT_SUFFIX)
413 branch1 = ous.create(properties={'ou': 'branch1'})
414 branch2 = ous.create(properties={'ou': 'branch2'})
415
416 # Add the automember config entry
417 am_configs = AutoMembershipDefinitions(inst)
418 am_config = am_configs.create(properties={'cn': 'config',
419 'autoMemberScope': branch1.dn,
420 'autoMemberFilter': 'objectclass=top',
421 'autoMemberDefaultGroup': group.dn,
422 'autoMemberGroupingAttr': '{}:dn'.format(MEMBER_ATTR)})
423
424 ############################################################################
425 # Test the plugin
426 ############################################################################
427
428 users = UserAccounts(inst, DEFAULT_SUFFIX, rdn='ou={}'.format(branch1.rdn))
429 # Add a user that should get added to the group
430 user1 = users.create_test_user(uid=1001)
431
432 # Check the group
433 group_members = group.get_attr_vals_utf8(MEMBER_ATTR)
434 assert user1.dn in group_members
435
436 ############################################################################
437 # Change config
438 ############################################################################
439 group.add('objectclass', 'groupOfUniqueNames')
440 am_config.set_groupattr('uniquemember:dn')
441 am_config.set_scope(branch2.dn)
442
443 ############################################################################
444 # Test plugin
445 ############################################################################
446 # Add a user that should get added to the group
447 users = UserAccounts(inst, DEFAULT_SUFFIX, rdn='ou={}'.format(branch2.rdn))
448 user2 = users.create_test_user(uid=1002)
449
450 # Check the group
451 group_members = group.get_attr_vals_utf8('uniquemember')
452 assert user2.dn in group_members
453
454 ############################################################################
455 # Test Task
456 ############################################################################
457
458 # Disable plugin
459 plugin.disable()
460
461 # If args is None then we run the test suite as pytest standalone and it's not dynamic
462 if args is None:
463 inst.restart()
464
465 # Add an entry that should be picked up by automember - verify it is not(yet)
466 user3 = users.create_test_user(uid=1003)
467
468 # Check the group - uniquemember should not exist
469 group_members = group.get_attr_vals_utf8('uniquemember')
470 assert user3.dn not in group_members
471
472 # Enable plugin
473 plugin.enable()
474
475 # If args is None then we run the test suite as pytest standalone and it's not dynamic
476 if args is None:
477 inst.restart()
478 task = plugin.fixup(branch2.dn, _filter='objectclass=top')
479 task.wait()
480
481 # Verify the fixup task worked
482 group_members = group.get_attr_vals_utf8('uniquemember')
483 assert user3.dn in group_members
484
485 ############################################################################
486 # Test plugin dependency
487 ############################################################################
488 check_dependency(inst, plugin, online=isinstance(args, str))
489
490 ############################################################################
491 # Cleanup
492 ############################################################################
493 user1.delete()
494 user2.delete()
495 user3.delete()
496 branch1.delete()
497 branch2.delete()
498 group.delete()
499 am_config.delete()
500
501 ############################################################################
502 # Test passed
503 ############################################################################
504 log.info('test_automember: PASS\n')
505 return
506
507
508 def test_dna(topo, args=None):
509 """Test DNA basic functionality
510
511 :id: 9b87493b-0493-46f9-8364-6099d0e5d803
512 :setup: Standalone Instance
513 :steps:
514 1. Enable the plugin
515 2. Restart the instance
516 3. Configure plugin for uidNumber
517 4. Add a user
518 5. See if the entry now has the new uidNumber assignment - uidNumber=1
519 6. Test the magic regen value
520 7. See if the entry now has the new uidNumber assignment - uidNumber=2
521 8. Set 'dnaMagicRegen': '-2'
522 9. Test the magic regen value
523 10. See if the entry now has the new uidNumber assignment - uidNumber=3
524 11. Check nsslapd-plugin-depends-on-named for the plugin
525 12. Clean up
526 :expectedresults:
527 1. Success
528 2. Success
529 3. Success
530 4. Success
531 5. Success
532 6. Success
533 7. Success
534 8. Success
535 9. Success
536 10. Success
537 11. Success
538 12. Success
539 """
540
541 inst = topo[0]
542
543 # stop the plugin, and start it
544 plugin = DNAPlugin(inst)
545 plugin.disable()
546 plugin.enable()
547
548 if args == "restart":
549 return
550
551 # If args is None then we run the test suite as pytest standalone and it's not dynamic
552 if args is None:
553 inst.restart()
554
555 log.info('Testing ' + PLUGIN_DNA + '...')
556
557 ############################################################################
558 # Configure plugin
559 ############################################################################
560 dna_configs = DNAPluginConfigs(inst, plugin.dn)
561 try:
562 dna_config = dna_configs.create(properties={'cn': 'config',
563 'dnatype': 'uidNumber',
564 'dnafilter': '(objectclass=top)',
565 'dnascope': DEFAULT_SUFFIX,
566 'dnaMagicRegen': '-1',
567 'dnaMaxValue': '50000',
568 'dnaNextValue': '1'})
569 except ldap.ALREADY_EXISTS:
570 dna_config = dna_configs.get('config')
571 dna_config.replace_many(('dnaNextValue', '1'), ('dnaMagicRegen', '-1'))
572
573 ############################################################################
574 # Test plugin
575 ############################################################################
576 users = UserAccounts(inst, DEFAULT_SUFFIX)
577 user1 = users.create_test_user(uid=1)
578
579 # See if the entry now has the new uidNumber assignment - uidNumber=1
580 entries = inst.search_s(user1.dn, ldap.SCOPE_BASE, '(uidNumber=1)')
581 assert entries
582
583 # Test the magic regen value
584 user1.replace('uidNumber', '-1')
585
586 # See if the entry now has the new uidNumber assignment - uidNumber=2
587 entries = inst.search_s(user1.dn, ldap.SCOPE_BASE, '(uidNumber=2)')
588 assert entries
589
590 ################################################################################
591 # Change the config
592 ################################################################################
593 dna_config.replace('dnaMagicRegen', '-2')
594
595 ################################################################################
596 # Test plugin
597 ################################################################################
598
599 # Test the magic regen value
600 user1.replace('uidNumber', '-2')
601
602 # See if the entry now has the new uidNumber assignment - uidNumber=3
603 entries = inst.search_s(user1.dn, ldap.SCOPE_BASE, '(uidNumber=3)')
604 assert entries
605
606 ############################################################################
607 # Test plugin dependency
608 ############################################################################
609 check_dependency(inst, plugin, online=isinstance(args, str))
610
611 ############################################################################
612 # Cleanup
613 ############################################################################
614 user1.delete()
615 dna_config.delete()
616 plugin.disable()
617
618 # If args is None then we run the test suite as pytest standalone and it's not dynamic
619 if args is None:
620 inst.restart()
621
622 ############################################################################
623 # Test passed
624 ############################################################################
625 log.info('test_dna: PASS\n')
626 return
627
628
629 def test_linkedattrs(topo, args=None):
630 """Test Linked Attributes basic functionality
631
632 :id: 9b87493b-0493-46f9-8364-6099d0e5d804
633 :setup: Standalone Instance
634 :steps:
635 1. Enable the plugin
636 2. Restart the instance
637 3. Add a config entry for directReport
638 4. Add test entries
639 5. Add the linked attrs config entry
640 6. User1 - Set "directReport" to user2
641 7. See if manager was added to the other entry
642 8. User1 - Remove "directReport"
643 9. See if manager was removed
644 10. Change the config - using linkType "indirectReport" now
645 11. Make sure the old linkType(directManager) is not working
646 12. See if manager was added to the other entry, better not be...
647 13. Now, set the new linkType "indirectReport", which should add "manager" to the other entry
648 14. See if manager was added to the other entry, better not be
649 15. Remove "indirectReport" should remove "manager" to the other entry
650 16. See if manager was removed
651 17. Disable plugin and make some updates that would of triggered the plugin
652 18. The entry should not have a manager attribute
653 19. Enable the plugin and rerun the task entry
654 20. Add the task again
655 21. Check if user2 now has a manager attribute now
656 22. Check nsslapd-plugin-depends-on-named for the plugin
657 23. Clean up
658 :expectedresults:
659 1. Success
660 2. Success
661 3. Success
662 4. Success
663 5. Success
664 6. Success
665 7. Success
666 8. Success
667 9. Success
668 10. Success
669 11. Success
670 12. Success
671 13. Success
672 14. Success
673 15. Success
674 16. Success
675 17. Success
676 18. Success
677 19. Success
678 20. Success
679 21. Success
680 22. Success
681 23. Success
682 """
683
684 inst = topo[0]
685
686 # stop the plugin, and start it
687 plugin = LinkedAttributesPlugin(inst)
688 plugin.disable()
689 plugin.enable()
690
691 if args == "restart":
692 return
693
694 # If args is None then we run the test suite as pytest standalone and it's not dynamic
695 if args is None:
696 inst.restart()
697
698 log.info('Testing ' + PLUGIN_LINKED_ATTRS + '...')
699
700 ############################################################################
701 # Configure plugin
702 ############################################################################
703
704 # Add test entries
705 users = UserAccounts(inst, DEFAULT_SUFFIX)
706 user1 = users.create_test_user(uid=1001)
707 user1.add('objectclass', 'extensibleObject')
708 user2 = users.create_test_user(uid=1002)
709 user2.add('objectclass', 'extensibleObject')
710
711 # Add the linked attrs config entry
712 la_configs = LinkedAttributesConfigs(inst)
713 la_config = la_configs.create(properties={'cn': 'config',
714 'linkType': 'directReport',
715 'managedType': 'manager'})
716
717 ############################################################################
718 # Test plugin
719 ############################################################################
720 # Set "directReport" should add "manager" to the other entry
721 user1.replace('directReport', user2.dn)
722
723 # See if manager was added to the other entry
724 entries = inst.search_s(user2.dn, ldap.SCOPE_BASE, '(manager=*)')
725 assert entries
726
727 # Remove "directReport" should remove "manager" to the other entry
728 user1.remove_all('directReport')
729
730 # See if manager was removed
731 entries = inst.search_s(user2.dn, ldap.SCOPE_BASE, '(manager=*)')
732 assert not entries
733
734 ############################################################################
735 # Change the config - using linkType "indirectReport" now
736 ############################################################################
737 la_config.replace('linkType', 'indirectReport')
738
739 ############################################################################
740 # Test plugin
741 ############################################################################
742 # Make sure the old linkType(directManager) is not working
743 user1.replace('directReport', user2.dn)
744
745 # See if manager was added to the other entry, better not be...
746 entries = inst.search_s(user2.dn, ldap.SCOPE_BASE, '(manager=*)')
747 assert not entries
748
749 # Now, set the new linkType "indirectReport", which should add "manager" to the other entry
750 user1.replace('indirectReport', user2.dn)
751
752 # See if manager was added to the other entry, better not be
753 entries = inst.search_s(user2.dn, ldap.SCOPE_BASE, '(manager=*)')
754 assert entries
755
756 # Remove "indirectReport" should remove "manager" to the other entry
757 user1.remove_all('indirectReport')
758
759 # See if manager was removed
760 entries = inst.search_s(user2.dn, ldap.SCOPE_BASE, '(manager=*)')
761 assert not entries
762
763 ############################################################################
764 # Test Fixup Task
765 ############################################################################
766 # Disable plugin and make some updates that would of triggered the plugin
767 plugin.disable()
768
769 # If args is None then we run the test suite as pytest standalone and it's not dynamic
770 if args is None:
771 inst.restart()
772
773 user1.replace('indirectReport', user2.dn)
774
775 # The entry should not have a manager attribute
776 entries = inst.search_s(user2.dn, ldap.SCOPE_BASE, '(manager=*)')
777 assert not entries
778
779 # Enable the plugin and rerun the task entry
780 plugin.enable()
781
782 # If args is None then we run the test suite as pytest standalone and it's not dynamic
783 if args is None:
784 inst.restart()
785
786 # Add the task again
787 task = plugin.fixup(la_config.dn)
788 task.wait()
789
790 # Check if user2 now has a manager attribute now
791 entries = inst.search_s(user2.dn, ldap.SCOPE_BASE, '(manager=*)')
792 assert entries
793
794 ############################################################################
795 # Test plugin dependency
796 ############################################################################
797 check_dependency(inst, plugin, online=isinstance(args, str))
798
799 ############################################################################
800 # Cleanup
801 ############################################################################
802 user1.delete()
803 user2.delete()
804 la_config.delete()
805
806 ############################################################################
807 # Test passed
808 ############################################################################
809 log.info('test_linkedattrs: PASS\n')
810 return
811
812
813 def test_memberof(topo, args=None):
814 """Test MemberOf basic functionality
815
816 :id: 9b87493b-0493-46f9-8364-6099d0e5d805
817 :setup: Standalone Instance
818 :steps:
819 1. Enable the plugin
820 2. Restart the instance
821 3. Replace groupattr with 'member'
822 4. Add our test entries
823 5. Check if the user now has a "memberOf" attribute
824 6. Remove "member" should remove "memberOf" from the entry
825 7. Check that "memberOf" was removed
826 8. Replace 'memberofgroupattr': 'uniquemember'
827 9. Replace 'uniquemember': user1
828 10. Check if the user now has a "memberOf" attribute
829 11. Remove "uniquemember" should remove "memberOf" from the entry
830 12. Check that "memberOf" was removed
831 13. The shared config entry uses "member" - the above test uses "uniquemember"
832 14. Delete the test entries then read them to start with a clean slate
833 15. Check if the user now has a "memberOf" attribute
834 16. Check that "memberOf" was removed
835 17. Replace 'memberofgroupattr': 'uniquemember'
836 18. Check if the user now has a "memberOf" attribute
837 19. Remove "uniquemember" should remove "memberOf" from the entry
838 20. Check that "memberOf" was removed
839 21. Replace 'memberofgroupattr': 'member'
840 22. Remove shared config from plugin
841 23. Check if the user now has a "memberOf" attribute
842 24. Remove "uniquemember" should remove "memberOf" from the entry
843 25. Check that "memberOf" was removed
844 26. First change the plugin to use uniquemember
845 27. Add uniquemember, should not update user1
846 28. Check for "memberOf"
847 29. Enable memberof plugin
848 30. Run the task and validate that it worked
849 31. Check for "memberOf"
850 32. Check nsslapd-plugin-depends-on-named for the plugin
851 33. Clean up
852 :expectedresults:
853 1. Success
854 2. Success
855 3. Success
856 4. Success
857 5. Success
858 6. Success
859 7. Success
860 8. Success
861 9. Success
862 10. Success
863 11. Success
864 12. Success
865 13. Success
866 14. Success
867 15. Success
868 16. Success
869 17. Success
870 18. Success
871 19. Success
872 20. Success
873 21. Success
874 22. Success
875 23. Success
876 24. Success
877 25. Success
878 26. Success
879 27. Success
880 28. Success
881 29. Success
882 30. Success
883 31. Success
884 32. Success
885 33. Success
886 """
887
888 inst = topo[0]
889
890 # stop the plugin, and start it
891 plugin = MemberOfPlugin(inst)
892 if (plugin.get_memberofdeferredupdate() and plugin.get_memberofdeferredupdate().lower() == "on"):
893 delay = 5
894 else:
895 delay = 0
896 plugin.disable()
897 plugin.enable()
898
899 if args == "restart":
900 return
901
902 # If args is None then we run the test suite as pytest standalone and it's not dynamic
903 if args is None:
904 inst.restart()
905
906 log.info('Testing ' + PLUGIN_MEMBER_OF + '...')
907
908 ############################################################################
909 # Configure plugin
910 ############################################################################
911 plugin.replace_groupattr('member')
912
913 ############################################################################
914 # Test plugin
915 ############################################################################
916 # Add our test entries
917 users = UserAccounts(inst, DEFAULT_SUFFIX)
918 user1 = users.create_test_user(uid=1001)
919
920 groups = Groups(inst, DEFAULT_SUFFIX)
921 group = groups.create(properties={'cn': 'group',
922 'member': user1.dn})
923 group.add('objectclass', 'groupOfUniqueNames')
924
925 memberof_config = MemberOfSharedConfig(inst, 'cn=memberOf config,{}'.format(DEFAULT_SUFFIX))
926 memberof_config.create(properties={'cn': 'memberOf config',
927 'memberOfGroupAttr': 'member',
928 'memberOfAttr': MEMBER_ATTR})
929
930 time.sleep(delay)
931 # Check if the user now has a "memberOf" attribute
932 entries = inst.search_s(user1.dn, ldap.SCOPE_BASE, '({}=*)'.format(MEMBER_ATTR))
933 assert entries
934
935 # Remove "member" should remove "memberOf" from the entry
936 group.remove_all('member')
937
938 time.sleep(delay)
939 # Check that "memberOf" was removed
940 entries = inst.search_s(user1.dn, ldap.SCOPE_BASE, '({}=*)'.format(MEMBER_ATTR))
941 assert not entries
942
943 ############################################################################
944 # Change the config
945 ############################################################################
946 plugin.replace('memberofgroupattr', 'uniquemember')
947
948 ############################################################################
949 # Test plugin
950 ############################################################################
951 group.replace('uniquemember', user1.dn)
952
953 time.sleep(delay)
954 # Check if the user now has a "memberOf" attribute
955 entries = inst.search_s(user1.dn, ldap.SCOPE_BASE, '({}=*)'.format(MEMBER_ATTR))
956 assert entries
957
958 # Remove "uniquemember" should remove "memberOf" from the entry
959 group.remove_all('uniquemember')
960
961 time.sleep(delay)
962 # Check that "memberOf" was removed
963 entries = inst.search_s(user1.dn, ldap.SCOPE_BASE, '({}=*)'.format(MEMBER_ATTR))
964 assert not entries
965
966 ############################################################################
967 # Set the shared config entry and test the plugin
968 ############################################################################
969 # The shared config entry uses "member" - the above test uses "uniquemember"
970 plugin.set_configarea(memberof_config.dn)
971 if args is None:
972 inst.restart()
973
974 # Delete the test entries then readd them to start with a clean slate
975 user1.delete()
976 group.delete()
977
978 user1 = users.create_test_user(uid=1001)
979 group = groups.create(properties={'cn': 'group',
980 'member': user1.dn})
981 group.add('objectclass', 'groupOfUniqueNames')
982
983 time.sleep(delay)
984 # Test the shared config
985 # Check if the user now has a "memberOf" attribute
986 entries = inst.search_s(user1.dn, ldap.SCOPE_BASE, '({}=*)'.format(MEMBER_ATTR))
987 assert entries
988
989 group.remove_all('member')
990
991 time.sleep(delay)
992 # Check that "memberOf" was removed
993 entries = inst.search_s(user1.dn, ldap.SCOPE_BASE, '({}=*)'.format(MEMBER_ATTR))
994 assert not entries
995
996 ############################################################################
997 # Change the shared config entry to use 'uniquemember' and test the plugin
998 ############################################################################
999 memberof_config.replace('memberofgroupattr', 'uniquemember')
1000
1001 group.replace('uniquemember', user1.dn)
1002
1003 time.sleep(delay)
1004 # Check if the user now has a "memberOf" attribute
1005 entries = inst.search_s(user1.dn, ldap.SCOPE_BASE, '({}=*)'.format(MEMBER_ATTR))
1006 assert entries
1007
1008 # Remove "uniquemember" should remove "memberOf" from the entry
1009 group.remove_all('uniquemember')
1010
1011 time.sleep(delay)
1012 # Check that "memberOf" was removed
1013 entries = inst.search_s(user1.dn, ldap.SCOPE_BASE, '({}=*)'.format(MEMBER_ATTR))
1014 assert not entries
1015
1016 ############################################################################
1017 # Remove shared config from plugin, and retest
1018 ############################################################################
1019 # First change the plugin to use member before we move the shared config that uses uniquemember
1020 plugin.replace('memberofgroupattr', 'member')
1021
1022 # Remove shared config from plugin
1023 plugin.remove_configarea()
1024 inst.restart()
1025
1026 group.replace('member', user1.dn)
1027
1028 time.sleep(delay)
1029 # Check if the user now has a "memberOf" attribute
1030 entries = inst.search_s(user1.dn, ldap.SCOPE_BASE, '({}=*)'.format(MEMBER_ATTR))
1031 assert entries
1032
1033 # Remove "uniquemember" should remove "memberOf" from the entry
1034 group.remove_all('member')
1035
1036 time.sleep(delay)
1037 # Check that "memberOf" was removed
1038 entries = inst.search_s(user1.dn, ldap.SCOPE_BASE, '({}=*)'.format(MEMBER_ATTR))
1039 assert not entries
1040
1041 ############################################################################
1042 # Test Fixup Task
1043 ############################################################################
1044 plugin.disable()
1045
1046 # If args is None then we run the test suite as pytest standalone and it's not dynamic
1047 if args is None:
1048 inst.restart()
1049
1050 # First change the plugin to use uniquemember
1051 plugin.replace('memberofgroupattr', 'uniquemember')
1052
1053 # Add uniquemember, should not update USER1
1054 group.replace('uniquemember', user1.dn)
1055
1056 time.sleep(delay)
1057 # Check for "memberOf"
1058 entries = inst.search_s(user1.dn, ldap.SCOPE_BASE, '({}=*)'.format(MEMBER_ATTR))
1059 assert not entries
1060
1061 # Enable memberof plugin
1062 plugin.enable()
1063
1064 # If args is None then we run the test suite as pytest standalone and it's not dynamic
1065 if args is None:
1066 inst.restart()
1067
1068 #############################################################
1069 # Test memberOf fixup arg validation: Test the DN and filter
1070 #############################################################
1071 for basedn, filter in (('{}bad'.format(DEFAULT_SUFFIX), 'objectclass=top'),
1072 ("bad", 'objectclass=top'),
1073 (DEFAULT_SUFFIX, '(objectclass=top')):
1074 task = plugin.fixup(basedn, filter)
1075 task.wait()
1076 exitcode = task.get_exit_code()
1077 assert exitcode != "0", 'test_memberof: Task with invalid DN still reported success'
1078
1079 ####################################################
1080 # Test fixup works
1081 ####################################################
1082 # Run the task and validate that it worked
1083 task = plugin.fixup(DEFAULT_SUFFIX, 'objectclass=top')
1084 task.wait()
1085
1086 # Check for "memberOf"
1087 entries = inst.search_s(user1.dn, ldap.SCOPE_BASE, '({}=*)'.format(MEMBER_ATTR))
1088 assert entries
1089
1090 ############################################################################
1091 # Test plugin dependency
1092 ############################################################################
1093 check_dependency(inst, plugin, online=isinstance(args, str))
1094
1095 ############################################################################
1096 # Cleanup
1097 ############################################################################
1098 user1.delete()
1099 group.delete()
1100 memberof_config.delete()
1101
1102 ############################################################################
1103 # Test passed
1104 ############################################################################
1105 log.info('test_memberof: PASS\n')
1106 return
1107
1108
1109 def test_mep(topo, args=None):
1110 """Test Managed Entries basic functionality
1111
1112 :id: 9b87493b-0493-46f9-8364-6099d0e5d806
1113 :setup: Standalone Instance
1114 :steps:
1115 1. Enable the plugin
1116 2. Restart the instance
1117 3. Add our org units
1118 4. Set up config entry and template entry for the org units
1119 5. Add an entry that meets the MEP scope
1120 6. Check if a managed group entry was created
1121 7. Add a new template entry
1122 8. Add an entry that meets the MEP scope
1123 9. Check if a managed group entry was created
1124 10. Check nsslapd-plugin-depends-on-named for the plugin
1125 11. Clean up
1126 :expectedresults:
1127 1. Success
1128 2. Success
1129 3. Success
1130 4. Success
1131 5. Success
1132 6. Success
1133 7. Success
1134 8. Success
1135 9. Success
1136 10. Success
1137 11. Success
1138 """
1139
1140 inst = topo[0]
1141
1142 # stop the plugin, and start it
1143 plugin = ManagedEntriesPlugin(inst)
1144 plugin.disable()
1145 plugin.enable()
1146
1147 if args == "restart":
1148 return
1149
1150 # If args is None then we run the test suite as pytest standalone and it's not dynamic
1151 if args is None:
1152 inst.restart()
1153
1154 log.info('Testing ' + PLUGIN_MANAGED_ENTRY + '...')
1155
1156 ############################################################################
1157 # Configure plugin
1158 ############################################################################
1159 # Add our org units
1160 ous = OrganizationalUnits(inst, DEFAULT_SUFFIX)
1161 ou_people = ous.create(properties={'ou': 'managed_people'})
1162 ou_groups = ous.create(properties={'ou': 'managed_groups'})
1163
1164 mep_templates = MEPTemplates(inst, DEFAULT_SUFFIX)
1165 mep_template1 = mep_templates.create(properties={
1166 'cn': 'MEP template',
1167 'mepRDNAttr': 'cn',
1168 'mepStaticAttr': 'objectclass: posixGroup|objectclass: extensibleObject'.split('|'),
1169 'mepMappedAttr': 'cn: $cn|uid: $cn|gidNumber: $uidNumber'.split('|')
1170 })
1171 mep_configs = MEPConfigs(inst)
1172 mep_config = mep_configs.create(properties={'cn': 'config',
1173 'originScope': ou_people.dn,
1174 'originFilter': 'objectclass=posixAccount',
1175 'managedBase': ou_groups.dn,
1176 'managedTemplate': mep_template1.dn})
1177 if args is None:
1178 inst.restart()
1179
1180 ############################################################################
1181 # Test plugin
1182 ############################################################################
1183 # Add an entry that meets the MEP scope
1184 test_users_m1 = UserAccounts(inst, DEFAULT_SUFFIX, rdn='ou={}'.format(ou_people.rdn))
1185 test_user1 = test_users_m1.create_test_user(1001)
1186
1187 # Check if a managed group entry was created
1188 entries = inst.search_s('cn={},{}'.format(test_user1.rdn, ou_groups.dn), ldap.SCOPE_BASE, '(objectclass=top)')
1189 assert len(entries) == 1
1190
1191 ############################################################################
1192 # Change the config
1193 ############################################################################
1194 # Add a new template entry
1195 mep_template2 = mep_templates.create(properties={
1196 'cn': 'MEP template2',
1197 'mepRDNAttr': 'uid',
1198 'mepStaticAttr': 'objectclass: posixGroup|objectclass: extensibleObject'.split('|'),
1199 'mepMappedAttr': 'cn: $cn|uid: $cn|gidNumber: $uidNumber'.split('|')
1200 })
1201 mep_config.replace('managedTemplate', mep_template2.dn)
1202
1203 ############################################################################
1204 # Test plugin
1205 ############################################################################
1206 # Add an entry that meets the MEP scope
1207 test_user2 = test_users_m1.create_test_user(1002)
1208
1209 # Check if a managed group entry was created
1210 entries = inst.search_s('uid={},{}'.format(test_user2.rdn, ou_groups.dn), ldap.SCOPE_BASE, '(objectclass=top)')
1211 assert len(entries) == 1
1212
1213 ############################################################################
1214 # Test plugin dependency
1215 ############################################################################
1216 check_dependency(inst, plugin, online=isinstance(args, str))
1217
1218 ############################################################################
1219 # Cleanup
1220 ############################################################################
1221 test_user1.delete()
1222 test_user2.delete()
1223 ou_people.delete()
1224 ou_groups.delete()
1225 mep_config.delete()
1226 mep_template1.delete()
1227 mep_template2.delete()
1228
1229 ############################################################################
1230 # Test passed
1231 ############################################################################
1232 log.info('test_mep: PASS\n')
1233 return
1234
1235
1236 def test_passthru(topo, args=None):
1237 """Test Passthrough Authentication basic functionality
1238
1239 :id: 9b87493b-0493-46f9-8364-6099d0e5d807
1240 :setup: Standalone Instance
1241 :steps:
1242 1. Stop the plugin
1243 2. Restart the instance
1244 3. Create a second backend
1245 4. Create the top of the tree
1246 5. Add user to suffix1
1247 6. Configure and start plugin
1248 7. Login as user
1249 8. Login as root DN
1250 9. Replace 'nsslapd-pluginarg0': ldap uri for second instance
1251 10. Login as user
1252 11. Login as root DN
1253 12. Check nsslapd-plugin-depends-on-named for the plugin
1254 13. Clean up
1255 :expectedresults:
1256 1. Success
1257 2. Success
1258 3. Success
1259 4. Success
1260 5. Success
1261 6. Success
1262 7. Success
1263 8. Success
1264 9. Success
1265 10. Success
1266 11. Success
1267 12. Success
1268 13. Success
1269 """
1270
1271 inst1 = topo[0]
1272 inst2 = topo[1]
1273
1274 # Passthru is a bit picky about the state of the entry - we can't just restart it
1275 if args == "restart":
1276 return
1277
1278 # stop the plugin
1279 plugin = PassThroughAuthenticationPlugin(inst1)
1280 plugin.disable()
1281
1282 # If args is None then we run the test suite as pytest standalone and it's not dynamic
1283 if args is None:
1284 inst1.restart()
1285
1286 PASS_SUFFIX1 = 'dc=pass1,dc=thru'
1287 PASS_SUFFIX2 = 'dc=pass2,dc=thru'
1288 PASS_BE1 = 'PASS1'
1289 PASS_BE2 = 'PASS2'
1290
1291 log.info('Testing ' + PLUGIN_PASSTHRU + '...')
1292
1293 ############################################################################
1294 # Use a new "remote" instance, and a user for auth
1295 ############################################################################
1296 # Create a second backend
1297 backend1 = inst2.backends.create(properties={'cn': PASS_BE1,
1298 'nsslapd-suffix': PASS_SUFFIX1})
1299 backend2 = inst2.backends.create(properties={'cn': PASS_BE2,
1300 'nsslapd-suffix': PASS_SUFFIX2})
1301
1302 # Create the top of the tree
1303 suffix = Domain(inst2, PASS_SUFFIX1)
1304 pass1 = suffix.create(properties={'dc': 'pass1'})
1305 suffix = Domain(inst2, PASS_SUFFIX2)
1306 pass2 = suffix.create(properties={'dc': 'pass2'})
1307
1308 # Add user to suffix1
1309 users = UserAccounts(inst2, pass1.dn, None)
1310 test_user1 = users.create_test_user(1001)
1311 test_user1.replace('userpassword', 'password')
1312
1313 users = UserAccounts(inst2, pass2.dn, None)
1314 test_user2 = users.create_test_user(1002)
1315 test_user2.replace('userpassword', 'password')
1316
1317 ############################################################################
1318 # Configure and start plugin
1319 ############################################################################
1320 plugin.replace('nsslapd-pluginarg0',
1321 'ldap://{}:{}/{}'.format(inst2.host, inst2.port, pass1.dn))
1322 plugin.enable()
1323
1324 # If args is None then we run the test suite as pytest standalone and it's not dynamic
1325 if args is None:
1326 inst1.restart()
1327
1328 ############################################################################
1329 # Test plugin
1330 ############################################################################
1331 # login as user
1332 inst1.simple_bind_s(test_user1.dn, "password")
1333
1334 ############################################################################
1335 # Change the config
1336 ############################################################################
1337 # login as root DN
1338 inst1.simple_bind_s(DN_DM, PASSWORD)
1339
1340 plugin.replace('nsslapd-pluginarg0',
1341 'ldap://{}:{}/{}'.format(inst2.host, inst2.port, pass2.dn))
1342 if args is None:
1343 inst1.restart()
1344
1345 ############################################################################
1346 # Test plugin
1347 ############################################################################
1348
1349 # login as user
1350 inst1.simple_bind_s(test_user2.dn, "password")
1351
1352 # login as root DN
1353 inst1.simple_bind_s(DN_DM, PASSWORD)
1354
1355 # Clean up
1356 backend1.delete()
1357 backend2.delete()
1358
1359 ############################################################################
1360 # Test plugin dependency
1361 ############################################################################
1362 check_dependency(inst1, plugin, online=isinstance(args, str))
1363
1364 ############################################################################
1365 # Test passed
1366 ############################################################################
1367 log.info('test_passthru: PASS\n')
1368 return
1369
1370
1371 def test_referint(topo, args=None):
1372 """Test Referential Integrity basic functionality
1373
1374 :id: 9b87493b-0493-46f9-8364-6099d0e5d808
1375 :setup: Standalone Instance
1376 :steps:
1377 1. Enable the plugin
1378 2. Restart the instance
1379 3. Replace 'referint-membership-attr': 'member'
1380 4. Add some users and a group
1381 5. Grab the referint log file from the plugin
1382 6. Add shared config entry
1383 7. Delete one user
1384 8. Check for integrity
1385 9. Replace 'referint-membership-attr': 'uniquemember'
1386 10. Delete second user
1387 11. Check for integrity
1388 12. The shared config entry uses "member" - the above test used "uniquemember"
1389 13. Recreate users and a group
1390 14. Delete one user
1391 15. Check for integrity
1392 16. Change the shared config entry to use 'uniquemember' and test the plugin
1393 17. Delete second user
1394 18. Check for integrity
1395 19. First change the plugin to use member before we move the shared config that uses uniquemember
1396 20. Remove shared config from plugin
1397 21. Add test user
1398 22. Add user to group
1399 23. Delete a user
1400 24. Check for integrity
1401 25. Check nsslapd-plugin-depends-on-named for the plugin
1402 26. Clean up
1403 :expectedresults:
1404 1. Success
1405 2. Success
1406 3. Success
1407 4. Success
1408 5. Success
1409 6. Success
1410 7. Success
1411 8. Success
1412 9. Success
1413 10. Success
1414 11. Success
1415 12. Success
1416 13. Success
1417 14. Success
1418 15. Success
1419 16. Success
1420 17. Success
1421 18. Success
1422 19. Success
1423 20. Success
1424 21. Success
1425 22. Success
1426 23. Success
1427 24. Success
1428 25. Success
1429 26. Success
1430 """
1431
1432 inst = topo[0]
1433
1434 # stop the plugin, and start it
1435 plugin = ReferentialIntegrityPlugin(inst)
1436 plugin.disable()
1437 plugin.enable()
1438
1439 if args == "restart":
1440 return
1441
1442 # If args is None then we run the test suite as pytest standalone and it's not dynamic
1443 if args is None:
1444 inst.restart()
1445
1446 log.info('Testing ' + PLUGIN_REFER_INTEGRITY + '...')
1447
1448 ############################################################################
1449 # Configure plugin
1450 ############################################################################
1451 plugin.replace('referint-membership-attr', 'member')
1452
1453 ############################################################################
1454 # Test plugin
1455 ############################################################################
1456 # Add some users and a group
1457 users = UserAccounts(inst, DEFAULT_SUFFIX, None)
1458 user1 = users.create_test_user(uid=1001)
1459 user2 = users.create_test_user(uid=1002)
1460
1461 groups = Groups(inst, DEFAULT_SUFFIX, None)
1462 group = groups.create(properties={'cn': 'group',
1463 MEMBER_ATTR: user1.dn})
1464 group.add('objectclass', 'groupOfUniqueNames')
1465 group.add('uniquemember', user2.dn)
1466
1467 # Grab the referint log file from the plugin
1468 referin_logfile = plugin.get_attr_val_utf8('referint-logfile')
1469
1470 # Add shared config entry
1471 referin_config = ReferentialIntegrityConfig(inst, 'cn=RI config,{}'.format(DEFAULT_SUFFIX))
1472 referin_config.create(properties={'cn': 'RI config',
1473 'referint-membership-attr': 'member',
1474 'referint-update-delay': '0',
1475 'referint-logfile': referin_logfile})
1476
1477 user1.delete()
1478
1479 # Check for integrity
1480 entry = inst.search_s(group.dn, ldap.SCOPE_BASE, '(member={})'.format(user1.dn))
1481 assert not entry
1482
1483 ############################################################################
1484 # Change the config
1485 ############################################################################
1486 plugin.replace('referint-membership-attr', 'uniquemember')
1487
1488 ############################################################################
1489 # Test plugin
1490 ############################################################################
1491
1492 user2.delete()
1493
1494 # Check for integrity
1495 entry = inst.search_s(group.dn, ldap.SCOPE_BASE, '(uniquemember={})'.format(user2.dn))
1496 assert not entry
1497
1498 ############################################################################
1499 # Set the shared config entry and test the plugin
1500 ############################################################################
1501 # The shared config entry uses "member" - the above test used "uniquemember"
1502 plugin.set_configarea(referin_config.dn)
1503 group.delete()
1504
1505 user1 = users.create_test_user(uid=1001)
1506 user2 = users.create_test_user(uid=1002)
1507 group = groups.create(properties={'cn': 'group',
1508 MEMBER_ATTR: user1.dn})
1509 group.add('objectclass', 'groupOfUniqueNames')
1510 group.add('uniquemember', user2.dn)
1511
1512 # Delete a user
1513 user1.delete()
1514
1515 # Check for integrity
1516 entry = inst.search_s(group.dn, ldap.SCOPE_BASE, '(member={})'.format(user1.dn))
1517 assert not entry
1518
1519 ############################################################################
1520 # Change the shared config entry to use 'uniquemember' and test the plugin
1521 ############################################################################
1522
1523 referin_config.replace('referint-membership-attr', 'uniquemember')
1524
1525 # Delete a user
1526 user2.delete()
1527
1528 # Check for integrity
1529 entry = inst.search_s(group.dn, ldap.SCOPE_BASE, '(uniquemember={})'.format(user2.dn))
1530 assert not entry
1531
1532 ############################################################################
1533 # Remove shared config from plugin, and retest
1534 ############################################################################
1535 # First change the plugin to use member before we move the shared config that uses uniquemember
1536 plugin.replace('referint-membership-attr', 'member')
1537
1538 # Remove shared config from plugin
1539 plugin.remove_configarea()
1540
1541 # Add test user
1542 user1 = users.create_test_user(uid=1001)
1543
1544 # Add user to group
1545 group.replace('member', user1.dn)
1546
1547 # Delete a user
1548 user1.delete()
1549
1550 # Check for integrity
1551 entry = inst.search_s(group.dn, ldap.SCOPE_BASE, '(member={})'.format(user1.dn))
1552 assert not entry
1553
1554 ############################################################################
1555 # Test plugin dependency
1556 ############################################################################
1557 check_dependency(inst, plugin, online=isinstance(args, str))
1558
1559 ############################################################################
1560 # Cleanup
1561 ############################################################################
1562 group.delete()
1563 referin_config.delete()
1564
1565 ############################################################################
1566 # Test passed
1567 ############################################################################
1568 log.info('test_referint: PASS\n')
1569 return
1570
1571 def test_retrocl(topo, args=None):
1572 """Test Retro Changelog basic functionality
1573
1574 :id: 9b87493b-0493-46f9-8364-6099d0e5d810
1575 :setup: Standalone Instance
1576 :steps:
1577 1. Enable the plugin
1578 2. Restart the instance
1579 3. Gather the current change count (it's not 1 once we start the stability tests)
1580 4. Add a user
1581 5. Check we logged this in the retro cl
1582 6. Change the config - disable plugin
1583 7. Delete the user
1584 8. Check we didn't log this in the retro cl
1585 9. Check nsslapd-plugin-depends-on-named for the plugin
1586 10. Clean up
1587 :expectedresults:
1588 1. Success
1589 2. Success
1590 3. Success
1591 4. Success
1592 5. Success
1593 6. Success
1594 7. Success
1595 8. Success
1596 9. Success
1597 10. Success
1598 """
1599
1600 inst = topo[0]
1601
1602 # stop the plugin, and start it
1603 plugin = RetroChangelogPlugin(inst)
1604 plugin.disable()
1605 plugin.enable()
1606
1607 if args == "restart":
1608 return
1609
1610 # If args is None then we run the test suite as pytest standalone and it's not dynamic
1611 if args is None:
1612 inst.restart()
1613
1614 log.info('Testing ' + PLUGIN_RETRO_CHANGELOG + '...')
1615
1616 ############################################################################
1617 # Configure plugin
1618 ############################################################################
1619
1620 # Gather the current change count (it's not 1 once we start the stabilty tests)
1621 entry = inst.search_s(RETROCL_SUFFIX, ldap.SCOPE_SUBTREE, '(changenumber=*)')
1622 entry_count = len(entry)
1623
1624 ############################################################################
1625 # Test plugin
1626 ############################################################################
1627
1628 # Add a user
1629 users = UserAccounts(inst, DEFAULT_SUFFIX)
1630 user1 = users.create_test_user(uid=1001)
1631
1632 # Check we logged this in the retro cl
1633 entry = inst.search_s(RETROCL_SUFFIX, ldap.SCOPE_SUBTREE, '(changenumber=*)')
1634 assert entry
1635 assert len(entry) != entry_count
1636
1637 entry_count += 1
1638
1639 ############################################################################
1640 # Change the config - disable plugin
1641 ############################################################################
1642 plugin.disable()
1643
1644 # If args is None then we run the test suite as pytest standalone and it's not dynamic
1645 if args is None:
1646 inst.restart()
1647
1648 ############################################################################
1649 # Test plugin
1650 ############################################################################
1651 user1.delete()
1652
1653 # Check we didn't logged this in the retro cl
1654 entry = inst.search_s(RETROCL_SUFFIX, ldap.SCOPE_SUBTREE, '(changenumber=*)')
1655 assert len(entry) == entry_count
1656
1657 plugin.enable()
1658 if args is None:
1659 inst.restart()
1660
1661 ############################################################################
1662 # Test plugin dependency
1663 ############################################################################
1664 check_dependency(inst, plugin, online=isinstance(args, str))
1665
1666 ############################################################################
1667 # Test passed
1668 ############################################################################
1669 log.info('test_retrocl: PASS\n')
1670 return
1671
1672
1673 def _rootdn_restart(inst):
1674 """Special restart wrapper function for rootDN plugin"""
1675
1676 with pytest.raises(ldap.LDAPError):
1677 inst.restart()
1678 # Bind as the user who can make updates to the config
1679 inst.simple_bind_s(USER_DN, USER_PW)
1680 # We need it online for other operations to work
1681 inst.state = DIRSRV_STATE_ONLINE
1682
1683
1684 def test_rootdn(topo, args=None):
1685 """Test Root DNA Access control basic functionality
1686
1687 :id: 9b87493b-0493-46f9-8364-6099d0e5d811
1688 :setup: Standalone Instance
1689 :steps:
1690 1. Enable the plugin
1691 2. Restart the instance
1692 3. Add an user and aci to open up cn=config
1693 4. Set an aci so we can modify the plugin after we deny the root dn
1694 5. Set allowed IP to an unknown host - blocks root dn
1695 6. Bind as Root DN
1696 7. Bind as the user who can make updates to the config
1697 8. Test that invalid plugin changes are rejected
1698 9. Remove the restriction
1699 10. Bind as Root DN
1700 11. Check nsslapd-plugin-depends-on-named for the plugin
1701 12. Clean up
1702 :expectedresults:
1703 1. Success
1704 2. Success
1705 3. Success
1706 4. Success
1707 5. Success
1708 6. Success
1709 7. Success
1710 8. Success
1711 9. Success
1712 10. Success
1713 11. Success
1714 12. Success
1715 """
1716
1717 inst = topo[0]
1718
1719 # stop the plugin, and start it
1720 plugin = RootDNAccessControlPlugin(inst)
1721 plugin.disable()
1722 plugin.enable()
1723
1724 if args == "restart":
1725 return
1726
1727 # If args is None then we run the test suite as pytest standalone and it's not dynamic
1728 if args is None:
1729 inst.restart()
1730
1731 log.info('Testing ' + PLUGIN_ROOTDN_ACCESS + '...')
1732
1733 ############################################################################
1734 # Configure plugin
1735 ############################################################################
1736
1737 # Add an user and aci to open up cn=config
1738 users = UserAccounts(inst, DEFAULT_SUFFIX)
1739 user1 = users.create_test_user(uid=1001)
1740 user1.replace('userpassword', USER_PW)
1741
1742 # Set an aci so we can modify the plugin after ew deny the root dn
1743 ACI = ('(target ="ldap:///cn=config")(targetattr = "*")(version 3.0;acl ' +
1744 '"all access";allow (all)(userdn="ldap:///anyone");)')
1745 inst.config.add('aci', ACI)
1746
1747 # Set allowed IP to an unknown host - blocks root dn
1748 plugin.replace('rootdn-allow-ip', '10.10.10.10')
1749
1750 ############################################################################
1751 # Test plugin
1752 ############################################################################
1753 # Bind as Root DN
1754 if args is None:
1755 _rootdn_restart(inst)
1756 else:
1757 with pytest.raises(ldap.LDAPError):
1758 inst.simple_bind_s(DN_DM, PASSWORD)
1759 # Bind as the user who can make updates to the config
1760 inst.simple_bind_s(USER_DN, USER_PW)
1761
1762 ############################################################################
1763 # Change the config
1764 ############################################################################
1765 # First, test that invalid plugin changes are rejected
1766 if args is None:
1767 plugin.replace('rootdn-deny-ip', '12.12.ZZZ.12')
1768 with pytest.raises((subprocess.CalledProcessError, ValueError)):
1769 inst.restart()
1770 dse_ldif = DSEldif(inst)
1771 dse_ldif.delete(plugin.dn, 'rootdn-deny-ip')
1772 _rootdn_restart(inst)
1773
1774 plugin.replace('rootdn-allow-host', 'host._.com')
1775 with pytest.raises((subprocess.CalledProcessError, ValueError)):
1776 inst.restart()
1777 dse_ldif = DSEldif(inst)
1778 dse_ldif.delete(plugin.dn, 'rootdn-allow-host')
1779 _rootdn_restart(inst)
1780 else:
1781 with pytest.raises(ldap.LDAPError):
1782 plugin.replace('rootdn-deny-ip', '12.12.ZZZ.12')
1783
1784 with pytest.raises(ldap.LDAPError):
1785 plugin.replace('rootdn-allow-host', 'host._.com')
1786
1787 # Remove the restriction
1788 plugin.remove_all('rootdn-allow-ip')
1789 if args is None:
1790 inst.restart()
1791
1792 ############################################################################
1793 # Test plugin
1794 ############################################################################
1795 # Bind as Root DN
1796 inst.simple_bind_s(DN_DM, PASSWORD)
1797
1798 ############################################################################
1799 # Test plugin dependency
1800 ############################################################################
1801 check_dependency(inst, plugin, online=isinstance(args, str))
1802
1803 ############################################################################
1804 # Cleanup - remove ACI from cn=config and test user
1805 ############################################################################
1806 inst.config.remove('aci', ACI)
1807 user1.delete()
1808
1809 ############################################################################
1810 # Test passed
1811 ############################################################################
1812 log.info('test_rootdn: PASS\n')
1813 return
1814
1815
1816 # Array of test functions
1817 func_tests = [test_acctpolicy, test_attruniq, test_automember, test_dna,
1818 test_linkedattrs, test_memberof, test_mep, test_passthru,
1819 test_referint, test_retrocl, test_rootdn]
1820
1821
1822 def check_all_plugins(topo, args="online"):
1823 for func in func_tests:
1824 func(topo, args)
1825
1826 return