Debian Codegraph @

dirsrvtests/tests/suites/automember_plugin/configuration_test.py

raw
1 # --- BEGIN COPYRIGHT BLOCK ---
2 # Copyright (C) 2021 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 ldap
10 import os
11 import pytest
12 from test389.topologies import topology_st as topo
13 from lib389.plugins import AutoMembershipPlugin, AutoMembershipDefinitions, MemberOfPlugin
14 from lib389._constants import DEFAULT_SUFFIX
15
16 pytestmark = pytest.mark.tier1
17
18 def test_configuration(topo):
19 """Automembership plugin and mixed in the plugin configuration
20
21 :id: 45a5a8f8-e800-11e8-ab16-8c16451d917b
22 :setup: Single Instance
23 :steps:
24 1. Automembership plugin fails in a MMR setup, if data and config
25 area mixed in the plugin configuration
26 2. Plugin configuration should throw proper error messages if not configured properly
27 :expectedresults:
28 1. Should success
29 2. Should success
30 """
31 # Configure pluginConfigArea for PLUGIN_AUTO
32 AutoMembershipPlugin(topo.standalone).set("nsslapd-pluginConfigArea", 'cn=config')
33 # Enable MemberOf plugin
34 MemberOfPlugin(topo.standalone).enable()
35 topo.standalone.restart()
36 # Add invalid configuration, which mixes data and config area: All will fail
37 automembers = AutoMembershipDefinitions(topo.standalone)
38 with pytest.raises(ldap.UNWILLING_TO_PERFORM):
39 automembers.create(properties={
40 'cn': 'autouserGroups',
41 'autoMemberScope': f'ou=Employees,cn=config',
42 'autoMemberFilter': "objectclass=posixAccount",
43 'autoMemberDefaultGroup': [f'cn=SuffDef1,ou=autouserGroups,cn=config',
44 f'cn=SuffDef2,ou=autouserGroups,cn=config'],
45 'autoMemberGroupingAttr': 'member:dn'
46 })
47 # Search in error logs
48 assert topo.standalone.ds_error_log.match('.*ERR - auto-membership-plugin - '
49 'automember_parse_config_entry - The default group '
50 '"cn=SuffDef1,ou=autouserGroups,cn=config" '
51 'can not be a child of the plugin config area "cn=config"')
52
53 def test_invalid_regex(topo):
54 """Test invalid regex is properly reportedin the error log
55
56 :id: a6d89f84-ec76-4871-be96-411d051800b1
57 :setup: Standalone Instance
58 :steps:
59 1. Setup automember
60 2. Add invalid regex
61 3. Error log reports useful message
62 :expectedresults:
63 1. Success
64 2. Success
65 3. Success
66 """
67 REGEX_DN = "cn=regex1,cn=testregex,cn=auto membership plugin,cn=plugins,cn=config"
68 REGEX_VALUE = "cn=*invalid*"
69 REGEX_ESC_VALUE = "cn=\\*invalid\\*"
70 GROUP_DN = "cn=demo_group,ou=groups," + DEFAULT_SUFFIX
71
72 AutoMembershipPlugin(topo.standalone).remove_all("nsslapd-pluginConfigArea")
73 automemberplugin = AutoMembershipPlugin(topo.standalone)
74
75 automember_prop = {
76 'cn': 'testRegex',
77 'autoMemberScope': 'ou=People,' + DEFAULT_SUFFIX,
78 'autoMemberFilter': 'objectclass=*',
79 'autoMemberDefaultGroup': GROUP_DN,
80 'autoMemberGroupingAttr': 'member:dn',
81 }
82 automember_defs = AutoMembershipDefinitions(topo.standalone, "cn=Auto Membership Plugin,cn=plugins,cn=config")
83 automember_def = automember_defs.create(properties=automember_prop)
84 automember_def.add_regex_rule("regex1", GROUP_DN, include_regex=[REGEX_VALUE])
85
86 automemberplugin.enable()
87 topo.standalone.restart()
88
89 # Check errors log for invalid message
90 ERR_STR1 = "automember_parse_regex_rule - Unable to parse regex rule"
91 ERR_STR2 = f"Skipping invalid inclusive regex rule in rule entry \"{REGEX_DN}\" \\(rule = \"{REGEX_ESC_VALUE}\"\\)"
92 assert topo.standalone.searchErrorsLog(ERR_STR1)
93 assert topo.standalone.searchErrorsLog(ERR_STR2)
94
95
96 if __name__ == "__main__":
97 CURRENT_FILE = os.path.realpath(__file__)
98 pytest.main("-s -v %s" % CURRENT_FILE)