Debian Codegraph @

dirsrvtests/tests/suites/plugins/deref_aci_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 os
10 import logging
11 import pytest
12 import ldap
13 from lib389._constants import DEFAULT_SUFFIX, PASSWORD
14 from lib389.idm.organizationalunit import OrganizationalUnits
15 from lib389.idm.user import UserAccounts, TEST_USER_PROPERTIES
16 from lib389.idm.group import Groups
17 from test389.topologies import topology_st as topo
18
19 pytestmark = pytest.mark.tier1
20
21 DEBUGGING = os.getenv("DEBUGGING", default=None)
22 if DEBUGGING:
23 logging.getLogger(__name__).setLevel(logging.DEBUG)
24 else:
25 logging.getLogger(__name__).setLevel(logging.INFO)
26 log = logging.getLogger(__name__)
27
28 ACCTS_DN = "ou=accounts,dc=example,dc=com"
29 USERS_DN = "ou=users,ou=accounts,dc=example,dc=com"
30 GROUPS_DN = "ou=groups,ou=accounts,dc=example,dc=com"
31 ADMIN_GROUP_DN = "cn=admins,ou=groups,ou=accounts,dc=example,dc=com"
32 ADMIN_DN = "uid=admin,ou=users,ou=accounts,dc=example,dc=com"
33
34 ACCTS_ACI = ('(targetattr="userPassword")(version 3.0; acl "allow password ' +
35 'search"; allow(search) userdn = "ldap:///all";)')
36 USERS_ACI = ('(targetattr = "cn || createtimestamp || description || displayname || entryusn || gecos ' +
37 '|| gidnumber || givenname || homedirectory || initials || ' +
38 'loginshell || manager || modifytimestamp || objectclass || sn || title || uid || uidnumber")' +
39 '(targetfilter = "(objectclass=posixaccount)")' +
40 '(version 3.0;acl "Read Attributes";allow (compare,read,search) userdn = "ldap:///anyone";)')
41 GROUPS_ACIS = [
42 (
43 '(targetattr = "businesscategory || cn || createtimestamp || description |' +
44 '| entryusn || gidnumber || mepmanagedby || modifytimestamp || o || objectclass || ou || own' +
45 'er || seealso")(targetfilter = "(objectclass=posixgroup)")(version 3.0;acl' +
46 '"permission:System: Read Groups";allow (compare,re' +
47 'ad,search) userdn = "ldap:///anyone";)'
48 ),
49 (
50 '(targetattr = "member || memberof || memberuid")(targetfilter = '+
51 '"(objectclass=posixgroup)")(version 3.0;acl' +
52 '"permission:System: Read Group Membership";allow (compare,read' +
53 ',search) userdn = "ldap:///all";)'
54 )
55 ]
56
57
58 def test_deref_and_access_control(topo):
59 """Test that the deref plugin honors access control rules correctly
60
61 The setup mimics a generic IPA DIT with its ACI's. The userpassword
62 attribute should not be returned
63
64 :id: bedb6af2-b765-479d-808c-df0348e0ec95
65 :setup: Standalone Instance
66 :steps:
67 1. Create container entries with aci's
68 2. Perform deref search and make sure userpassword is not returned
69 :expectedresults:
70 1. Success
71 2. Success
72 """
73
74 topo.standalone.config.set('nsslapd-schemacheck', 'off')
75 if DEBUGGING:
76 topo.standalone.config.enable_log('audit')
77 topo.standalone.config.set('nsslapd-errorlog-level', '128')
78
79 # Accounts
80 ou1 = OrganizationalUnits(topo.standalone, DEFAULT_SUFFIX)
81 ou1.create(properties={
82 'ou': 'accounts',
83 'aci': ACCTS_ACI
84 })
85
86 # Users
87 ou2 = OrganizationalUnits(topo.standalone, ACCTS_DN)
88 ou2.create(properties={
89 'ou': 'users',
90 'aci': USERS_ACI
91 })
92
93 # Groups
94 ou3 = OrganizationalUnits(topo.standalone, ACCTS_DN)
95 ou3.create(properties={
96 'ou': 'groups',
97 'aci': GROUPS_ACIS
98 })
99
100 # Create User
101 users = UserAccounts(topo.standalone, USERS_DN, rdn=None)
102 user_props = TEST_USER_PROPERTIES.copy()
103 user_props.update(
104 {
105 'uid': 'user',
106 'objectclass': ['posixAccount', 'extensibleObject'],
107 'userpassword': PASSWORD
108 }
109 )
110 user = users.create(properties=user_props)
111
112 # Create Admin user
113 user_props = TEST_USER_PROPERTIES.copy()
114 user_props.update(
115 {
116 'uid': 'admin',
117 'objectclass': ['posixAccount', 'extensibleObject', 'inetuser'],
118 'userpassword': PASSWORD,
119 'memberOf': ADMIN_GROUP_DN
120 }
121 )
122 users.create(properties=user_props)
123
124 # Create Admin group
125 groups = Groups(topo.standalone, GROUPS_DN, rdn=None)
126 group_props = {
127 'cn': 'admins',
128 'gidNumber': '123',
129 'objectclass': ['posixGroup', 'extensibleObject'],
130 'member': ADMIN_DN
131 }
132 groups.create(properties=group_props)
133
134 # Bind as user, then perform deref search on admin user
135 user.rebind(PASSWORD)
136 result, control_response = topo.standalone.dereference(
137 'member:cn,userpassword',
138 base=ADMIN_GROUP_DN,
139 scope=ldap.SCOPE_BASE)
140
141 log.info('Check, that the dereference search result does not have userpassword')
142 assert result[0][2][0].entry[0]['attrVals'][0]['type'] != 'userpassword'
143
144
145 if __name__ == '__main__':
146 # Run isolated
147 # -s for DEBUG mode
148 CURRENT_FILE = os.path.realpath(__file__)
149 pytest.main(["-s", CURRENT_FILE])