| 1 |
# --- BEGIN COPYRIGHT BLOCK --- |
| 2 |
# Copyright (C) 2019 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 |
import pytest, os, ldap |
| 11 |
from lib389._constants import DEFAULT_SUFFIX, PW_DM |
| 12 |
from lib389.idm.user import UserAccount |
| 13 |
from lib389.idm.account import Anonymous |
| 14 |
from lib389.idm.group import Group, UniqueGroup |
| 15 |
from lib389.idm.organizationalunit import OrganizationalUnit |
| 16 |
from lib389.idm.group import Groups |
| 17 |
from test389.topologies import topology_st as topo |
| 18 |
from lib389.idm.domain import Domain |
| 19 |
|
| 20 |
pytestmark = pytest.mark.tier1 |
| 21 |
|
| 22 |
CONTAINER_1_DELADD = "ou=Product Development,{}".format(DEFAULT_SUFFIX) |
| 23 |
CONTAINER_2_DELADD = "ou=Accounting,{}".format(DEFAULT_SUFFIX) |
| 24 |
USER_DELADD = "cn=Jeff Vedder,{}".format(CONTAINER_1_DELADD) |
| 25 |
USER_WITH_ACI_DELADD = "cn=Sam Carter,{}".format(CONTAINER_2_DELADD) |
| 26 |
KIRSTENVAUGHAN = "cn=Kirsten Vaughan, ou=Human Resources, {}".format(DEFAULT_SUFFIX) |
| 27 |
HUMAN_OU_GLOBAL = "ou=Human Resources,{}".format(DEFAULT_SUFFIX) |
| 28 |
|
| 29 |
|
| 30 |
@pytest.fixture(scope="function") |
| 31 |
def cleanup_tree(request, topo): |
| 32 |
|
| 33 |
def fin(): |
| 34 |
for i in [USER_DELADD, USER_WITH_ACI_DELADD, KIRSTENVAUGHAN, CONTAINER_1_DELADD, CONTAINER_2_DELADD, HUMAN_OU_GLOBAL]: |
| 35 |
try: |
| 36 |
UserAccount(topo.standalone, i).delete() |
| 37 |
except: |
| 38 |
pass |
| 39 |
|
| 40 |
request.addfinalizer(fin) |
| 41 |
|
| 42 |
|
| 43 |
@pytest.fixture(scope="function") |
| 44 |
def aci_of_user(request, topo): |
| 45 |
# Add anonymous access aci |
| 46 |
ACI_TARGET = "(targetattr=\"*\")(target = \"ldap:///%s\")" % (DEFAULT_SUFFIX) |
| 47 |
ACI_ALLOW = "(version 3.0; acl \"Anonymous Read access\"; allow (read,search,compare)" |
| 48 |
ACI_SUBJECT = "(userdn=\"ldap:///anyone\");)" |
| 49 |
ANON_ACI = ACI_TARGET + ACI_ALLOW + ACI_SUBJECT |
| 50 |
suffix = Domain(topo.standalone, DEFAULT_SUFFIX) |
| 51 |
try: |
| 52 |
suffix.add('aci', ANON_ACI) |
| 53 |
except ldap.TYPE_OR_VALUE_EXISTS: |
| 54 |
pass |
| 55 |
|
| 56 |
aci_list = suffix.get_attr_vals('aci') |
| 57 |
|
| 58 |
def finofaci(): |
| 59 |
domain = Domain(topo.standalone, DEFAULT_SUFFIX) |
| 60 |
domain.set('aci', None) |
| 61 |
for i in aci_list: |
| 62 |
domain.add("aci", i) |
| 63 |
|
| 64 |
request.addfinalizer(finofaci) |
| 65 |
|
| 66 |
|
| 67 |
def test_allow_write_access_to_targetattr_with_a_single_attribute( |
| 68 |
topo, aci_of_user, cleanup_tree): |
| 69 |
"""Modify Test 1 Allow write access to targetattr with a single attribute |
| 70 |
|
| 71 |
:id: 620d7b82-7abf-11e8-a4db-8c16451d917b |
| 72 |
:setup: server |
| 73 |
:steps: |
| 74 |
1. Add test entry |
| 75 |
2. Add ACI |
| 76 |
3. User should follow ACI role |
| 77 |
:expectedresults: |
| 78 |
1. Entry should be added |
| 79 |
2. Operation should succeed |
| 80 |
3. Operation should succeed |
| 81 |
""" |
| 82 |
ACI_BODY = '(targetattr = "title")(version 3.0; acl "ACI NAME"; allow (write) (userdn = "ldap:///anyone") ;)' |
| 83 |
Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY) |
| 84 |
|
| 85 |
ou = OrganizationalUnit(topo.standalone, "ou=Product Development,{}".format(DEFAULT_SUFFIX)) |
| 86 |
ou.create(properties={'ou': 'Product Development'}) |
| 87 |
|
| 88 |
properties = { |
| 89 |
'uid': 'Jeff Vedder', |
| 90 |
'cn': 'Jeff Vedder', |
| 91 |
'sn': 'user', |
| 92 |
'uidNumber': '1000', |
| 93 |
'gidNumber': '2000', |
| 94 |
'homeDirectory': '/home/' + 'JeffVedder', |
| 95 |
'userPassword': PW_DM |
| 96 |
} |
| 97 |
user = UserAccount(topo.standalone, "cn=Jeff Vedder,ou=Product Development,{}".format(DEFAULT_SUFFIX)) |
| 98 |
user.create(properties=properties) |
| 99 |
|
| 100 |
# Allow write access to targetattr with a single attribute |
| 101 |
conn = Anonymous(topo.standalone).bind() |
| 102 |
ua = UserAccount(conn, USER_DELADD) |
| 103 |
ua.add("title", "Architect") |
| 104 |
assert ua.get_attr_val('title') |
| 105 |
ua.remove("title", "Architect") |
| 106 |
|
| 107 |
|
| 108 |
def test_allow_write_access_to_targetattr_with_multiple_attibutes( |
| 109 |
topo, aci_of_user, cleanup_tree): |
| 110 |
"""Modify Test 2 Allow write access to targetattr with multiple attibutes |
| 111 |
|
| 112 |
:id: 6b9f05c6-7abf-11e8-9ba1-8c16451d917b |
| 113 |
:setup: server |
| 114 |
:steps: |
| 115 |
1. Add test entry |
| 116 |
2. Add ACI |
| 117 |
3. User should follow ACI role |
| 118 |
:expectedresults: |
| 119 |
1. Entry should be added |
| 120 |
2. Operation should succeed |
| 121 |
3. Operation should succeed |
| 122 |
""" |
| 123 |
ACI_BODY = '(targetattr = "telephonenumber || roomnumber")(version 3.0; acl "ACI NAME"; allow (write) (userdn = "ldap:///anyone") ;)' |
| 124 |
Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY) |
| 125 |
|
| 126 |
ou = OrganizationalUnit(topo.standalone, "ou=Product Development,{}".format(DEFAULT_SUFFIX)) |
| 127 |
ou.create(properties={'ou': 'Product Development'}) |
| 128 |
|
| 129 |
properties = { |
| 130 |
'uid': 'Jeff Vedder', |
| 131 |
'cn': 'Jeff Vedder', |
| 132 |
'sn': 'user', |
| 133 |
'uidNumber': '1000', |
| 134 |
'gidNumber': '2000', |
| 135 |
'homeDirectory': '/home/' + 'JeffVedder', |
| 136 |
'userPassword': PW_DM |
| 137 |
} |
| 138 |
user = UserAccount(topo.standalone, "cn=Jeff Vedder,ou=Product Development,{}".format(DEFAULT_SUFFIX)) |
| 139 |
user.create(properties=properties) |
| 140 |
|
| 141 |
# Allow write access to targetattr with multiple attibutes |
| 142 |
conn = Anonymous(topo.standalone).bind() |
| 143 |
ua = UserAccount(conn, USER_DELADD) |
| 144 |
ua.add("telephonenumber", "+1 408 555 1212") |
| 145 |
assert ua.get_attr_val('telephonenumber') |
| 146 |
ua.add("roomnumber", "101") |
| 147 |
assert ua.get_attr_val('roomnumber') |
| 148 |
|
| 149 |
|
| 150 |
def test_allow_write_access_to_userdn_all(topo, aci_of_user, cleanup_tree): |
| 151 |
"""Modify Test 3 Allow write access to userdn 'all' |
| 152 |
|
| 153 |
:id: 70c58818-7abf-11e8-afa1-8c16451d917b |
| 154 |
:setup: server |
| 155 |
:steps: |
| 156 |
1. Add test entry |
| 157 |
2. Add ACI |
| 158 |
3. User should follow ACI role |
| 159 |
:expectedresults: |
| 160 |
1. Entry should be added |
| 161 |
2. Operation should succeed |
| 162 |
3. Operation should succeed |
| 163 |
""" |
| 164 |
ACI_BODY = '(targetattr = "*")(version 3.0; acl "ACI NAME"; allow (write) (userdn = "ldap:///all") ;)' |
| 165 |
Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY) |
| 166 |
|
| 167 |
for i in ['Product Development', 'Accounting']: |
| 168 |
ou = OrganizationalUnit(topo.standalone, "ou={},{}".format(i, DEFAULT_SUFFIX)) |
| 169 |
ou.create(properties={'ou': i}) |
| 170 |
|
| 171 |
for i in ['Jeff Vedder,ou=Product Development', 'Sam Carter,ou=Accounting']: |
| 172 |
properties = { |
| 173 |
'uid': i, |
| 174 |
'cn': i, |
| 175 |
'sn': 'user', |
| 176 |
'uidNumber': '1000', |
| 177 |
'gidNumber': '2000', |
| 178 |
'homeDirectory': '/home/' + i, |
| 179 |
'userPassword': PW_DM |
| 180 |
} |
| 181 |
user = UserAccount(topo.standalone, "cn={},{}".format(i, DEFAULT_SUFFIX)) |
| 182 |
user.create(properties=properties) |
| 183 |
|
| 184 |
# Allow write access to userdn 'all' |
| 185 |
conn = Anonymous(topo.standalone).bind() |
| 186 |
with pytest.raises(ldap.INSUFFICIENT_ACCESS): |
| 187 |
UserAccount(conn, USER_DELADD).add("title", "Architect") |
| 188 |
conn = UserAccount(topo.standalone, USER_WITH_ACI_DELADD).bind(PW_DM) |
| 189 |
UserAccount(conn, USER_DELADD).add("title", "Architect") |
| 190 |
assert UserAccount(conn, USER_DELADD).get_attr_val('title') |
| 191 |
|
| 192 |
|
| 193 |
def test_allow_write_access_to_userdn_with_wildcards_in_dn( |
| 194 |
topo, aci_of_user, cleanup_tree): |
| 195 |
"""Modify Test 4 Allow write access to userdn with wildcards in DN |
| 196 |
|
| 197 |
:id: 766c2312-7abf-11e8-b57d-8c16451d917b |
| 198 |
:setup: server |
| 199 |
:steps: |
| 200 |
1. Add test entry |
| 201 |
2. Add ACI |
| 202 |
3. User should follow ACI role |
| 203 |
:expectedresults: |
| 204 |
1. Entry should be added |
| 205 |
2. Operation should succeed |
| 206 |
3. Operation should succeed |
| 207 |
""" |
| 208 |
ACI_BODY = '(targetattr = "*")(version 3.0; acl "ACI NAME"; allow (write)(userdn = "ldap:///cn=*, ou=Product Development,{}") ;)'.format(DEFAULT_SUFFIX) |
| 209 |
Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY) |
| 210 |
|
| 211 |
ou = OrganizationalUnit(topo.standalone, "ou=Product Development,{}".format(DEFAULT_SUFFIX)) |
| 212 |
ou.create(properties={'ou': 'Product Development'}) |
| 213 |
|
| 214 |
properties = { |
| 215 |
'uid': 'Jeff Vedder', |
| 216 |
'cn': 'Jeff Vedder', |
| 217 |
'sn': 'user', |
| 218 |
'uidNumber': '1000', |
| 219 |
'gidNumber': '2000', |
| 220 |
'homeDirectory': '/home/' + 'JeffVedder', |
| 221 |
'userPassword': PW_DM |
| 222 |
} |
| 223 |
user = UserAccount(topo.standalone, "cn=Jeff Vedder,ou=Product Development,{}".format(DEFAULT_SUFFIX)) |
| 224 |
user.create(properties=properties) |
| 225 |
|
| 226 |
conn = UserAccount(topo.standalone, USER_DELADD).bind(PW_DM) |
| 227 |
# Allow write access to userdn with wildcards in DN |
| 228 |
ua = UserAccount(conn, USER_DELADD) |
| 229 |
ua.add("title", "Architect") |
| 230 |
assert ua.get_attr_val('title') |
| 231 |
|
| 232 |
|
| 233 |
def test_allow_write_access_to_userdn_with_multiple_dns(topo, aci_of_user, cleanup_tree): |
| 234 |
"""Modify Test 5 Allow write access to userdn with multiple DNs |
| 235 |
|
| 236 |
:id: 7aae760a-7abf-11e8-bc3a-8c16451d917b |
| 237 |
:setup: server |
| 238 |
:steps: |
| 239 |
1. Add test entry |
| 240 |
2. Add ACI |
| 241 |
3. User should follow ACI role |
| 242 |
:expectedresults: |
| 243 |
1. Entry should be added |
| 244 |
2. Operation should succeed |
| 245 |
3. Operation should succeed |
| 246 |
""" |
| 247 |
ACI_BODY = '(targetattr = "*")(version 3.0; acl "ACI NAME"; allow (write)(userdn = "ldap:///{} || ldap:///{}") ;)'.format(USER_DELADD, USER_WITH_ACI_DELADD) |
| 248 |
Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY) |
| 249 |
|
| 250 |
for i in ['Product Development', 'Accounting', 'Human Resources']: |
| 251 |
ou = OrganizationalUnit(topo.standalone, "ou={},{}".format(i, DEFAULT_SUFFIX)) |
| 252 |
ou.create(properties={'ou': i}) |
| 253 |
|
| 254 |
for i in ['Jeff Vedder,ou=Product Development', 'Sam Carter,ou=Accounting', 'Kirsten Vaughan, ou=Human Resources']: |
| 255 |
properties = { |
| 256 |
'uid': i, |
| 257 |
'cn': i, |
| 258 |
'sn': 'user', |
| 259 |
'uidNumber': '1000', |
| 260 |
'gidNumber': '2000', |
| 261 |
'homeDirectory': '/home/' + i, |
| 262 |
'userPassword': PW_DM |
| 263 |
} |
| 264 |
user = UserAccount(topo.standalone, "cn={},{}".format(i, DEFAULT_SUFFIX)) |
| 265 |
user.create(properties=properties) |
| 266 |
|
| 267 |
conn = UserAccount(topo.standalone, USER_DELADD).bind(PW_DM) |
| 268 |
# Allow write access to userdn with multiple DNs |
| 269 |
ua = UserAccount(conn, KIRSTENVAUGHAN) |
| 270 |
ua.add("title", "Architect") |
| 271 |
conn = UserAccount(topo.standalone, USER_WITH_ACI_DELADD).bind(PW_DM) |
| 272 |
# Allow write access to userdn with multiple DNs |
| 273 |
ua = UserAccount(conn, USER_DELADD) |
| 274 |
ua.add("title", "Architect") |
| 275 |
assert ua.get_attr_val('title') |
| 276 |
|
| 277 |
|
| 278 |
def test_allow_write_access_to_target_with_wildcards(topo, aci_of_user, cleanup_tree): |
| 279 |
"""Modify Test 6 Allow write access to target with wildcards |
| 280 |
|
| 281 |
:id: 825fe884-7abf-11e8-8541-8c16451d917b |
| 282 |
:setup: server |
| 283 |
:steps: |
| 284 |
1. Add test entry |
| 285 |
2. Add ACI |
| 286 |
3. User should follow ACI role |
| 287 |
:expectedresults: |
| 288 |
1. Entry should be added |
| 289 |
2. Operation should succeed |
| 290 |
3. Operation should succeed |
| 291 |
""" |
| 292 |
ACI_BODY = '(target = ldap:///{})(targetattr = "*")(version 3.0; acl "ACI NAME"; allow (write) (userdn = "ldap:///anyone") ;)'.format(DEFAULT_SUFFIX) |
| 293 |
Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY) |
| 294 |
|
| 295 |
for i in ['Product Development', 'Accounting', 'Human Resources']: |
| 296 |
ou = OrganizationalUnit(topo.standalone, "ou={},{}".format(i, DEFAULT_SUFFIX)) |
| 297 |
ou.create(properties={'ou': i}) |
| 298 |
|
| 299 |
for i in ['Jeff Vedder,ou=Product Development', 'Sam Carter,ou=Accounting', 'Kirsten Vaughan, ou=Human Resources']: |
| 300 |
properties = { |
| 301 |
'uid': i, |
| 302 |
'cn': i, |
| 303 |
'sn': 'user', |
| 304 |
'uidNumber': '1000', |
| 305 |
'gidNumber': '2000', |
| 306 |
'homeDirectory': '/home/' + i, |
| 307 |
'userPassword': PW_DM |
| 308 |
} |
| 309 |
user = UserAccount(topo.standalone, "cn={},{}".format(i, DEFAULT_SUFFIX)) |
| 310 |
user.create(properties=properties) |
| 311 |
|
| 312 |
conn = UserAccount(topo.standalone, USER_DELADD).bind(PW_DM) |
| 313 |
# Allow write access to target with wildcards |
| 314 |
ua = UserAccount(conn, KIRSTENVAUGHAN) |
| 315 |
ua.add("title", "Architect") |
| 316 |
assert ua.get_attr_val('title') |
| 317 |
conn = UserAccount(topo.standalone, USER_WITH_ACI_DELADD).bind(PW_DM) |
| 318 |
# Allow write access to target with wildcards |
| 319 |
ua = UserAccount(conn, USER_DELADD) |
| 320 |
ua.add("title", "Architect") |
| 321 |
assert ua.get_attr_val('title') |
| 322 |
|
| 323 |
|
| 324 |
def test_allow_write_access_to_userdnattr(topo, aci_of_user, cleanup_tree, request): |
| 325 |
"""Modify Test 7 Allow write access to userdnattr |
| 326 |
|
| 327 |
:id: 86b418f6-7abf-11e8-ae28-8c16451d917b |
| 328 |
:setup: server |
| 329 |
:steps: |
| 330 |
1. Add test entry |
| 331 |
2. Add ACI |
| 332 |
3. User should follow ACI role |
| 333 |
:expectedresults: |
| 334 |
1. Entry should be added |
| 335 |
2. Operation should succeed |
| 336 |
3. Operation should succeed |
| 337 |
""" |
| 338 |
ACI_BODY = '(target = ldap:///{})(targetattr="*")(version 3.0; acl "{}";allow (write) (userdn = "ldap:///anyone"); )'.format(DEFAULT_SUFFIX, request.node.name) |
| 339 |
Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY) |
| 340 |
|
| 341 |
for i in ['Product Development', 'Accounting']: |
| 342 |
ou = OrganizationalUnit(topo.standalone, "ou={},{}".format(i, DEFAULT_SUFFIX)) |
| 343 |
ou.create(properties={'ou': i}) |
| 344 |
|
| 345 |
for i in ['Jeff Vedder,ou=Product Development', 'Sam Carter,ou=Accounting']: |
| 346 |
properties = { |
| 347 |
'uid': i, |
| 348 |
'cn': i, |
| 349 |
'sn': 'user', |
| 350 |
'uidNumber': '1000', |
| 351 |
'gidNumber': '2000', |
| 352 |
'homeDirectory': '/home/' + i, |
| 353 |
'userPassword': PW_DM |
| 354 |
} |
| 355 |
user = UserAccount(topo.standalone, "cn={},{}".format(i, DEFAULT_SUFFIX)) |
| 356 |
user.create(properties=properties) |
| 357 |
|
| 358 |
UserAccount(topo.standalone, USER_WITH_ACI_DELADD).add('manager', USER_WITH_ACI_DELADD) |
| 359 |
conn = UserAccount(topo.standalone, USER_WITH_ACI_DELADD).bind(PW_DM) |
| 360 |
# Allow write access to userdnattr |
| 361 |
ua = UserAccount(conn, USER_DELADD) |
| 362 |
ua.add('uid', 'scoobie') |
| 363 |
assert ua.get_attr_val('uid') |
| 364 |
ua.add('uid', 'jvedder') |
| 365 |
assert ua.get_attr_val('uid') |
| 366 |
|
| 367 |
|
| 368 |
def test_allow_selfwrite_access_to_anyone(topo, aci_of_user, cleanup_tree): |
| 369 |
"""Modify Test 8 Allow selfwrite access to anyone |
| 370 |
|
| 371 |
:id: 8b3becf0-7abf-11e8-ac34-8c16451d917b |
| 372 |
:setup: server |
| 373 |
:steps: |
| 374 |
1. Add test entry |
| 375 |
2. Add ACI |
| 376 |
3. User should follow ACI role |
| 377 |
:expectedresults: |
| 378 |
1. Entry should be added |
| 379 |
2. Operation should succeed |
| 380 |
3. Operation should succeed |
| 381 |
""" |
| 382 |
groups = Groups(topo.standalone, DEFAULT_SUFFIX) |
| 383 |
group = groups.create(properties={"cn": "group1", |
| 384 |
"description": "testgroup"}) |
| 385 |
|
| 386 |
ACI_BODY = '(target = ldap:///cn=group1,ou=Groups,{})(targetattr = "member")(version 3.0; acl "ACI NAME"; allow (selfwrite) (userdn = "ldap:///anyone") ;)'.format(DEFAULT_SUFFIX) |
| 387 |
Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY) |
| 388 |
|
| 389 |
ou = OrganizationalUnit(topo.standalone, "ou=Product Development,{}".format(DEFAULT_SUFFIX)) |
| 390 |
ou.create(properties={'ou': 'Product Development'}) |
| 391 |
|
| 392 |
properties = { |
| 393 |
'uid': 'Jeff Vedder', |
| 394 |
'cn': 'Jeff Vedder', |
| 395 |
'sn': 'user', |
| 396 |
'uidNumber': '1000', |
| 397 |
'gidNumber': '2000', |
| 398 |
'homeDirectory': '/home/' + 'JeffVedder', |
| 399 |
'userPassword': PW_DM |
| 400 |
} |
| 401 |
user = UserAccount(topo.standalone, "cn=Jeff Vedder,ou=Product Development,{}".format(DEFAULT_SUFFIX)) |
| 402 |
user.create(properties=properties) |
| 403 |
|
| 404 |
conn = UserAccount(topo.standalone, USER_DELADD).bind(PW_DM) |
| 405 |
# Allow selfwrite access to anyone |
| 406 |
groups = Groups(conn, DEFAULT_SUFFIX) |
| 407 |
groups.list()[1].add_member(USER_DELADD) |
| 408 |
|
| 409 |
|
| 410 |
def test_uniquemember_should_also_be_the_owner(topo, aci_of_user): |
| 411 |
"""Modify Test 10 groupdnattr = \"ldap:///$BASEDN?owner\" if owner is a group, group's |
| 412 |
uniquemember should also be the owner |
| 413 |
|
| 414 |
:id: 9456b2d4-7abf-11e8-829d-8c16451d917b |
| 415 |
:setup: server |
| 416 |
:steps: |
| 417 |
1. Add test entry |
| 418 |
2. Add ACI |
| 419 |
3. User should follow ACI role |
| 420 |
:expectedresults: |
| 421 |
1. Entry should be added |
| 422 |
2. Operation should succeed |
| 423 |
3. Operation should succeed |
| 424 |
""" |
| 425 |
for i in ['ACLGroupTest']: |
| 426 |
ou = OrganizationalUnit(topo.standalone, "ou={},{}".format(i, DEFAULT_SUFFIX)) |
| 427 |
ou.create(properties={'ou': i}) |
| 428 |
|
| 429 |
ou = OrganizationalUnit(topo.standalone, "ou=ACLDevelopment,{}".format(DEFAULT_SUFFIX)) |
| 430 |
ou.create(properties={'ou': 'ACLDevelopment'}) |
| 431 |
ou.set('aci','(targetattr="*")(version 3.0; acl "groupdnattr acl"; ' |
| 432 |
'allow (all)groupdnattr = "ldap:///{}?owner";)'.format(DEFAULT_SUFFIX)) |
| 433 |
|
| 434 |
grp = UniqueGroup(topo.standalone, "uid=anuj,ou=ACLDevelopment, {}".format(DEFAULT_SUFFIX)) |
| 435 |
user_props = ( |
| 436 |
{'sn': 'Borah', |
| 437 |
'cn': 'Anuj', |
| 438 |
'objectclass': ['top', 'person', 'organizationalPerson', 'inetOrgPerson', 'groupofUniquenames'], |
| 439 |
'userpassword': PW_DM, |
| 440 |
'givenname': 'Anuj', |
| 441 |
'ou': ['ACLDevelopment', 'People'], |
| 442 |
'roomnumber': '123', |
| 443 |
'uniquemember': 'cn=mandatory member' |
| 444 |
} |
| 445 |
) |
| 446 |
grp.create(properties=user_props) |
| 447 |
|
| 448 |
grp = UniqueGroup(topo.standalone, "uid=2ishani,ou=ACLDevelopment, {}".format(DEFAULT_SUFFIX)) |
| 449 |
user_props = ( |
| 450 |
{'sn': 'Borah', |
| 451 |
'cn': '2ishani', |
| 452 |
'objectclass': ['top', 'person','organizationalPerson', 'inetOrgPerson', 'groupofUniquenames'], |
| 453 |
'userpassword': PW_DM, |
| 454 |
'givenname': '2ishani', |
| 455 |
'ou': ['ACLDevelopment', 'People'], |
| 456 |
'roomnumber': '1234', |
| 457 |
'uniquemember': 'cn=mandatory member', "owner": "cn=group4, ou=ACLGroupTest, {}".format(DEFAULT_SUFFIX) |
| 458 |
} |
| 459 |
) |
| 460 |
grp.create(properties=user_props) |
| 461 |
|
| 462 |
grp = UniqueGroup(topo.standalone, 'cn=group1,ou=ACLGroupTest,'+DEFAULT_SUFFIX) |
| 463 |
grp.create(properties={'cn': 'group1', |
| 464 |
'ou': 'groups'}) |
| 465 |
grp.set('uniquemember', ["cn=group2, ou=ACLGroupTest, {}".format(DEFAULT_SUFFIX), |
| 466 |
"cn=group3, ou=ACLGroupTest, {}".format(DEFAULT_SUFFIX)]) |
| 467 |
|
| 468 |
grp = UniqueGroup(topo.standalone, 'cn=group3,ou=ACLGroupTest,' + DEFAULT_SUFFIX) |
| 469 |
grp.create(properties={'cn': 'group3', |
| 470 |
'ou': 'groups'}) |
| 471 |
grp.set('uniquemember', ["cn=group4, ou=ACLGroupTest, {}".format(DEFAULT_SUFFIX)]) |
| 472 |
|
| 473 |
grp = UniqueGroup(topo.standalone, 'cn=group4,ou=ACLGroupTest,' + DEFAULT_SUFFIX) |
| 474 |
grp.create(properties={ |
| 475 |
'cn': 'group4', |
| 476 |
'ou': 'groups'}) |
| 477 |
grp.set('uniquemember', ["uid=anuj, ou=ACLDevelopment, {}".format(DEFAULT_SUFFIX)]) |
| 478 |
|
| 479 |
#uniquemember should also be the owner |
| 480 |
conn = UserAccount(topo.standalone, "uid=anuj,ou=ACLDevelopment, {}".format(DEFAULT_SUFFIX)).bind(PW_DM) |
| 481 |
ua = UserAccount(conn, "uid=2ishani, ou=ACLDevelopment, {}".format(DEFAULT_SUFFIX)) |
| 482 |
ua.add('roomnumber', '9999') |
| 483 |
assert ua.get_attr_val('roomnumber') |
| 484 |
|
| 485 |
for DN in ["cn=group4,ou=ACLGroupTest,{}".format(DEFAULT_SUFFIX), |
| 486 |
"cn=group3,ou=ACLGroupTest,{}".format(DEFAULT_SUFFIX), |
| 487 |
"cn=group1,ou=ACLGroupTest,{}".format(DEFAULT_SUFFIX), |
| 488 |
"uid=2ishani,ou=ACLDevelopment,{}".format(DEFAULT_SUFFIX), |
| 489 |
"uid=anuj,ou=ACLDevelopment,{}".format(DEFAULT_SUFFIX), "ou=ACLDevelopment,{}".format(DEFAULT_SUFFIX), |
| 490 |
"ou=ACLGroupTest, {}".format(DEFAULT_SUFFIX)]: |
| 491 |
UserAccount(topo.standalone, DN).delete() |
| 492 |
|
| 493 |
|
| 494 |
def test_aci_with_both_allow_and_deny(topo, aci_of_user, cleanup_tree): |
| 495 |
"""Modify Test 12 aci with both allow and deny |
| 496 |
|
| 497 |
:id: 9dcfe902-7abf-11e8-86dc-8c16451d917b |
| 498 |
:setup: server |
| 499 |
:steps: |
| 500 |
1. Add test entry |
| 501 |
2. Add ACI |
| 502 |
3. User should follow ACI role |
| 503 |
:expectedresults: |
| 504 |
1. Entry should be added |
| 505 |
2. Operation should succeed |
| 506 |
3. Operation should succeed |
| 507 |
""" |
| 508 |
ACI_BODY = '(targetattr = "*")(version 3.0; acl "ACI NAME"; deny (read, search)userdn = "ldap:///{}"; allow (all) userdn = "ldap:///{}" ;)'.format(USER_WITH_ACI_DELADD, USER_DELADD) |
| 509 |
Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY) |
| 510 |
|
| 511 |
for i in ['Product Development', 'Accounting']: |
| 512 |
ou = OrganizationalUnit(topo.standalone, "ou={},{}".format(i, DEFAULT_SUFFIX)) |
| 513 |
ou.create(properties={'ou': i}) |
| 514 |
|
| 515 |
for i in ['Jeff Vedder,ou=Product Development', 'Sam Carter,ou=Accounting']: |
| 516 |
properties = { |
| 517 |
'uid': i, |
| 518 |
'cn': i, |
| 519 |
'sn': 'user', |
| 520 |
'uidNumber': '1000', |
| 521 |
'gidNumber': '2000', |
| 522 |
'homeDirectory': '/home/' + i, |
| 523 |
'userPassword': PW_DM |
| 524 |
} |
| 525 |
user = UserAccount(topo.standalone, "cn={},{}".format(i, DEFAULT_SUFFIX)) |
| 526 |
user.create(properties=properties) |
| 527 |
|
| 528 |
conn = UserAccount(topo.standalone, USER_DELADD).bind(PW_DM) |
| 529 |
# aci with both allow and deny, testing allow |
| 530 |
assert UserAccount(conn, USER_WITH_ACI_DELADD).get_attr_val('uid') |
| 531 |
conn = UserAccount(topo.standalone, USER_WITH_ACI_DELADD).bind(PW_DM) |
| 532 |
# aci with both allow and deny, testing deny |
| 533 |
assert len(UserAccount(conn, USER_WITH_ACI_DELADD).get_attr_val('uid')) == 0 |
| 534 |
|
| 535 |
|
| 536 |
def test_allow_owner_to_modify_entry(topo, aci_of_user, cleanup_tree, request): |
| 537 |
"""Modify Test 14 allow userdnattr = owner to modify entry |
| 538 |
|
| 539 |
:id: aa302090-7abf-11e8-811a-8c16451d917b |
| 540 |
:setup: server |
| 541 |
:steps: |
| 542 |
1. Add test entry |
| 543 |
2. Add ACI |
| 544 |
3. User should follow ACI role |
| 545 |
:expectedresults: |
| 546 |
1. Entry should be added |
| 547 |
2. Operation should succeed |
| 548 |
3. Operation should succeed |
| 549 |
""" |
| 550 |
grp = UniqueGroup(topo.standalone, 'cn=intranet,' + DEFAULT_SUFFIX) |
| 551 |
grp.create(properties={ |
| 552 |
'cn': 'intranet', |
| 553 |
'ou': 'groups'}) |
| 554 |
grp.set('owner', USER_WITH_ACI_DELADD) |
| 555 |
|
| 556 |
ACI_BODY = '(target ="ldap:///cn=intranet, {}") (targetattr ="*")(targetfilter ="(objectclass=groupOfUniqueNames)") (version 3.0;acl "{}";allow(read, write, delete, search, compare, add) (userdnattr = "owner");)'.format(DEFAULT_SUFFIX, request.node.name) |
| 557 |
Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY) |
| 558 |
|
| 559 |
for i in ['Product Development', 'Accounting']: |
| 560 |
ou = OrganizationalUnit(topo.standalone, "ou={},{}".format(i, DEFAULT_SUFFIX)) |
| 561 |
ou.create(properties={'ou': i}) |
| 562 |
for i in ['Jeff Vedder,ou=Product Development', 'Sam Carter,ou=Accounting']: |
| 563 |
properties = { |
| 564 |
'uid': i, |
| 565 |
'cn': i, |
| 566 |
'sn': 'user', |
| 567 |
'uidNumber': '1000', |
| 568 |
'gidNumber': '2000', |
| 569 |
'homeDirectory': '/home/' + i, |
| 570 |
'userPassword': PW_DM |
| 571 |
} |
| 572 |
user = UserAccount(topo.standalone, "cn={},{}".format(i, DEFAULT_SUFFIX)) |
| 573 |
user.create(properties=properties) |
| 574 |
|
| 575 |
conn = UserAccount(topo.standalone, USER_WITH_ACI_DELADD).bind(PW_DM) |
| 576 |
# allow userdnattr = owner to modify entry |
| 577 |
ua = UserAccount(conn, 'cn=intranet,dc=example,dc=com') |
| 578 |
ua.set('uniquemember', "cn=Andy Walker, ou=Accounting,dc=example,dc=com") |
| 579 |
assert ua.get_attr_val('uniquemember') |
| 580 |
|
| 581 |
|
| 582 |
if __name__ == "__main__": |
| 583 |
CURRENT_FILE = os.path.realpath(__file__) |
| 584 |
pytest.main("-s -v %s" % CURRENT_FILE) |