| 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 ldap |
| 12 |
import pytest |
| 13 |
from lib389.idm.user import UserAccounts |
| 14 |
from test389.topologies import topology_m2 as topo |
| 15 |
from lib389._constants import * |
| 16 |
|
| 17 |
pytestmark = pytest.mark.tier1 |
| 18 |
|
| 19 |
DEBUGGING = os.getenv("DEBUGGING", default=False) |
| 20 |
if DEBUGGING: |
| 21 |
logging.getLogger(__name__).setLevel(logging.DEBUG) |
| 22 |
else: |
| 23 |
logging.getLogger(__name__).setLevel(logging.INFO) |
| 24 |
log = logging.getLogger(__name__) |
| 25 |
|
| 26 |
BINVALUE1 = 'thedeadbeef1' |
| 27 |
BINVALUE2 = 'thedeadbeef2' |
| 28 |
BINVALUE3 = 'thedeadbeef3' |
| 29 |
|
| 30 |
USER_PROPERTIES = { |
| 31 |
'uid': 'state1usr', |
| 32 |
'cn': 'state1usr', |
| 33 |
'sn': 'state1usr', |
| 34 |
'uidNumber': '1001', |
| 35 |
'gidNumber': '2001', |
| 36 |
'userpassword': PASSWORD, |
| 37 |
'homeDirectory': '/home/testuser' |
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
def _check_user_oper_attrs(topo, tuser, attr_name, attr_value, oper_type, exp_values, oper_attr): |
| 42 |
"""Check if list of operational attributes present for a given entry""" |
| 43 |
|
| 44 |
log.info('Checking if operational attrs vucsn, adcsn and vdcsn present for: {}'.format(tuser)) |
| 45 |
entry = topo.ms["supplier1"].search_s(tuser.dn, ldap.SCOPE_BASE, 'objectclass=*',['nscpentrywsi']) |
| 46 |
if oper_attr: |
| 47 |
match = False |
| 48 |
for line in str(entry).split('\n'): |
| 49 |
if attr_name.lower() + ';' in line.lower(): |
| 50 |
match = True |
| 51 |
if not 'DELETE' in oper_type: |
| 52 |
assert any(attr in line for attr in exp_values) and oper_attr in line |
| 53 |
else: |
| 54 |
assert 'deleted' in line and oper_attr in line |
| 55 |
|
| 56 |
# If we didn't look at a single attribute then something went wrong |
| 57 |
assert match |
| 58 |
|
| 59 |
|
| 60 |
@pytest.mark.parametrize("attr_name, attr_value, oper_type, exp_values, oper_attr", |
| 61 |
[('description', 'Test1usr1', 'ldap.MOD_ADD', ['Test1usr1'], 'vucsn'), |
| 62 |
('description', 'Test1usr2', 'ldap.MOD_ADD', ['Test1usr1', |
| 63 |
'Test1usr2'], 'vucsn'), |
| 64 |
('description', 'Test1usr3', 'ldap.MOD_ADD', |
| 65 |
['Test1usr1', 'Test1usr2', 'Test1usr3'], 'vucsn'), |
| 66 |
('description', 'Test1usr4', 'ldap.MOD_REPLACE', ['Test1usr4'], |
| 67 |
'adcsn'), |
| 68 |
('description', 'Test1usr4', 'ldap.MOD_DELETE', [], 'vdcsn')]) |
| 69 |
def test_check_desc_attr_state(topo, attr_name, attr_value, oper_type, exp_values, oper_attr): |
| 70 |
"""Modify user's description attribute and check if description attribute is |
| 71 |
added/modified/deleted and operational attributes vucsn, adcsn and vdcsn are present. |
| 72 |
|
| 73 |
:id: f0830538-02cf-11e9-8be0-8c16451d917b |
| 74 |
:parametrized: yes |
| 75 |
:setup: Replication with two suppliers. |
| 76 |
:steps: 1. Add user to Supplier1 without description attribute. |
| 77 |
2. Add description attribute to user. |
| 78 |
3. Check if only one description attribute exist. |
| 79 |
4. Check if operational attribute vucsn exist. |
| 80 |
5. Add second description attribute to user. |
| 81 |
6. Check if two description attributes exist. |
| 82 |
7. Check if operational attribute vucsn exist. |
| 83 |
8. Add third description attribute to user. |
| 84 |
9. Check if three description attributes exist. |
| 85 |
10. Check if operational attribute vucsn exist. |
| 86 |
11. Replace description attribute for the user. |
| 87 |
12. Check if only one description attribute exist. |
| 88 |
13. Check if operational attribute adcsn exist. |
| 89 |
14. Delete description attribute for the user. |
| 90 |
15. Check if no description attribute exist. |
| 91 |
16. Check if no operational attribute vdcsn exist. |
| 92 |
:expectedresults: |
| 93 |
1. Add user to M1 should PASS. |
| 94 |
2. Adding description attribute should PASS |
| 95 |
3. Only one description attribute should be present. |
| 96 |
4. Vucsn attribute should be present. |
| 97 |
5. Adding a new description attribute should PASS |
| 98 |
6. Two description attribute should be present. |
| 99 |
7. Vucsn attribute should be present. |
| 100 |
8. Adding a new description attribute should PASS |
| 101 |
9. Three description attribute should be present. |
| 102 |
10. Vucsn attribute should be present. |
| 103 |
11. Replacing new description attribute should PASS |
| 104 |
12. Only one description attribute should be present. |
| 105 |
13. Adcsn attribute should be present. |
| 106 |
14. Deleting description attribute should PASS |
| 107 |
15. No description attribute should be present. |
| 108 |
16. Vdcsn attribute should be present. |
| 109 |
""" |
| 110 |
|
| 111 |
test_entry = 'state1test' |
| 112 |
log.info('Add user: {}'.format(test_entry)) |
| 113 |
users = UserAccounts(topo.ms['supplier1'], DEFAULT_SUFFIX) |
| 114 |
try: |
| 115 |
tuser = users.get(test_entry) |
| 116 |
except ldap.NO_SUCH_OBJECT: |
| 117 |
USER_PROPERTIES.update(dict.fromkeys(['uid', 'cn'], test_entry)) |
| 118 |
tuser = users.create(properties=USER_PROPERTIES) |
| 119 |
tuser.set(attr_name, attr_value, eval(oper_type)) |
| 120 |
log.info('Check if list of description attrs present for: {}'.format(test_entry)) |
| 121 |
assert sorted([i.decode() for i in tuser.get_attr_vals(attr_name)]) == sorted(exp_values) |
| 122 |
|
| 123 |
log.info('Checking for operational attributes') |
| 124 |
_check_user_oper_attrs(topo, tuser, attr_name, attr_value, oper_type, exp_values, oper_attr) |
| 125 |
|
| 126 |
|
| 127 |
@pytest.mark.parametrize("attr_name, attr_value, oper_type, exp_values, oper_attr", |
| 128 |
[('cn', 'TestCN1', 'ldap.MOD_ADD', ['TestCN1', 'TestCNusr1'], 'vucsn'), |
| 129 |
('cn', 'TestCN2', 'ldap.MOD_ADD', ['TestCN1', |
| 130 |
'TestCN2', 'TestCNusr1'], 'vucsn'), |
| 131 |
('cn', 'TestnewCN3', 'ldap.MOD_REPLACE', ['TestnewCN3'], 'adcsn'), |
| 132 |
('cn', 'TestnewCN3', 'ldap.MOD_DELETE', None, None)]) |
| 133 |
def test_check_cn_attr_state(topo, attr_name, attr_value, oper_type, exp_values, oper_attr): |
| 134 |
"""Modify user's cn attribute and check if cn attribute is added/modified/deleted and |
| 135 |
operational attributes vucsn, adcsn and vdcsn are present. |
| 136 |
|
| 137 |
:id: 19614bae-02d0-11e9-a295-8c16451d917b |
| 138 |
:parametrized: yes |
| 139 |
:setup: Replication with two suppliers. |
| 140 |
:steps: 1. Add user to Supplier1 with cn attribute. |
| 141 |
2. Add a new cn attribute to user. |
| 142 |
3. Check if two cn attributes exist. |
| 143 |
4. Check if operational attribute vucsn exist for each cn attribute. |
| 144 |
5. Add a new cn attribute to user. |
| 145 |
6. Check if three cn attributes exist. |
| 146 |
7. Check if operational attribute vucsn exist for each cn attribute. |
| 147 |
8. Replace cn attribute for the user. |
| 148 |
9. Check if only one cn attribute exist. |
| 149 |
10. Check if operational attribute adcsn exist. |
| 150 |
11. Delete cn attribute from user and check if it fails. |
| 151 |
:expectedresults: |
| 152 |
1. Add user to M1 should PASS. |
| 153 |
2. Adding a new cn attribute should PASS |
| 154 |
3. Two cn attribute should be present. |
| 155 |
4. Vucsn attribute should be present. |
| 156 |
5. Adding a new cn attribute should PASS |
| 157 |
6. Three cn attribute should be present. |
| 158 |
7. Vucsn attribute should be present. |
| 159 |
8. Replacing new cn attribute should PASS |
| 160 |
9. Only one cn attribute should be present. |
| 161 |
10. Operational attribute adcsn should be present. |
| 162 |
11. Deleting cn attribute should fail with ObjectClass violation error. |
| 163 |
""" |
| 164 |
|
| 165 |
test_entry = 'TestCNusr1' |
| 166 |
log.info('Add user: {}'.format(test_entry)) |
| 167 |
users = UserAccounts(topo.ms['supplier1'], DEFAULT_SUFFIX) |
| 168 |
try: |
| 169 |
tuser = users.get(test_entry) |
| 170 |
except ldap.NO_SUCH_OBJECT: |
| 171 |
USER_PROPERTIES.update(dict.fromkeys(['uid', 'cn'], test_entry)) |
| 172 |
tuser = users.create(properties=USER_PROPERTIES) |
| 173 |
|
| 174 |
if 'MOD_DELETE' in oper_type: |
| 175 |
with pytest.raises(ldap.OBJECT_CLASS_VIOLATION): |
| 176 |
tuser.set(attr_name, attr_value, eval(oper_type)) |
| 177 |
else: |
| 178 |
tuser.set(attr_name, attr_value, eval(oper_type)) |
| 179 |
log.info('Check if list of cn attrs present for: {}'.format(test_entry)) |
| 180 |
assert sorted([i.decode() for i in tuser.get_attr_vals(attr_name)]) == sorted(exp_values) |
| 181 |
log.info('Checking for operational attributes') |
| 182 |
_check_user_oper_attrs(topo, tuser, attr_name, attr_value, oper_type, exp_values, oper_attr) |
| 183 |
|
| 184 |
|
| 185 |
@pytest.mark.parametrize("attr_name, attr_value, oper_type, exp_values, oper_attr", |
| 186 |
[('preferredlanguage', 'Chinese', 'ldap.MOD_REPLACE', ['Chinese'], |
| 187 |
'vucsn'), |
| 188 |
('preferredlanguage', 'French', 'ldap.MOD_ADD', None, None), |
| 189 |
('preferredlanguage', 'German', 'ldap.MOD_REPLACE', ['German'], 'adcsn'), |
| 190 |
('preferredlanguage', 'German', 'ldap.MOD_DELETE', [], 'vdcsn')]) |
| 191 |
def test_check_single_value_attr_state(topo, attr_name, attr_value, oper_type, |
| 192 |
exp_values, oper_attr): |
| 193 |
"""Modify user's preferredlanguage attribute and check if preferredlanguage attribute is |
| 194 |
added/modified/deleted and operational attributes vucsn, adcsn and vdcsn are present. |
| 195 |
|
| 196 |
:id: 22fd645e-02d0-11e9-a9e4-8c16451d917b |
| 197 |
:parametrized: yes |
| 198 |
:setup: Replication with two suppliers. |
| 199 |
:steps: 1. Add user to Supplier1 without preferredlanguage attribute. |
| 200 |
2. Add a new preferredlanguage attribute to user. |
| 201 |
3. Check if one preferredlanguage attributes exist. |
| 202 |
4. Check if operational attribute vucsn exist. |
| 203 |
5. Add a new preferredlanguage attribute for the user and check if its rejected. |
| 204 |
6. Replace preferredlanguage attribute for the user. |
| 205 |
7. Check if only one preferredlanguage attribute exist. |
| 206 |
8. Check if operational attribute adcsn exist with preferredlanguage. |
| 207 |
:expectedresults: |
| 208 |
1. Add user to M1 should PASS. |
| 209 |
2. Adding a new preferredlanguage attribute should PASS |
| 210 |
3. Only one preferredlanguage attribute should be present. |
| 211 |
4. Vucsn attribute should be present. |
| 212 |
5. Adding a new preferredlanguage should fail with ObjectClass violation error. |
| 213 |
6. Replace preferredlanguage should PASS. |
| 214 |
7. Only one preferredlanguage attribute should be present. |
| 215 |
8. Operational attribute adcsn should be present with preferredlanguage. |
| 216 |
""" |
| 217 |
|
| 218 |
test_entry = 'Langusr1' |
| 219 |
log.info('Add user: {}'.format(test_entry)) |
| 220 |
users = UserAccounts(topo.ms['supplier1'], DEFAULT_SUFFIX) |
| 221 |
try: |
| 222 |
tuser = users.get(test_entry) |
| 223 |
except ldap.NO_SUCH_OBJECT: |
| 224 |
USER_PROPERTIES.update(dict.fromkeys(['uid', 'cn'], test_entry)) |
| 225 |
tuser = users.create(properties=USER_PROPERTIES) |
| 226 |
|
| 227 |
if 'MOD_ADD' in oper_type: |
| 228 |
with pytest.raises(ldap.OBJECT_CLASS_VIOLATION): |
| 229 |
tuser.set(attr_name, attr_value, eval(oper_type)) |
| 230 |
else: |
| 231 |
tuser.set(attr_name, attr_value, eval(oper_type)) |
| 232 |
log.info('Check if list of cn attrs present for: {}'.format(test_entry)) |
| 233 |
assert sorted([i.decode() for i in tuser.get_attr_vals(attr_name)]) == sorted(exp_values) |
| 234 |
log.info('Checking for operational attributes') |
| 235 |
_check_user_oper_attrs(topo, tuser, attr_name, attr_value, oper_type, exp_values, oper_attr) |
| 236 |
|
| 237 |
|
| 238 |
@pytest.mark.parametrize("attr_name, attr_value, oper_type, exp_values, oper_attr", |
| 239 |
[('roomnumber;office', 'Tower1', 'ldap.MOD_ADD', ['Tower1'], 'vucsn'), |
| 240 |
('roomnumber;office', 'Tower2', 'ldap.MOD_ADD', ['Tower1', 'Tower2'], |
| 241 |
'vucsn'), |
| 242 |
('roomnumber;office', 'Tower3', 'ldap.MOD_ADD', ['Tower1', 'Tower2', |
| 243 |
'Tower3'], 'vucsn'), |
| 244 |
('roomnumber;office', 'Tower4', 'ldap.MOD_REPLACE', ['Tower4'], 'adcsn'), |
| 245 |
('roomnumber;office', 'Tower4', 'ldap.MOD_DELETE', [], 'vucsn')]) |
| 246 |
def test_check_subtype_attr_state(topo, attr_name, attr_value, oper_type, exp_values, oper_attr): |
| 247 |
"""Modify user's roomnumber;office attribute subtype and check if roomnumber;office attribute |
| 248 |
is added/modified/deleted and operational attributes vucsn, adcsn and vdcsn are present. |
| 249 |
|
| 250 |
:id: 29ab87a4-02d0-11e9-b104-8c16451d917b |
| 251 |
:parametrized: yes |
| 252 |
:setup: Replication with two suppliers. |
| 253 |
:steps: 1. Add user to Supplier1 without roomnumber;office attribute. |
| 254 |
2. Add roomnumber;office attribute to user. |
| 255 |
3. Check if only one roomnumber;office attribute exist. |
| 256 |
4. Check if operational attribute vucsn exist. |
| 257 |
5. Add second roomnumber;office attribute to user. |
| 258 |
6. Check if two roomnumber;office attributes exist. |
| 259 |
7. Check if operational attribute vucsn exist. |
| 260 |
8. Add third roomnumber;office attribute to user. |
| 261 |
9. Check if three roomnumber;office attributes exist. |
| 262 |
10. Check if operational attribute vucsn exist. |
| 263 |
11. Replace roomnumber;office attribute for the user. |
| 264 |
12. Check if only one roomnumber;office attribute exist. |
| 265 |
13. Check if operational attribute adcsn exist. |
| 266 |
14. Delete roomnumber;office attribute for the user. |
| 267 |
15. Check if no roomnumber;office attribute exist. |
| 268 |
16. Check if no operational attribute vdcsn exist. |
| 269 |
:expectedresults: |
| 270 |
1. Add user to M1 should PASS. |
| 271 |
2. Adding roomnumber;office attribute should PASS |
| 272 |
3. Only one roomnumber;office attribute should be present. |
| 273 |
4. Vucsn attribute should be present. |
| 274 |
5. Adding a new roomnumber;office attribute should PASS |
| 275 |
6. Two roomnumber;office attribute should be present. |
| 276 |
7. Vucsn attribute should be present. |
| 277 |
8. Adding a new roomnumber;office attribute should PASS |
| 278 |
9. Three roomnumber;office attribute should be present. |
| 279 |
10. Vucsn attribute should be present. |
| 280 |
11. Replacing new roomnumber;office attribute should PASS |
| 281 |
12. Only one roomnumber;office attribute should be present. |
| 282 |
13. Adcsn attribute should be present. |
| 283 |
14. Deleting roomnumber;office attribute should PASS |
| 284 |
15. No roomnumber;office attribute should be present. |
| 285 |
16. Vdcsn attribute should be present. |
| 286 |
""" |
| 287 |
|
| 288 |
test_entry = 'roomoffice1usr' |
| 289 |
log.info('Add user: {}'.format(test_entry)) |
| 290 |
users = UserAccounts(topo.ms['supplier1'], DEFAULT_SUFFIX) |
| 291 |
try: |
| 292 |
tuser = users.get(test_entry) |
| 293 |
except ldap.NO_SUCH_OBJECT: |
| 294 |
USER_PROPERTIES.update(dict.fromkeys(['uid', 'cn'], test_entry)) |
| 295 |
tuser = users.create(properties=USER_PROPERTIES) |
| 296 |
|
| 297 |
tuser.set(attr_name, attr_value, eval(oper_type)) |
| 298 |
log.info('Check if list of roomnumber;office attributes are present for a given entry') |
| 299 |
assert sorted([i.decode() for i in tuser.get_attr_vals(attr_name)]) == sorted(exp_values) |
| 300 |
log.info('Checking if operational attributes are present for cn') |
| 301 |
_check_user_oper_attrs(topo, tuser, attr_name, attr_value, oper_type, exp_values, oper_attr) |
| 302 |
|
| 303 |
|
| 304 |
@pytest.mark.parametrize("attr_name, attr_value, oper_type, exp_values, oper_attr", |
| 305 |
[('jpegphoto', BINVALUE1, 'ldap.MOD_ADD', [BINVALUE1], 'vucsn'), |
| 306 |
('jpegphoto', BINVALUE2, 'ldap.MOD_ADD', [BINVALUE1, BINVALUE2], |
| 307 |
'vucsn'), |
| 308 |
('jpegphoto', BINVALUE3, 'ldap.MOD_ADD', [BINVALUE1, BINVALUE2, |
| 309 |
BINVALUE3], 'vucsn'), |
| 310 |
('jpegphoto', BINVALUE2, 'ldap.MOD_REPLACE', [BINVALUE2], 'adcsn'), |
| 311 |
('jpegphoto', BINVALUE2, 'ldap.MOD_DELETE', [], 'vdcsn')]) |
| 312 |
def test_check_jpeg_attr_state(topo, attr_name, attr_value, oper_type, exp_values, oper_attr): |
| 313 |
"""Modify user's jpegphoto attribute and check if jpegphoto attribute is added/modified/deleted |
| 314 |
and operational attributes vucsn, adcsn and vdcsn are present. |
| 315 |
|
| 316 |
:id: 312ac0d0-02d0-11e9-9d34-8c16451d917b |
| 317 |
:parametrized: yes |
| 318 |
:setup: Replication with two suppliers. |
| 319 |
:steps: 1. Add user to Supplier1 without jpegphoto attribute. |
| 320 |
2. Add jpegphoto attribute to user. |
| 321 |
3. Check if only one jpegphoto attribute exist. |
| 322 |
4. Check if operational attribute vucsn exist. |
| 323 |
5. Add second jpegphoto attribute to user. |
| 324 |
6. Check if two jpegphoto attributes exist. |
| 325 |
7. Check if operational attribute vucsn exist. |
| 326 |
8. Add third jpegphoto attribute to user. |
| 327 |
9. Check if three jpegphoto attributes exist. |
| 328 |
10. Check if operational attribute vucsn exist. |
| 329 |
11. Replace jpegphoto attribute for the user. |
| 330 |
12. Check if only one jpegphoto attribute exist. |
| 331 |
13. Check if operational attribute adcsn exist. |
| 332 |
14. Delete jpegphoto attribute for the user. |
| 333 |
15. Check if no jpegphoto attribute exist. |
| 334 |
16. Check if no operational attribute vdcsn exist. |
| 335 |
:expectedresults: |
| 336 |
1. Add user to M1 should PASS. |
| 337 |
2. Adding jpegphoto attribute should PASS |
| 338 |
3. Only one jpegphoto attribute should be present. |
| 339 |
4. Vucsn attribute should be present. |
| 340 |
5. Adding a new jpegphoto attribute should PASS |
| 341 |
6. Two jpegphoto attribute should be present. |
| 342 |
7. Vucsn attribute should be present. |
| 343 |
8. Adding a new jpegphoto attribute should PASS |
| 344 |
9. Three jpegphoto attribute should be present. |
| 345 |
10. Vucsn attribute should be present. |
| 346 |
11. Replacing new jpegphoto attribute should PASS |
| 347 |
12. Only one jpegphoto attribute should be present. |
| 348 |
13. Adcsn attribute should be present. |
| 349 |
14. Deleting jpegphoto attribute should PASS |
| 350 |
15. No jpegphoto attribute should be present. |
| 351 |
16. Vdcsn attribute should be present. |
| 352 |
""" |
| 353 |
|
| 354 |
test_entry = 'testJpeg1usr' |
| 355 |
log.info('Add user: {}'.format(test_entry)) |
| 356 |
users = UserAccounts(topo.ms['supplier1'], DEFAULT_SUFFIX) |
| 357 |
try: |
| 358 |
tuser = users.get(test_entry) |
| 359 |
except ldap.NO_SUCH_OBJECT: |
| 360 |
USER_PROPERTIES.update(dict.fromkeys(['uid', 'cn'], test_entry)) |
| 361 |
tuser = users.create(properties=USER_PROPERTIES) |
| 362 |
|
| 363 |
tuser.set(attr_name, attr_value, eval(oper_type)) |
| 364 |
log.info('Check if list of jpeg attributes are present for a given entry') |
| 365 |
assert sorted([i.decode() for i in tuser.get_attr_vals(attr_name)]) == sorted(exp_values) |
| 366 |
log.info('Checking if operational attributes are present for cn') |
| 367 |
_check_user_oper_attrs(topo, tuser, attr_name, attr_value, oper_type, exp_values, oper_attr) |
| 368 |
|
| 369 |
|
| 370 |
if __name__ == "__main__": |
| 371 |
# Run isolated |
| 372 |
# -s for DEBUG mode |
| 373 |
CURRENT_FILE = os.path.realpath(__file__) |
| 374 |
pytest.main("-s -v %s" % CURRENT_FILE) |