| 1 |
# --- BEGIN COPYRIGHT BLOCK --- |
| 2 |
# Copyright (C) 2020 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, os, ldap |
| 10 |
from lib389._constants import DEFAULT_SUFFIX, PW_DM |
| 11 |
from lib389.idm.user import UserAccount |
| 12 |
from lib389.idm.account import Anonymous |
| 13 |
from lib389.idm.group import Group, UniqueGroup |
| 14 |
from lib389.idm.organizationalunit import OrganizationalUnit, OrganizationalUnits |
| 15 |
from test389.topologies import topology_st as topo |
| 16 |
from lib389.idm.domain import Domain |
| 17 |
|
| 18 |
pytestmark = pytest.mark.tier1 |
| 19 |
|
| 20 |
CONTAINER_1_DELADD = "ou=Product Development,{}".format(DEFAULT_SUFFIX) |
| 21 |
CONTAINER_2_DELADD = "ou=Accounting,{}".format(DEFAULT_SUFFIX) |
| 22 |
USER_DELADD = "cn=Jeff Vedder,{}".format(CONTAINER_1_DELADD) |
| 23 |
USER_WITH_ACI_DELADD = "cn=Sam Carter,{}".format(CONTAINER_2_DELADD) |
| 24 |
DYNAMIC_MODRDN = "cn=Test DYNAMIC_MODRDN Group 70, {}".format(DEFAULT_SUFFIX) |
| 25 |
SAM_DAMMY_MODRDN = "cn=Sam Carter1,ou=Accounting,{}".format(DEFAULT_SUFFIX) |
| 26 |
TRAC340_MODRDN = "cn=TRAC340_MODRDN,{}".format(DEFAULT_SUFFIX) |
| 27 |
NEWENTRY9_MODRDN = "cn=NEWENTRY9_MODRDN,{}".format("ou=People,{}".format(DEFAULT_SUFFIX)) |
| 28 |
OU0_OU_MODRDN = "ou=OU0,{}".format(DEFAULT_SUFFIX) |
| 29 |
OU2_OU_MODRDN = "ou=OU2,{}".format(DEFAULT_SUFFIX) |
| 30 |
|
| 31 |
|
| 32 |
@pytest.fixture(scope="function") |
| 33 |
def aci_of_user(request, topo): |
| 34 |
aci_list = Domain(topo.standalone, DEFAULT_SUFFIX).get_attr_vals('aci') |
| 35 |
|
| 36 |
def finofaci(): |
| 37 |
domain = Domain(topo.standalone, DEFAULT_SUFFIX) |
| 38 |
domain.set('aci', None) |
| 39 |
for i in aci_list: |
| 40 |
domain.add("aci", i) |
| 41 |
|
| 42 |
request.addfinalizer(finofaci) |
| 43 |
|
| 44 |
|
| 45 |
@pytest.fixture(scope="function") |
| 46 |
def _add_user(request, topo): |
| 47 |
ou = OrganizationalUnit(topo.standalone, 'ou=Product Development,{}'.format(DEFAULT_SUFFIX)) |
| 48 |
ou.create(properties={'ou': 'Product Development'}) |
| 49 |
|
| 50 |
ou = OrganizationalUnit(topo.standalone, 'ou=Accounting,{}'.format(DEFAULT_SUFFIX)) |
| 51 |
ou.create(properties={'ou': 'Accounting'}) |
| 52 |
|
| 53 |
groups = Group(topo.standalone, DYNAMIC_MODRDN) |
| 54 |
group_properties = {"cn": "Test DYNAMIC_MODRDN Group 70", |
| 55 |
"objectclass": ["top", 'groupofURLs'], |
| 56 |
'memberURL': 'ldap:///{}??base?(cn=*)'.format(USER_WITH_ACI_DELADD)} |
| 57 |
groups.create(properties=group_properties) |
| 58 |
|
| 59 |
properties = { |
| 60 |
'uid': 'Jeff Vedder', |
| 61 |
'cn': 'Jeff Vedder', |
| 62 |
'sn': 'user', |
| 63 |
'uidNumber': '1000', |
| 64 |
'gidNumber': '2000', |
| 65 |
'homeDirectory': '/home/' + 'JeffVedder', |
| 66 |
'userPassword': PW_DM |
| 67 |
} |
| 68 |
user = UserAccount(topo.standalone, 'cn=Jeff Vedder,ou=Product Development,{}'.format(DEFAULT_SUFFIX)) |
| 69 |
user.create(properties=properties) |
| 70 |
|
| 71 |
properties = { |
| 72 |
'uid': 'Sam Carter', |
| 73 |
'cn': 'Sam Carter', |
| 74 |
'sn': 'user', |
| 75 |
'uidNumber': '1000', |
| 76 |
'gidNumber': '2000', |
| 77 |
'homeDirectory': '/home/' + 'SamCarter', |
| 78 |
'userPassword': PW_DM |
| 79 |
} |
| 80 |
user = UserAccount(topo.standalone, 'cn=Sam Carter,ou=Accounting,{}'.format(DEFAULT_SUFFIX)) |
| 81 |
user.create(properties=properties) |
| 82 |
|
| 83 |
def fin(): |
| 84 |
for DN in [USER_DELADD,USER_WITH_ACI_DELADD,DYNAMIC_MODRDN,CONTAINER_2_DELADD,CONTAINER_1_DELADD]: |
| 85 |
UserAccount(topo.standalone, DN).delete() |
| 86 |
|
| 87 |
request.addfinalizer(fin) |
| 88 |
|
| 89 |
|
| 90 |
def test_allow_write_privilege_to_anyone(topo, _add_user, aci_of_user, request): |
| 91 |
"""Modrdn Test 1 Allow write privilege to anyone |
| 92 |
|
| 93 |
:id: 4406f12e-7932-11e8-9dea-8c16451d917b |
| 94 |
:setup: server |
| 95 |
:steps: |
| 96 |
1. Add test entry |
| 97 |
2. Add ACI |
| 98 |
3. User should follow ACI role |
| 99 |
:expectedresults: |
| 100 |
1. Entry should be added |
| 101 |
2. Operation should succeed |
| 102 |
3. Operation should succeed |
| 103 |
""" |
| 104 |
Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", |
| 105 |
'(target ="ldap:///{}")(targetattr="*")(version 3.0;acl "{}";allow ' |
| 106 |
'(write) (userdn = "ldap:///anyone");)'.format(DEFAULT_SUFFIX, request.node.name)) |
| 107 |
conn = Anonymous(topo.standalone).bind() |
| 108 |
# Allow write privilege to anyone |
| 109 |
useraccount = UserAccount(conn, USER_WITH_ACI_DELADD) |
| 110 |
useraccount.rename("cn=Jeff Vedder") |
| 111 |
assert 'cn=Jeff Vedder,ou=Accounting,dc=example,dc=com' == useraccount.dn |
| 112 |
useraccount = UserAccount(conn, "cn=Jeff Vedder,ou=Accounting,dc=example,dc=com") |
| 113 |
useraccount.rename("cn=Sam Carter") |
| 114 |
assert 'cn=Sam Carter,ou=Accounting,dc=example,dc=com' == useraccount.dn |
| 115 |
|
| 116 |
|
| 117 |
def test_allow_write_privilege_to_dynamic_group_with_scope_set_to_base_in_ldap_url( |
| 118 |
topo, _add_user, aci_of_user, request |
| 119 |
): |
| 120 |
"""Modrdn Test 2 Allow write privilege to DYNAMIC_MODRDN group with scope set to base in LDAP URL |
| 121 |
|
| 122 |
:id: 4c0f8c00-7932-11e8-8398-8c16451d917b |
| 123 |
:setup: server |
| 124 |
:steps: |
| 125 |
1. Add test entry |
| 126 |
2. Add ACI |
| 127 |
3. User should follow ACI role |
| 128 |
:expectedresults: |
| 129 |
1. Entry should be added |
| 130 |
2. Operation should succeed |
| 131 |
3. Operation should succeed |
| 132 |
""" |
| 133 |
Domain(topo.standalone, DEFAULT_SUFFIX).add("aci",'(target = ldap:///{})(targetattr="*")(version 3.0; acl "{}"; allow(all)(groupdn = "ldap:///{}"); )'.format(DEFAULT_SUFFIX, request.node.name, DYNAMIC_MODRDN)) |
| 134 |
conn = UserAccount(topo.standalone, USER_WITH_ACI_DELADD).bind(PW_DM) |
| 135 |
# Allow write privilege to DYNAMIC_MODRDN group with scope set to base in LDAP URL |
| 136 |
useraccount = UserAccount(conn, USER_DELADD) |
| 137 |
useraccount.rename("cn=Jeffbo Vedder") |
| 138 |
assert 'cn=Jeffbo Vedder,ou=Product Development,dc=example,dc=com' == useraccount.dn |
| 139 |
useraccount = UserAccount(conn, "cn=Jeffbo Vedder,{}".format(CONTAINER_1_DELADD)) |
| 140 |
useraccount.rename("cn=Jeff Vedder") |
| 141 |
assert 'cn=Jeff Vedder,ou=Product Development,dc=example,dc=com' == useraccount.dn |
| 142 |
|
| 143 |
|
| 144 |
def test_write_access_to_naming_atributes(topo, _add_user, aci_of_user, request): |
| 145 |
"""Test for write access to naming atributes |
| 146 |
Test that check for add writes to the new naming attr |
| 147 |
|
| 148 |
:id: 532fc630-7932-11e8-8924-8c16451d917b |
| 149 |
:setup: server |
| 150 |
:steps: |
| 151 |
1. Add test entry |
| 152 |
2. Add ACI |
| 153 |
3. User should follow ACI role |
| 154 |
:expectedresults: |
| 155 |
1. Entry should be added |
| 156 |
2. Operation should succeed |
| 157 |
3. Operation should succeed |
| 158 |
""" |
| 159 |
Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", '(target ="ldap:///{}")(targetattr != "uid")(version 3.0;acl "{}";allow (write) (userdn = "ldap:///anyone");)'.format(DEFAULT_SUFFIX, request.node.name)) |
| 160 |
conn = UserAccount(topo.standalone, USER_WITH_ACI_DELADD).bind(PW_DM) |
| 161 |
#Test for write access to naming atributes |
| 162 |
useraccount = UserAccount(conn, USER_WITH_ACI_DELADD) |
| 163 |
with pytest.raises(ldap.INSUFFICIENT_ACCESS): |
| 164 |
useraccount.rename("uid=Jeffbo Vedder") |
| 165 |
|
| 166 |
|
| 167 |
def test_write_access_to_naming_atributes_two(topo, _add_user, aci_of_user, request): |
| 168 |
"""Test for write access to naming atributes (2) |
| 169 |
|
| 170 |
:id: 5a2077d2-7932-11e8-9e7b-8c16451d917b |
| 171 |
:setup: server |
| 172 |
:steps: |
| 173 |
1. Add test entry |
| 174 |
2. Add ACI |
| 175 |
3. User should follow ACI role |
| 176 |
4. Now try to modrdn it to cn, won't work if request deleteoldrdn. |
| 177 |
:expectedresults: |
| 178 |
1. Entry should be added |
| 179 |
2. Operation should succeed |
| 180 |
3. Operation should succeed |
| 181 |
4. Operation should not succeed |
| 182 |
""" |
| 183 |
Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", '(target ="ldap:///{}")(targetattr != "uid")(version 3.0;acl "{}";allow (write) (userdn = "ldap:///anyone");)'.format(DEFAULT_SUFFIX, request.node.name)) |
| 184 |
properties = { |
| 185 |
'uid': 'Sam Carter1', |
| 186 |
'cn': 'Sam Carter1', |
| 187 |
'sn': 'user', |
| 188 |
'uidNumber': '1000', |
| 189 |
'gidNumber': '2000', |
| 190 |
'homeDirectory': '/home/' + 'SamCarter1' |
| 191 |
} |
| 192 |
user = UserAccount(topo.standalone, 'cn=Sam Carter1,ou=Accounting,{}'.format(DEFAULT_SUFFIX)) |
| 193 |
user.create(properties=properties) |
| 194 |
user.set("userPassword", "password") |
| 195 |
conn = UserAccount(topo.standalone, USER_WITH_ACI_DELADD).bind(PW_DM) |
| 196 |
# Test for write access to naming atributes |
| 197 |
useraccount = UserAccount(conn, SAM_DAMMY_MODRDN) |
| 198 |
with pytest.raises(ldap.INSUFFICIENT_ACCESS): |
| 199 |
useraccount.rename("uid=Jeffbo Vedder") |
| 200 |
UserAccount(topo.standalone, SAM_DAMMY_MODRDN).delete() |
| 201 |
|
| 202 |
|
| 203 |
def test_access_aci_list_contains_any_deny_rule(topo, _add_user, aci_of_user): |
| 204 |
"""RHDS denies MODRDN access if ACI list contains any DENY rule |
| 205 |
Bug description: If you create a deny ACI for some or more attributes there is incorrect behaviour |
| 206 |
as you cannot rename the entry anymore |
| 207 |
|
| 208 |
:id: 62cbbb8a-7932-11e8-96a7-8c16451d917b |
| 209 |
:setup: server |
| 210 |
:steps: |
| 211 |
1. Add test entry |
| 212 |
2. Adding a new ou ou=People to $BASEDN |
| 213 |
3. Adding a user NEWENTRY9_MODRDN to ou=People,$BASEDN |
| 214 |
4. Adding an allow rule for NEWENTRY9_MODRDN and for others an aci deny rule |
| 215 |
:expectedresults: |
| 216 |
1. Entry should be added |
| 217 |
2. Operation should succeed |
| 218 |
3. Operation should succeed |
| 219 |
4. Operation should succeed |
| 220 |
""" |
| 221 |
properties = { |
| 222 |
'uid': 'NEWENTRY9_MODRDN', |
| 223 |
'cn': 'NEWENTRY9_MODRDN_People', |
| 224 |
'sn': 'user', |
| 225 |
'uidNumber': '1000', |
| 226 |
'gidNumber': '2000', |
| 227 |
'homeDirectory': '/home/' + 'NEWENTRY9_MODRDN' |
| 228 |
} |
| 229 |
user = UserAccount(topo.standalone, 'cn=NEWENTRY9_MODRDN,ou=People,{}'.format(DEFAULT_SUFFIX)) |
| 230 |
user.create(properties=properties) |
| 231 |
user.set("userPassword", "password") |
| 232 |
user.set("telephoneNumber", "989898191") |
| 233 |
user.set("mail", "[email protected]") |
| 234 |
user.set("givenName", "givenName") |
| 235 |
user.set("uid", "NEWENTRY9_MODRDN") |
| 236 |
OrganizationalUnits(topo.standalone, DEFAULT_SUFFIX).get('People').add("aci", ['(targetattr = "*") ' |
| 237 |
'(version 3.0;acl "admin";allow (all)(userdn = "ldap:///{}");)'.format(NEWENTRY9_MODRDN), |
| 238 |
'(targetattr = "mail") (version 3.0;acl "deny_mail";deny (write)(userdn = "ldap:///anyone");)', |
| 239 |
'(targetattr = "uid") (version 3.0;acl "allow uid";allow (write)(userdn = "ldap:///{}");)'.format(NEWENTRY9_MODRDN)]) |
| 240 |
UserAccount(topo.standalone, NEWENTRY9_MODRDN).replace("userpassword", "Anuj") |
| 241 |
useraccount = UserAccount(topo.standalone, NEWENTRY9_MODRDN) |
| 242 |
useraccount.rename("uid=newrdnchnged") |
| 243 |
assert 'uid=newrdnchnged,ou=People,dc=example,dc=com' == useraccount.dn |
| 244 |
|
| 245 |
|
| 246 |
def test_renaming_target_entry(topo, _add_user, aci_of_user): |
| 247 |
"""Test for renaming target entry |
| 248 |
|
| 249 |
:id: 6be1d33a-7932-11e8-9115-8c16451d917b |
| 250 |
:setup: server |
| 251 |
:steps: |
| 252 |
1. Add test entry |
| 253 |
2. Create a test user entry |
| 254 |
3. Create a new ou entry with an aci |
| 255 |
4. Make sure uid=$MYUID has the access |
| 256 |
5. Rename ou=OU0 to ou=OU1 |
| 257 |
6. Create another ou=OU2 |
| 258 |
7. Move ou=OU1 under ou=OU2 |
| 259 |
8. Make sure uid=$MYUID still has the access |
| 260 |
:expectedresults: |
| 261 |
1. Entry should be added |
| 262 |
2. Operation should succeed |
| 263 |
3. Operation should succeed |
| 264 |
4. Operation should succeed |
| 265 |
5. Operation should succeed |
| 266 |
6. Operation should succeed |
| 267 |
7. Operation should succeed |
| 268 |
8. Operation should succeed |
| 269 |
""" |
| 270 |
properties = { |
| 271 |
'uid': 'TRAC340_MODRDN', |
| 272 |
'cn': 'TRAC340_MODRDN', |
| 273 |
'sn': 'user', |
| 274 |
'uidNumber': '1000', |
| 275 |
'gidNumber': '2000', |
| 276 |
'homeDirectory': '/home/' + 'TRAC340_MODRDN' |
| 277 |
} |
| 278 |
user = UserAccount(topo.standalone, 'cn=TRAC340_MODRDN,{}'.format(DEFAULT_SUFFIX)) |
| 279 |
user.create(properties=properties) |
| 280 |
user.set("userPassword", "password") |
| 281 |
ou = OrganizationalUnit(topo.standalone, 'ou=OU0,{}'.format(DEFAULT_SUFFIX)) |
| 282 |
ou.create(properties={'ou': 'OU0'}) |
| 283 |
ou.set('aci', '(targetattr="*")(version 3.0; acl "$MYUID";allow(read, search, compare) userdn = "ldap:///{}";)'.format(TRAC340_MODRDN)) |
| 284 |
conn = UserAccount(topo.standalone, TRAC340_MODRDN).bind(PW_DM) |
| 285 |
assert OrganizationalUnits(conn, DEFAULT_SUFFIX).get('OU0') |
| 286 |
# Test for renaming target entry |
| 287 |
OrganizationalUnits(topo.standalone, DEFAULT_SUFFIX).get('OU0').rename("ou=OU1") |
| 288 |
assert OrganizationalUnits(conn, DEFAULT_SUFFIX).get('OU1') |
| 289 |
ou = OrganizationalUnit(topo.standalone, 'ou=OU2,{}'.format(DEFAULT_SUFFIX)) |
| 290 |
ou.create(properties={'ou': 'OU2'}) |
| 291 |
# Test for renaming target entry |
| 292 |
OrganizationalUnits(topo.standalone, DEFAULT_SUFFIX).get('OU1').rename("ou=OU1", newsuperior=OU2_OU_MODRDN) |
| 293 |
assert OrganizationalUnits(conn, DEFAULT_SUFFIX).get('OU1') |
| 294 |
|
| 295 |
|
| 296 |
if __name__ == "__main__": |
| 297 |
CURRENT_FILE = os.path.realpath(__file__) |
| 298 |
pytest.main("-s -v %s" % CURRENT_FILE) |