| 1 |
# --- BEGIN COPYRIGHT BLOCK --- |
| 2 |
# Copyright (C) 2023 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, re |
| 10 |
from lib389.tasks import * |
| 11 |
from lib389.utils import * |
| 12 |
from ldap import SCOPE_SUBTREE, ALREADY_EXISTS |
| 13 |
|
| 14 |
from lib389._constants import DEFAULT_SUFFIX, PW_DM, PLUGIN_MEMBER_OF |
| 15 |
from test389.topologies import topology_st as topo |
| 16 |
from lib389.plugins import MemberOfPlugin |
| 17 |
|
| 18 |
from lib389.schema import Schema |
| 19 |
from lib389.idm.user import UserAccount, UserAccounts |
| 20 |
from lib389.idm.account import Accounts |
| 21 |
from lib389.idm.account import Anonymous |
| 22 |
|
| 23 |
INCHAIN_OID = "1.2.840.113556.1.4.1941" |
| 24 |
|
| 25 |
pytestmark = pytest.mark.tier0 |
| 26 |
|
| 27 |
@pytest.fixture(scope="function") |
| 28 |
def provision_inchain(topo): |
| 29 |
"""fixture that provision a hierachical tree |
| 30 |
with 'manager' membership relation |
| 31 |
|
| 32 |
""" |
| 33 |
# hierarchy of the entries is |
| 34 |
# 3_1 |
| 35 |
# |__ 2_1 |
| 36 |
# | |__ 1_1 |
| 37 |
# | |__ 100 |
| 38 |
# | | |__ 101 |
| 39 |
# | | |__ 102 |
| 40 |
# | | |__ 103 |
| 41 |
# | | |__ 104 |
| 42 |
# | | |
| 43 |
# | |__ 1_2 |
| 44 |
# | | |__ 200 |
| 45 |
# | | |__ 201 |
| 46 |
# | | |__ 202 |
| 47 |
# | | |__ 203 |
| 48 |
# | | |__ 204 |
| 49 |
# | |
| 50 |
# |__ 2_2 |
| 51 |
# |__ 1_3 |
| 52 |
# | |__ 300 |
| 53 |
# | |__ 301 |
| 54 |
# | |__ 302 |
| 55 |
# | |__ 303 |
| 56 |
# | |__ 304 |
| 57 |
# | |
| 58 |
# |__ 1_4 |
| 59 |
# |__ 400 |
| 60 |
# |__ 401 |
| 61 |
# |__ 402 |
| 62 |
# |__ 403 |
| 63 |
# |__ 404 |
| 64 |
# |
| 65 |
user = UserAccounts(topo.standalone, DEFAULT_SUFFIX) |
| 66 |
try: |
| 67 |
manager_lvl_3_1 = user.create_test_user(uid=31) |
| 68 |
except ALREADY_EXISTS: |
| 69 |
manager_lvl_3_1 = None |
| 70 |
pass |
| 71 |
|
| 72 |
try: |
| 73 |
manager_lvl_2_1 = user.create_test_user(uid=21) |
| 74 |
if manager_lvl_3_1: |
| 75 |
manager_lvl_2_1.set("manager", manager_lvl_3_1.dn) |
| 76 |
else: |
| 77 |
manager_lvl_2_1.set("manager", "uid=test_user_31,ou=People,%s" % DEFAULT_SUFFIX) |
| 78 |
except ALREADY_EXISTS: |
| 79 |
manager_lvl_2_1 = None |
| 80 |
pass |
| 81 |
|
| 82 |
try: |
| 83 |
manager_lvl_2_2 = user.create_test_user(uid=22) |
| 84 |
if manager_lvl_3_1: |
| 85 |
manager_lvl_2_2.set("manager", manager_lvl_3_1.dn) |
| 86 |
else: |
| 87 |
manager_lvl_2_2.set("manager", "uid=test_user_31,ou=People,%s" % DEFAULT_SUFFIX) |
| 88 |
except ALREADY_EXISTS: |
| 89 |
manager_lvl_2_2 = None |
| 90 |
pass |
| 91 |
|
| 92 |
try: |
| 93 |
manager_lvl_1_1 = user.create_test_user(uid=11) |
| 94 |
if manager_lvl_2_1: |
| 95 |
manager_lvl_1_1.set("manager", manager_lvl_2_1.dn) |
| 96 |
else: |
| 97 |
manager_lvl_1_1.set("manager", "uid=test_user_21,ou=People,%s" % DEFAULT_SUFFIX) |
| 98 |
except ALREADY_EXISTS: |
| 99 |
manager_lvl_1_1 = None |
| 100 |
pass |
| 101 |
|
| 102 |
try: |
| 103 |
manager_lvl_1_2 = user.create_test_user(uid=12) |
| 104 |
if manager_lvl_2_1: |
| 105 |
manager_lvl_1_2.set("manager", manager_lvl_2_1.dn) |
| 106 |
else: |
| 107 |
manager_lvl_1_2.set("manager", "uid=test_user_21,ou=People,%s" % DEFAULT_SUFFIX) |
| 108 |
except ALREADY_EXISTS: |
| 109 |
manager_lvl_1_2 = None |
| 110 |
pass |
| 111 |
|
| 112 |
try: |
| 113 |
manager_lvl_1_3 = user.create_test_user(uid=13) |
| 114 |
if manager_lvl_2_2: |
| 115 |
manager_lvl_1_3.set("manager", manager_lvl_2_2.dn) |
| 116 |
else: |
| 117 |
manager_lvl_1_3.set("manager", "uid=test_user_22,ou=People,%s" % DEFAULT_SUFFIX) |
| 118 |
except ALREADY_EXISTS: |
| 119 |
manager_lvl_1_3 = None |
| 120 |
pass |
| 121 |
|
| 122 |
try: |
| 123 |
manager_lvl_1_4 = user.create_test_user(uid=14) |
| 124 |
if manager_lvl_2_2: |
| 125 |
manager_lvl_1_4.set("manager", manager_lvl_2_2.dn) |
| 126 |
else: |
| 127 |
manager_lvl_1_4.set("manager", "uid=test_user_22,ou=People,%s" % DEFAULT_SUFFIX) |
| 128 |
except ALREADY_EXISTS: |
| 129 |
manager_lvl_1_4 = None |
| 130 |
pass |
| 131 |
|
| 132 |
for i in range(100, 105): |
| 133 |
try: |
| 134 |
user1 = user.create_test_user(uid=i) |
| 135 |
if manager_lvl_1_1: |
| 136 |
user1.set("manager", manager_lvl_1_1.dn) |
| 137 |
else: |
| 138 |
user1.set("manager", "uid=test_user_11,ou=People,%s" % DEFAULT_SUFFIX) |
| 139 |
except ALREADY_EXISTS: |
| 140 |
pass |
| 141 |
|
| 142 |
for i in range(200, 205): |
| 143 |
try: |
| 144 |
user1 = user.create_test_user(uid=i) |
| 145 |
if manager_lvl_1_2: |
| 146 |
user1.set("manager", manager_lvl_1_2.dn) |
| 147 |
else: |
| 148 |
user1.set("manager", "uid=test_user_12,ou=People,%s" % DEFAULT_SUFFIX) |
| 149 |
except ALREADY_EXISTS: |
| 150 |
pass |
| 151 |
|
| 152 |
for i in range(300, 305): |
| 153 |
try: |
| 154 |
user1 = user.create_test_user(uid=i) |
| 155 |
if manager_lvl_1_3: |
| 156 |
user1.set("manager", manager_lvl_1_3.dn) |
| 157 |
else: |
| 158 |
user1.set("manager", "uid=test_user_13,ou=People,%s" % DEFAULT_SUFFIX) |
| 159 |
except ALREADY_EXISTS: |
| 160 |
pass |
| 161 |
|
| 162 |
for i in range(400, 405): |
| 163 |
try: |
| 164 |
user1 = user.create_test_user(uid=i) |
| 165 |
if manager_lvl_1_4: |
| 166 |
user1.set("manager", manager_lvl_1_4.dn) |
| 167 |
else: |
| 168 |
user1.set("manager", "uid=test_user_14,ou=People,%s" % DEFAULT_SUFFIX) |
| 169 |
except ALREADY_EXISTS: |
| 170 |
pass |
| 171 |
|
| 172 |
def check_subordinates(topo, uid, expected): |
| 173 |
"""Test filter can search attributes |
| 174 |
|
| 175 |
:id: 39640b4b-0e64-44a4-8611-191aae412370 |
| 176 |
:setup: Standalone instance |
| 177 |
:steps: |
| 178 |
1. Add test entry |
| 179 |
2. make search |
| 180 |
:expectedresults: |
| 181 |
1. Entry should be added |
| 182 |
2. Operation should succeed |
| 183 |
""" |
| 184 |
manager = "uid=%s,ou=People,%s" % (uid, DEFAULT_SUFFIX) |
| 185 |
topo.standalone.log.info("Subordinate of manager %s" % manager) |
| 186 |
|
| 187 |
subordinates = topo.standalone.search_s(DEFAULT_SUFFIX, SCOPE_SUBTREE, "(manager:%s:=%s)" % (INCHAIN_OID, manager)) |
| 188 |
found = [] |
| 189 |
for sub in subordinates: |
| 190 |
p =re.compile("uid=(.*),ou.*$") |
| 191 |
res = p.search(sub.dn) |
| 192 |
found.append(res.group(1)) |
| 193 |
topo.standalone.log.info("Subordinate found : %s" % res.group(1)) |
| 194 |
|
| 195 |
|
| 196 |
for sub in expected: |
| 197 |
assert sub in found |
| 198 |
|
| 199 |
for sub in found: |
| 200 |
assert sub in expected |
| 201 |
|
| 202 |
|
| 203 |
def test_manager_lvl_1(topo, provision_inchain): |
| 204 |
"""Test that it succeeds to retrieve the subordinate |
| 205 |
of level 1 manager |
| 206 |
|
| 207 |
:id: 193040ef-861e-41bd-84c7-c07a53a74e18 |
| 208 |
:setup: Standalone instance |
| 209 |
:steps: |
| 210 |
1. fixture provision a hierachical tree |
| 211 |
2. Check subordinates of 1_4 entry |
| 212 |
3. Check subordinates of 1_3 entry |
| 213 |
4. Check subordinates of 1_2 entry |
| 214 |
5. Check subordinates of 1_1 entry |
| 215 |
:expectedresults: |
| 216 |
1. provisioning done |
| 217 |
2. found subordinates should match expected ones |
| 218 |
3. found subordinates should match expected ones |
| 219 |
4. found subordinates should match expected ones |
| 220 |
5. found subordinates should match expected ones |
| 221 |
""" |
| 222 |
|
| 223 |
# Check subordinates of user_14 |
| 224 |
# |__ 1_4 |
| 225 |
# |__ 400 |
| 226 |
# |__ 401 |
| 227 |
# |__ 402 |
| 228 |
# |__ 403 |
| 229 |
# |__ 404 |
| 230 |
uid = "test_user_14" |
| 231 |
topo.standalone.log.info("Subordinate of uid=%s" % uid) |
| 232 |
expected = [] |
| 233 |
for i in range(400, 405): |
| 234 |
uid_expected = "test_user_%s" % i |
| 235 |
expected.append(uid_expected) |
| 236 |
topo.standalone.log.info("Subordinate expected: %s" % uid_expected) |
| 237 |
|
| 238 |
check_subordinates(topo, uid, expected) |
| 239 |
|
| 240 |
# Check subordinates of user_13 |
| 241 |
# |__ 1_3 |
| 242 |
# | |__ 300 |
| 243 |
# | |__ 301 |
| 244 |
# | |__ 302 |
| 245 |
# | |__ 303 |
| 246 |
# | |__ 304 |
| 247 |
uid = "test_user_13" |
| 248 |
topo.standalone.log.info("Subordinate of uid=%s" % uid) |
| 249 |
expected = [] |
| 250 |
for i in range(300, 305): |
| 251 |
uid_expected = "test_user_%s" % i |
| 252 |
expected.append(uid_expected) |
| 253 |
topo.standalone.log.info("Subordinate expected: %s" % uid_expected) |
| 254 |
|
| 255 |
check_subordinates(topo, uid, expected) |
| 256 |
|
| 257 |
# Check subordinates of user_12 |
| 258 |
#| |__ 1_2 |
| 259 |
#| | |__ 200 |
| 260 |
#| | |__ 201 |
| 261 |
#| | |__ 202 |
| 262 |
#| | |__ 203 |
| 263 |
#| | |__ 204 |
| 264 |
|
| 265 |
uid = "test_user_12" |
| 266 |
topo.standalone.log.info("Subordinate of uid=%s" % uid) |
| 267 |
expected = [] |
| 268 |
for i in range(200, 205): |
| 269 |
uid_expected = "test_user_%s" % i |
| 270 |
expected.append(uid_expected) |
| 271 |
topo.standalone.log.info("Subordinate expected: %s" % uid_expected) |
| 272 |
|
| 273 |
check_subordinates(topo, uid, expected) |
| 274 |
|
| 275 |
# Check subordinates of user_11 |
| 276 |
#| |__ 1_1 |
| 277 |
#| | |__ 100 |
| 278 |
#| | |__ 101 |
| 279 |
#| | |__ 102 |
| 280 |
#| | |__ 103 |
| 281 |
#| | |__ 104 |
| 282 |
uid = "test_user_11" |
| 283 |
topo.standalone.log.info("Subordinate of uid=%s" % uid) |
| 284 |
expected = [] |
| 285 |
for i in range(100, 105): |
| 286 |
uid_expected = "test_user_%s" % i |
| 287 |
expected.append(uid_expected) |
| 288 |
topo.standalone.log.info("Subordinate expected: %s" % uid_expected) |
| 289 |
|
| 290 |
check_subordinates(topo, uid, expected) |
| 291 |
|
| 292 |
def test_manager_lvl_2(topo, provision_inchain): |
| 293 |
"""Test that it succeeds to retrieve the subordinate |
| 294 |
of level 2 manager |
| 295 |
|
| 296 |
:id: d0c98211-3b90-4764-913d-f55ea5479029 |
| 297 |
:setup: Standalone instance |
| 298 |
:steps: |
| 299 |
1. fixture provision a hierachical tree |
| 300 |
2. Check subordinates of 2_1 entry |
| 301 |
3. Check subordinates of 2_2 entry |
| 302 |
:expectedresults: |
| 303 |
1. provisioning done |
| 304 |
2. found subordinates should match expected ones |
| 305 |
3. found subordinates should match expected ones |
| 306 |
""" |
| 307 |
|
| 308 |
# Check subordinates of user_22 |
| 309 |
#| |
| 310 |
#|__ 2_2 |
| 311 |
# |__ 1_3 |
| 312 |
# ... |
| 313 |
# |__ 1_4 |
| 314 |
# ... |
| 315 |
uid = "test_user_22" |
| 316 |
topo.standalone.log.info("Subordinate of uid=%s" % uid) |
| 317 |
expected = [] |
| 318 |
|
| 319 |
# it contains user_14 and below |
| 320 |
# |__ 1_4 |
| 321 |
# |__ 400 |
| 322 |
# |__ 401 |
| 323 |
# |__ 402 |
| 324 |
# |__ 403 |
| 325 |
# |__ 404 |
| 326 |
uid_expected = "test_user_14" |
| 327 |
topo.standalone.log.info("Subordinate expected: %s" % uid_expected) |
| 328 |
expected.append(uid_expected) |
| 329 |
for i in range(400, 405): |
| 330 |
uid_expected = "test_user_%s" % i |
| 331 |
expected.append(uid_expected) |
| 332 |
topo.standalone.log.info("Subordinate expected: %s" % uid_expected) |
| 333 |
|
| 334 |
# it contains user_13 and below |
| 335 |
#| |
| 336 |
#|__ 2_2 |
| 337 |
# |__ 1_3 |
| 338 |
# | |__ 300 |
| 339 |
# | |__ 301 |
| 340 |
# | |__ 302 |
| 341 |
# | |__ 303 |
| 342 |
# | |__ 304 |
| 343 |
# | |
| 344 |
uid_expected = "test_user_13" |
| 345 |
topo.standalone.log.info("Subordinate expected: %s" % uid_expected) |
| 346 |
expected.append(uid_expected) |
| 347 |
for i in range(300, 305): |
| 348 |
uid_expected = "test_user_%s" % i |
| 349 |
expected.append(uid_expected) |
| 350 |
topo.standalone.log.info("Subordinate expected: %s" % uid_expected) |
| 351 |
|
| 352 |
check_subordinates(topo, uid, expected) |
| 353 |
|
| 354 |
# Check subordinates of user_21 |
| 355 |
#|__ 2_1 |
| 356 |
#| |__ 1_1 |
| 357 |
#| | |
| 358 |
#| ... |
| 359 |
#| | |
| 360 |
#| |__ 1_2 |
| 361 |
#| ... |
| 362 |
uid = "test_user_21" |
| 363 |
topo.standalone.log.info("Subordinate of uid=%s" % uid) |
| 364 |
expected = [] |
| 365 |
|
| 366 |
# it contains user_12 and below |
| 367 |
#|__ 2_1 |
| 368 |
#| ... |
| 369 |
#| |__ 1_2 |
| 370 |
#| | |__ 200 |
| 371 |
#| | |__ 201 |
| 372 |
#| | |__ 202 |
| 373 |
#| | |__ 203 |
| 374 |
#| | |__ 204 |
| 375 |
|
| 376 |
uid_expected = "test_user_12" |
| 377 |
topo.standalone.log.info("Subordinate expected: %s" % uid_expected) |
| 378 |
expected.append(uid_expected) |
| 379 |
for i in range(200, 205): |
| 380 |
uid_expected = "test_user_%s" % i |
| 381 |
expected.append(uid_expected) |
| 382 |
topo.standalone.log.info("Subordinate expected: %s" % uid_expected) |
| 383 |
|
| 384 |
# it contains user_11 and below |
| 385 |
#|__ 2_1 |
| 386 |
#| |__ 1_1 |
| 387 |
#| | |__ 100 |
| 388 |
#| | |__ 101 |
| 389 |
#| | |__ 102 |
| 390 |
#| | |__ 103 |
| 391 |
#| | |__ 104 |
| 392 |
#| | |
| 393 |
#| ... |
| 394 |
uid_expected = "test_user_11" |
| 395 |
topo.standalone.log.info("Subordinate expected: %s" % uid_expected) |
| 396 |
expected.append(uid_expected) |
| 397 |
for i in range(100, 105): |
| 398 |
uid_expected = "test_user_%s" % i |
| 399 |
expected.append(uid_expected) |
| 400 |
topo.standalone.log.info("Subordinate expected: %s" % uid_expected) |
| 401 |
|
| 402 |
check_subordinates(topo, uid, expected) |
| 403 |
|
| 404 |
def test_manager_lvl_3(topo, provision_inchain): |
| 405 |
"""Test that it succeeds to retrieve the subordinate |
| 406 |
of level 3 manager |
| 407 |
|
| 408 |
:id: d3708a39-7901-4c88-b4af-272aed2aa846 |
| 409 |
:setup: Standalone instance |
| 410 |
:steps: |
| 411 |
1. fixture provision a hierachical tree |
| 412 |
2. Check subordinates of 3_1 entry |
| 413 |
:expectedresults: |
| 414 |
1. provisioning done |
| 415 |
2. found subordinates should match expected ones |
| 416 |
""" |
| 417 |
|
| 418 |
# Check subordinates of user_31 |
| 419 |
# 3_1 |
| 420 |
#|__ 2_1 |
| 421 |
#| |__ 1_1 |
| 422 |
#| | |__ 100 |
| 423 |
#| | |__ 101 |
| 424 |
#| | |__ 102 |
| 425 |
#| | |__ 103 |
| 426 |
#| | |__ 104 |
| 427 |
#| | |
| 428 |
#| |__ 1_2 |
| 429 |
#| | |__ 200 |
| 430 |
#| | |__ 201 |
| 431 |
#| | |__ 202 |
| 432 |
#| | |__ 203 |
| 433 |
#| | |__ 204 |
| 434 |
#| |
| 435 |
#|__ 2_2 |
| 436 |
# |__ 1_3 |
| 437 |
# | |__ 300 |
| 438 |
# | |__ 301 |
| 439 |
# | |__ 302 |
| 440 |
# | |__ 303 |
| 441 |
# | |__ 304 |
| 442 |
# | |
| 443 |
# |__ 1_4 |
| 444 |
# |__ 400 |
| 445 |
# |__ 401 |
| 446 |
# |__ 402 |
| 447 |
# |__ 403 |
| 448 |
# |__ 404 |
| 449 |
uid = "test_user_31" |
| 450 |
topo.standalone.log.info("Subordinate of uid=%s" % uid) |
| 451 |
expected = [] |
| 452 |
|
| 453 |
# it contains user_22 and below |
| 454 |
uid_expected = "test_user_22" |
| 455 |
topo.standalone.log.info("Subordinate expected: %s" % uid_expected) |
| 456 |
expected.append(uid_expected) |
| 457 |
|
| 458 |
# it contains user_14 and below |
| 459 |
uid_expected = "test_user_14" |
| 460 |
topo.standalone.log.info("Subordinate expected: %s" % uid_expected) |
| 461 |
expected.append(uid_expected) |
| 462 |
for i in range(400, 405): |
| 463 |
uid_expected = "test_user_%s" % i |
| 464 |
expected.append(uid_expected) |
| 465 |
topo.standalone.log.info("Subordinate expected: %s" % uid_expected) |
| 466 |
|
| 467 |
# it contains user_13 and below |
| 468 |
uid_expected = "test_user_13" |
| 469 |
topo.standalone.log.info("Subordinate expected: %s" % uid_expected) |
| 470 |
expected.append(uid_expected) |
| 471 |
for i in range(300, 305): |
| 472 |
uid_expected = "test_user_%s" % i |
| 473 |
expected.append(uid_expected) |
| 474 |
topo.standalone.log.info("Subordinate expected: %s" % uid_expected) |
| 475 |
|
| 476 |
|
| 477 |
# it contains user_21 and below |
| 478 |
uid_expected = "test_user_21" |
| 479 |
topo.standalone.log.info("Subordinate expected: %s" % uid_expected) |
| 480 |
expected.append(uid_expected) |
| 481 |
|
| 482 |
# it contains user_12 and below |
| 483 |
uid_expected = "test_user_12" |
| 484 |
topo.standalone.log.info("Subordinate expected: %s" % uid_expected) |
| 485 |
expected.append(uid_expected) |
| 486 |
for i in range(200, 205): |
| 487 |
uid_expected = "test_user_%s" % i |
| 488 |
expected.append(uid_expected) |
| 489 |
topo.standalone.log.info("Subordinate expected: %s" % uid_expected) |
| 490 |
|
| 491 |
# it contains user_11 and below |
| 492 |
uid_expected = "test_user_11" |
| 493 |
topo.standalone.log.info("Subordinate expected: %s" % uid_expected) |
| 494 |
expected.append(uid_expected) |
| 495 |
for i in range(100, 105): |
| 496 |
uid_expected = "test_user_%s" % i |
| 497 |
expected.append(uid_expected) |
| 498 |
topo.standalone.log.info("Subordinate expected: %s" % uid_expected) |
| 499 |
|
| 500 |
check_subordinates(topo, uid, expected) |
| 501 |
|
| 502 |
def test_recompute_del(topo, provision_inchain): |
| 503 |
"""Test that if we delete a subordinate |
| 504 |
the subordinate list is correctly updated |
| 505 |
|
| 506 |
:id: 6865876d-64b5-41a2-ae6e-4453aae5caab |
| 507 |
:setup: Standalone instance |
| 508 |
:steps: |
| 509 |
1. fixture provision a hierachical tree |
| 510 |
2. Check subordinates of 1_1 entry |
| 511 |
3. Delete user_100 |
| 512 |
4. Check subordinates of 1_1 entry |
| 513 |
:expectedresults: |
| 514 |
1. provisioning done |
| 515 |
2. found subordinates should match expected ones |
| 516 |
""" |
| 517 |
|
| 518 |
# Check subordinates of user_11 |
| 519 |
#| |__ 1_1 |
| 520 |
#| | |__ 100 |
| 521 |
#| | |__ 101 |
| 522 |
#| | |__ 102 |
| 523 |
#| | |__ 103 |
| 524 |
#| | |__ 104 |
| 525 |
|
| 526 |
uid = "test_user_11" |
| 527 |
topo.standalone.log.info("Subordinate of uid=%s" % uid) |
| 528 |
expected = [] |
| 529 |
for i in range(100, 105): |
| 530 |
uid_expected = "test_user_%s" % i |
| 531 |
expected.append(uid_expected) |
| 532 |
topo.standalone.log.info("Subordinate expected: %s" % uid_expected) |
| 533 |
|
| 534 |
check_subordinates(topo, uid, expected) |
| 535 |
|
| 536 |
del_dn = "uid=test_user_100,ou=People,%s" % (DEFAULT_SUFFIX) |
| 537 |
user = UserAccount(topo.standalone, del_dn) |
| 538 |
topo.standalone.log.info("Delete: %s" % del_dn) |
| 539 |
user.delete() |
| 540 |
|
| 541 |
# Check subordinates of user_11 |
| 542 |
#| |__ 1_1 |
| 543 |
#| | |__ 101 |
| 544 |
#| | |__ 102 |
| 545 |
#| | |__ 103 |
| 546 |
#| | |__ 104 |
| 547 |
topo.standalone.log.info("Subordinate of uid=%s" % uid) |
| 548 |
expected = [] |
| 549 |
for i in range(101, 105): |
| 550 |
uid_expected = "test_user_%s" % i |
| 551 |
expected.append(uid_expected) |
| 552 |
topo.standalone.log.info("Subordinate expected: %s" % uid_expected) |
| 553 |
|
| 554 |
check_subordinates(topo, uid, expected) |
| 555 |
|
| 556 |
def test_recompute_add(topo, provision_inchain, request): |
| 557 |
"""Test that if we add a subordinate |
| 558 |
the subordinate list is correctly updated |
| 559 |
|
| 560 |
:id: 60d10233-37c2-400b-ac6e-d29b68706216 |
| 561 |
:setup: Standalone instance |
| 562 |
:steps: |
| 563 |
1. fixture provision a hierachical tree |
| 564 |
2. Check subordinates of 1_1 entry |
| 565 |
3. add user_105 |
| 566 |
4. Check subordinates of 1_1 entry |
| 567 |
:expectedresults: |
| 568 |
1. provisioning done |
| 569 |
2. found subordinates should match expected ones |
| 570 |
""" |
| 571 |
|
| 572 |
# Check subordinates of user_11 |
| 573 |
#| |__ 1_1 |
| 574 |
#| | |__ 100 |
| 575 |
#| | |__ 101 |
| 576 |
#| | |__ 102 |
| 577 |
#| | |__ 103 |
| 578 |
#| | |__ 104 |
| 579 |
uid = "test_user_11" |
| 580 |
topo.standalone.log.info("Subordinate of uid=%s" % uid) |
| 581 |
expected = [] |
| 582 |
for i in range(100, 105): |
| 583 |
uid_expected = "test_user_%s" % i |
| 584 |
expected.append(uid_expected) |
| 585 |
topo.standalone.log.info("Subordinate expected: %s" % uid_expected) |
| 586 |
|
| 587 |
check_subordinates(topo, uid, expected) |
| 588 |
|
| 589 |
# add a new subordinate of user_11 |
| 590 |
users = UserAccounts(topo.standalone, DEFAULT_SUFFIX) |
| 591 |
user_added = users.create_test_user(uid=105) |
| 592 |
topo.standalone.log.info("Add: %s" % user_added.dn) |
| 593 |
user_added.set("manager", "uid=%s,ou=People,%s" % (uid, DEFAULT_SUFFIX)) |
| 594 |
|
| 595 |
# Check subordinates of user_11 |
| 596 |
#| |__ 1_1 |
| 597 |
#| | |__ 100 |
| 598 |
#| | |__ 101 |
| 599 |
#| | |__ 102 |
| 600 |
#| | |__ 103 |
| 601 |
#| | |__ 104 |
| 602 |
#| | |__ 105 |
| 603 |
topo.standalone.log.info("Subordinate of uid=%s" % uid) |
| 604 |
expected = [] |
| 605 |
for i in range(100, 106): |
| 606 |
uid_expected = "test_user_%s" % i |
| 607 |
expected.append(uid_expected) |
| 608 |
topo.standalone.log.info("Subordinate expected: %s" % uid_expected) |
| 609 |
|
| 610 |
check_subordinates(topo, uid, expected) |
| 611 |
|
| 612 |
def fin(): |
| 613 |
user_added.delete() |
| 614 |
|
| 615 |
request.addfinalizer(fin) |
| 616 |
|
| 617 |
|
| 618 |
def test_anonymous_inchain(topo, provision_inchain): |
| 619 |
"""Test that anonymous connection can not |
| 620 |
retrieve subordinates |
| 621 |
|
| 622 |
:id: d6c41cc1-7c36-4a3f-bcdf-f479c12310e2 |
| 623 |
:setup: Standalone instance |
| 624 |
:steps: |
| 625 |
1. fixture provision a hierachical tree |
| 626 |
2. bound anonymous |
| 627 |
3. Check subordinates of 1_2 entry is empty although hierarchy |
| 628 |
:expectedresults: |
| 629 |
1. provisioning done |
| 630 |
2. succeed |
| 631 |
3. succeeds but 0 subordinates |
| 632 |
""" |
| 633 |
|
| 634 |
# create an anonymous connection |
| 635 |
topo.standalone.log.info("Bind as anonymous user") |
| 636 |
conn = Anonymous(topo.standalone).bind() |
| 637 |
|
| 638 |
# Check that there are no subordinates of test_user_12 |
| 639 |
uid = "test_user_12" |
| 640 |
manager = "uid=%s,ou=People,%s" % (uid, DEFAULT_SUFFIX) |
| 641 |
topo.standalone.log.info("Subordinate of manager %s on anonymous connection" % manager) |
| 642 |
|
| 643 |
subordinates = conn.search_s(DEFAULT_SUFFIX, SCOPE_SUBTREE, "(manager:%s:=%s)" % (INCHAIN_OID, manager)) |
| 644 |
assert len(subordinates) == 0 |
| 645 |
|
| 646 |
# Check the ACI right failure |
| 647 |
assert topo.standalone.ds_error_log.match('.*inchain - Requestor is not allowed to use InChain Matching rule$') |
| 648 |
|
| 649 |
def test_authenticated_inchain(topo, provision_inchain, request): |
| 650 |
"""Test that bound connection can not |
| 651 |
retrieve subordinates (only DM is allowed by default) |
| 652 |
|
| 653 |
:id: 17ebee0d-86e2-4f0d-95fe-8a4cf566a493 |
| 654 |
:setup: Standalone instance |
| 655 |
:steps: |
| 656 |
1. fixture provision a hierachical tree |
| 657 |
2. create a test user |
| 658 |
3. create a bound connection |
| 659 |
4. Check subordinates of 1_2 entry is empty although hierarchy |
| 660 |
:expectedresults: |
| 661 |
1. provisioning done |
| 662 |
2. succeed |
| 663 |
3. succeed |
| 664 |
4. succeeds but 0 subordinates |
| 665 |
""" |
| 666 |
|
| 667 |
# create a user |
| 668 |
RDN = "test_bound_user" |
| 669 |
test_user = UserAccount(topo.standalone, "uid=%s,ou=People,%s" % (RDN, DEFAULT_SUFFIX)) |
| 670 |
test_user.create(properties={ |
| 671 |
'uid': RDN, |
| 672 |
'cn': RDN, |
| 673 |
'sn': RDN, |
| 674 |
'userPassword': "password", |
| 675 |
'uidNumber' : '1000', |
| 676 |
'gidNumber' : '2000', |
| 677 |
'homeDirectory' : '/home/inchain', |
| 678 |
}) |
| 679 |
|
| 680 |
# create a bound connection |
| 681 |
conn = test_user.bind("password") |
| 682 |
|
| 683 |
# Check that there are no subordinates of test_user_12 |
| 684 |
uid = "test_user_12" |
| 685 |
manager = "uid=%s,ou=People,%s" % (uid, DEFAULT_SUFFIX) |
| 686 |
topo.standalone.log.info("Subordinate of manager %s on bound connection" % manager) |
| 687 |
|
| 688 |
subordinates = conn.search_s(DEFAULT_SUFFIX, SCOPE_SUBTREE, "(manager:%s:=%s)" % (INCHAIN_OID, manager)) |
| 689 |
assert len(subordinates) == 0 |
| 690 |
|
| 691 |
# Check the ACI right failure |
| 692 |
assert topo.standalone.ds_error_log.match('.*inchain - Requestor is not allowed to use InChain Matching rule$') |
| 693 |
|
| 694 |
def fin(): |
| 695 |
test_user.delete() |
| 696 |
|
| 697 |
request.addfinalizer(fin) |
| 698 |
|
| 699 |
|
| 700 |
def _create_user(topology_st, ext): |
| 701 |
user_dn = "uid=%s,ou=People,%s" % (ext, DEFAULT_SUFFIX) |
| 702 |
topology_st.standalone.add_s(Entry((user_dn, { |
| 703 |
'objectclass': 'top extensibleObject'.split(), |
| 704 |
'uid': ext |
| 705 |
}))) |
| 706 |
topology_st.standalone.log.info("Create user %s" % user_dn) |
| 707 |
return ensure_bytes(user_dn) |
| 708 |
|
| 709 |
def _create_group(topology_st, ext): |
| 710 |
group_dn = "ou=%s,ou=People,%s" % (ext, DEFAULT_SUFFIX) |
| 711 |
topology_st.standalone.add_s(Entry((group_dn, { |
| 712 |
'objectclass': 'top groupOfNames extensibleObject'.split(), |
| 713 |
'ou': ext, |
| 714 |
'cn': ext |
| 715 |
}))) |
| 716 |
topology_st.standalone.log.info("Create group %s" % group_dn) |
| 717 |
return ensure_bytes(group_dn) |
| 718 |
|
| 719 |
def test_reuse_memberof(topo, request): |
| 720 |
"""Check that slapi_memberof successfully |
| 721 |
compute the membership either using 'memberof' attribute |
| 722 |
or either recomputing it. |
| 723 |
|
| 724 |
:id: e52bd21a-3ff6-493f-9ec5-8cf4e76696a0 |
| 725 |
:setup: Standalone instance |
| 726 |
:steps: |
| 727 |
1. Enable the plugin |
| 728 |
2. Create a user belonging in cascade to 3 groups |
| 729 |
3. Check that slapi_member re-computes membership |
| 730 |
4. Check that slapi_member retrieve membership from memberof |
| 731 |
:expectedresults: |
| 732 |
1. Success |
| 733 |
2. Success |
| 734 |
3. Success |
| 735 |
4. Success |
| 736 |
""" |
| 737 |
|
| 738 |
# enable the plugin |
| 739 |
topo.standalone.log.info("Enable MemberOf plugin") |
| 740 |
topo.standalone.plugins.enable(name=PLUGIN_MEMBER_OF) |
| 741 |
topo.standalone.restart() |
| 742 |
|
| 743 |
# Create a user belonging to 3 goups |
| 744 |
# in cascade |
| 745 |
user1 = _create_user(topo, 'user1') |
| 746 |
|
| 747 |
group1 = _create_group(topo, 'group1') |
| 748 |
mods = [(ldap.MOD_ADD, 'member', user1)] |
| 749 |
topo.standalone.modify_s(ensure_str(group1), mods) |
| 750 |
|
| 751 |
group2 = _create_group(topo, 'group2') |
| 752 |
mods = [(ldap.MOD_ADD, 'member', group1)] |
| 753 |
topo.standalone.modify_s(ensure_str(group2), mods) |
| 754 |
|
| 755 |
group3 = _create_group(topo, 'group3') |
| 756 |
mods = [(ldap.MOD_ADD, 'member', group2)] |
| 757 |
topo.standalone.modify_s(ensure_str(group3), mods) |
| 758 |
|
| 759 |
# Call slapi_member that does *not* reuse the memberof |
| 760 |
# because of 'memberOfEntryScope' not being set |
| 761 |
topo.standalone.log.info("Groups that %s is memberof" % ensure_str(user1)) |
| 762 |
|
| 763 |
topo.standalone.config.set('nsslapd-errorlog-level', '65536') # plugin logging |
| 764 |
memberof = topo.standalone.search_s(DEFAULT_SUFFIX, SCOPE_SUBTREE, "(member:%s:=%s)" % (INCHAIN_OID, ensure_str(user1))) |
| 765 |
topo.standalone.config.set('nsslapd-errorlog-level', '0') |
| 766 |
for sub in memberof: |
| 767 |
topo.standalone.log.info("memberof found : %s" % sub.dn) |
| 768 |
assert sub.dn in [ensure_str(group1), ensure_str(group2), ensure_str(group3)] |
| 769 |
assert topo.standalone.ds_error_log.match('.*sm_compare_memberof_config: fails because requested include scope is not empty.*') |
| 770 |
assert not topo.standalone.ds_error_log.match('.*slapi_memberof - sm_compare_memberof_config: succeeds. requested options match config.*') |
| 771 |
|
| 772 |
# Call slapi_member that does reuse the memberof |
| 773 |
# because of 'memberOfEntryScope' being set |
| 774 |
memberof = MemberOfPlugin(topo.standalone) |
| 775 |
memberof.replace('memberOfEntryScope', DEFAULT_SUFFIX) |
| 776 |
topo.standalone.restart() |
| 777 |
topo.standalone.config.set('nsslapd-errorlog-level', '65536') # plugin logging |
| 778 |
memberof = topo.standalone.search_s(DEFAULT_SUFFIX, SCOPE_SUBTREE, "(member:%s:=%s)" % (INCHAIN_OID, ensure_str(user1))) |
| 779 |
topo.standalone.config.set('nsslapd-errorlog-level', '0') |
| 780 |
for sub in memberof: |
| 781 |
topo.standalone.log.info("memberof found : %s" % sub.dn) |
| 782 |
assert sub.dn in [ensure_str(group1), ensure_str(group2), ensure_str(group3)] |
| 783 |
assert topo.standalone.ds_error_log.match('.*slapi_memberof - sm_compare_memberof_config: succeeds. requested options match config.*') |
| 784 |
|
| 785 |
def fin(): |
| 786 |
topo.standalone.delete_s(ensure_str(user1)) |
| 787 |
topo.standalone.delete_s(ensure_str(group1)) |
| 788 |
topo.standalone.delete_s(ensure_str(group2)) |
| 789 |
topo.standalone.delete_s(ensure_str(group3)) |
| 790 |
|
| 791 |
request.addfinalizer(fin) |
| 792 |
|
| 793 |
def test_invalid_assertion(topo): |
| 794 |
"""Check that with invalid assertion |
| 795 |
there is no returned entries |
| 796 |
|
| 797 |
:id: 0a204b81-e7c0-41a0-97cc-7d9425a603c2 |
| 798 |
:setup: Standalone instance |
| 799 |
:steps: |
| 800 |
1. Search with invalid assertion '..:=foo' |
| 801 |
2. Search with not existing entry '..:=<dummy_entry>' |
| 802 |
:expectedresults: |
| 803 |
1. Success |
| 804 |
2. Success |
| 805 |
""" |
| 806 |
topo.standalone.log.info("Search with an invalid assertion") |
| 807 |
memberof = topo.standalone.search_s(DEFAULT_SUFFIX, SCOPE_SUBTREE, "(member:%s:=foo)" % (INCHAIN_OID)) |
| 808 |
assert len(memberof) == 0 |
| 809 |
|
| 810 |
topo.standalone.log.info("Search with an none exisiting entry") |
| 811 |
|
| 812 |
user = "uid=not_existing_entry,ou=People,%s" % (DEFAULT_SUFFIX) |
| 813 |
memberof = topo.standalone.search_s(DEFAULT_SUFFIX, SCOPE_SUBTREE, "(member:%s:=%s)" % (INCHAIN_OID, user)) |
| 814 |
assert len(memberof) == 0 |
| 815 |
|
| 816 |
def test_check_dsconf_matchingrule(topo): |
| 817 |
"""Test that the matching rule 'inchain' is listed by dsconf |
| 818 |
|
| 819 |
:id: b8dd4049-ccec-4316-bc9c-5aa5c5afcfbd |
| 820 |
:setup: Standalone Instance |
| 821 |
:steps: |
| 822 |
1. fetch matching rules from the schema |
| 823 |
2. Checks that matching rules contains inchaineMatch matching rule |
| 824 |
:expectedresults: |
| 825 |
1. Success |
| 826 |
2. Success |
| 827 |
""" |
| 828 |
schema = Schema(topo.standalone) |
| 829 |
mrs = [ f"{mr.oid} {mr.names[0]}" for mr in schema.get_matchingrules() if len(mr.names) > 0 ] |
| 830 |
for mr in mrs: |
| 831 |
log.info("retrieved matching rules are: %s", mr) |
| 832 |
assert '1.2.840.113556.1.4.1941 inchainMatch' in mrs |
| 833 |
|
| 834 |
if __name__ == "__main__": |
| 835 |
CURRENT_FILE = os.path.realpath(__file__) |
| 836 |
pytest.main("-s -v %s" % CURRENT_FILE) |