Debian Codegraph @

dirsrvtests/tests/suites/get_effective_rights/acceptance_test.py

raw
1 # --- BEGIN COPYRIGHT BLOCK ---
2 # Copyright (C) 2022 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 logging
11 from ldap.controls import GetEffectiveRightsControl
12 from lib389.idm.domain import Domain
13 from lib389.idm.group import Groups
14 from lib389.idm.user import UserAccounts, TEST_USER_PROPERTIES
15 from test389.topologies import topology_st as topo
16 from lib389._constants import *
17 from lib389.utils import *
18
19 pytestmark = pytest.mark.tier1
20
21 TEST_ENTRY_NAME = 'testuser'
22 TEST_GROUP_NAME = 'group1'
23 TEST_GROUP2_NAME = 'group1'
24
25 DEBUGGING = os.getenv('DEBUGGING', default=False)
26 if DEBUGGING:
27 logging.getLogger(__name__).setLevel(logging.DEBUG)
28 else:
29 logging.getLogger(__name__).setLevel(logging.INFO)
30 log = logging.getLogger(__name__)
31
32 @pytest.fixture(scope="module")
33 def create_user(topo):
34 """
35 Create a user.
36 Create a request_ctrl.
37 """
38 log.info('Adding user {}'.format(TEST_ENTRY_NAME))
39 users = UserAccounts(topo.standalone, DEFAULT_SUFFIX, rdn=None)
40 test_user = users.create(properties=TEST_USER_PROPERTIES)
41
42 request_ctrl = GetEffectiveRightsControl(criticality=True,
43 authzId=ensure_bytes("dn:{}".format(test_user.dn)))
44 return (test_user,request_ctrl)
45
46 def test_group_aci_entry_exists(topo,create_user):
47 """This test case adds the groupdn aci and check ger contains 'vadn'
48
49 :id: 1d73f715-e4b3-4ed6-a93b-9d529898ca78
50 :setup: Standalone instance
51 :steps:
52 1. Create a group.
53 2. Add the user as member into the group.
54 3. Apply the ACI which will give the group full rights.
55 4. Check entryLevelRights value for entries.
56 5. Check 'vadn' is in the entryLevelRights.
57 :expectedresults:
58 1. It should pass
59 2. It should pass
60 3. It should pass
61 4. It should pass
62 5. It should pass
63 """
64 (test_user,request_ctrl) = create_user
65 log.info('Adding group {}'.format(TEST_GROUP_NAME))
66 groups = Groups(topo.standalone, DEFAULT_SUFFIX, rdn=None)
67 group_properties = {
68 'cn': TEST_GROUP_NAME,
69 'description': 'testgroup'}
70 test_group = groups.create(properties=group_properties)
71 test_group.add_member(test_user.dn)
72 suffix = Domain(topo.standalone, DEFAULT_SUFFIX)
73 ACI_TARGET = '(targetattr="*")'
74 ACI_TARGET_FILTER = '(targetfilter ="(objectClass=person)")'
75 ACI_ALLOW = '(version 3.0; acl "give group1 full rights"; allow (all) '
76 ACI_SUBJECT = 'groupdn = "ldap:///{}";)'.format(test_group.dn)
77 ACI_BODY = ACI_TARGET + ACI_TARGET_FILTER + ACI_ALLOW + ACI_SUBJECT
78 log.info("Add an ACI granting add access to a user matching the groupdn")
79 suffix.add('aci', ACI_BODY)
80 entries = topo.standalone.search_ext('{}'.format(test_user.dn),
81 ldap.SCOPE_SUBTREE,
82 "objectclass=person",
83 serverctrls=[request_ctrl])
84
85 rtype, rdata, rmsgid, response_ctrl = topo.standalone.result3(entries)
86 for dn, attrs in rdata:
87 topo.standalone.log.info("dn: %s" % dn)
88 value = attrs['entryLevelRights'][0]
89 topo.standalone.log.info("######## entryLevelRights: %r" % value)
90 assert b'vadn' in value
91
92 def test_group_aci_template_entry(topo,create_user):
93 """This test case adds the groupdn aci and check ger contains 'vadn'
94
95 :id: 714c8649-36b6-4e28-a4c5-4b16ede4355f
96 :setup: Standalone instance
97 :steps:
98 1. Apply the ACI which will give the user full rights.
99 2. Check entryLevelRights value for a non-existing template entry.
100 3. Check 'vadn' is in the entryLevelRights of the non-existing template entry.
101 :expectedresults:
102 1. It should pass
103 2. It should pass
104 3. It should pass
105 """
106 (test_user, request_ctrl) = create_user
107 suffix = Domain(topo.standalone, DEFAULT_SUFFIX)
108 ACI_TARGET = '(targetattr="*")'
109 ACI_TARGET_FILTER = '(targetfilter ="(objectClass=person)")'
110 ACI_ALLOW = '(version 3.0; acl "allow all to target"; allow (all) '
111 ACI_SUBJECT = 'userdn = "ldap:///{}";)'.format(test_user.dn)
112 ACI_BODY = ACI_TARGET + ACI_TARGET_FILTER + ACI_ALLOW + ACI_SUBJECT
113 log.info("Add an ACI granting add access to a user matching the userdn")
114 suffix.add('aci', ACI_BODY)
115 entries = topo.standalone.search_ext(DEFAULT_SUFFIX,
116 ldap.SCOPE_SUBTREE,
117 "cn=sub_entry11", ["sn@person:cn", "member@groupofnames:cn"],
118 serverctrls=[request_ctrl])
119
120 rtype, rdata, rmsgid, response_ctrl = topo.standalone.result3(entries)
121 for dn, attrs in rdata:
122 if dn == 'cn=template_person_objectclass,dc=example,dc=com':
123 topo.standalone.log.info("dn: %s" % dn)
124 value = attrs['entryLevelRights'][0]
125 topo.standalone.log.info("######## entryLevelRights: %r" % value)
126 assert b'vadn' in value
127 elif dn == 'cn=template_groupofnames_objectclass,dc=example,dc=com':
128 topo.standalone.log.info("dn: %s" % dn)
129 value = attrs['entryLevelRights'][0]
130 topo.standalone.log.info("######## entryLevelRights: %r" % value)
131 assert b'vadn' not in value
132 else:
133 assert False
134
135
136 if __name__ == '__main__':
137 # Run isolated
138 # -s for DEBUG mode
139 CURRENT_FILE = os.path.realpath(__file__)
140 pytest.main('-s {}'.format(CURRENT_FILE))