| 1 |
# --- BEGIN COPYRIGHT BLOCK --- |
| 2 |
# Copyright (C) 2025 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 |
| 10 |
import os |
| 11 |
import ldap |
| 12 |
import logging |
| 13 |
from test389.topologies import topology_st |
| 14 |
from lib389._constants import DEFAULT_SUFFIX |
| 15 |
from lib389.idm.user import UserAccount, UserAccounts |
| 16 |
from lib389.idm.group import Group, Groups |
| 17 |
|
| 18 |
logging.getLogger(__name__).setLevel(logging.DEBUG) |
| 19 |
log = logging.getLogger(__name__) |
| 20 |
|
| 21 |
|
| 22 |
@pytest.fixture(scope='function') |
| 23 |
def group1(topology_st, request): |
| 24 |
groupname = 'group1' |
| 25 |
log.info('Create group1') |
| 26 |
groups = Groups(topology_st.standalone, DEFAULT_SUFFIX) |
| 27 |
if groups.exists(groupname): |
| 28 |
groups.get(groupname).delete() |
| 29 |
|
| 30 |
group1 = groups.create(properties={'cn': groupname}) |
| 31 |
|
| 32 |
def fin(): |
| 33 |
if group1.exists(): |
| 34 |
log.info('Delete group1') |
| 35 |
group1.delete() |
| 36 |
|
| 37 |
request.addfinalizer(fin) |
| 38 |
|
| 39 |
return group1 |
| 40 |
|
| 41 |
|
| 42 |
@pytest.fixture(scope='function') |
| 43 |
def group2(topology_st, request): |
| 44 |
groupname = 'group2' |
| 45 |
log.info('Create group2') |
| 46 |
groups = Groups(topology_st.standalone, DEFAULT_SUFFIX) |
| 47 |
if groups.exists(groupname): |
| 48 |
groups.get(groupname).delete() |
| 49 |
|
| 50 |
group2 = groups.create(properties={'cn': groupname}) |
| 51 |
|
| 52 |
def fin(): |
| 53 |
if group2.exists(): |
| 54 |
log.info('Delete group2') |
| 55 |
group2.delete() |
| 56 |
|
| 57 |
request.addfinalizer(fin) |
| 58 |
|
| 59 |
return group2 |
| 60 |
|
| 61 |
|
| 62 |
@pytest.fixture(scope='function') |
| 63 |
def group3(topology_st, request): |
| 64 |
groupname = 'group3' |
| 65 |
log.info('Create group3') |
| 66 |
groups = Groups(topology_st.standalone, DEFAULT_SUFFIX) |
| 67 |
if groups.exists(groupname): |
| 68 |
groups.get(groupname).delete() |
| 69 |
|
| 70 |
group3 = groups.create(properties={'cn': groupname}) |
| 71 |
|
| 72 |
def fin(): |
| 73 |
if group3.exists(): |
| 74 |
log.info('Delete group3') |
| 75 |
group3.delete() |
| 76 |
|
| 77 |
request.addfinalizer(fin) |
| 78 |
|
| 79 |
return group3 |
| 80 |
|
| 81 |
|
| 82 |
@pytest.fixture(scope='function') |
| 83 |
def supergroup(topology_st, request): |
| 84 |
groupname = 'supergroup' |
| 85 |
log.info('Create supergroup') |
| 86 |
groups = Groups(topology_st.standalone, DEFAULT_SUFFIX) |
| 87 |
if groups.exists(groupname): |
| 88 |
groups.get(groupname).delete() |
| 89 |
|
| 90 |
supergroup = groups.create(properties={'cn': groupname}) |
| 91 |
|
| 92 |
def fin(): |
| 93 |
if supergroup.exists(): |
| 94 |
log.info('Delete supergroup') |
| 95 |
supergroup.delete() |
| 96 |
|
| 97 |
request.addfinalizer(fin) |
| 98 |
|
| 99 |
return supergroup |
| 100 |
|
| 101 |
|
| 102 |
@pytest.fixture(scope='function') |
| 103 |
def user1(topology_st, request): |
| 104 |
username = 'user1' |
| 105 |
log.info('Create user1') |
| 106 |
users = UserAccounts(topology_st.standalone, DEFAULT_SUFFIX) |
| 107 |
if users.exists(username): |
| 108 |
users.get(username).delete() |
| 109 |
|
| 110 |
user1 = users.create(properties={'cn': username, |
| 111 |
'uid': username, |
| 112 |
'sn': username, |
| 113 |
'uidNumber': '1', |
| 114 |
'gidNumber': '11', |
| 115 |
'homeDirectory': f'/home/{username}'}) |
| 116 |
|
| 117 |
def fin(): |
| 118 |
if user1.exists(): |
| 119 |
log.info('Delete user1') |
| 120 |
user1.delete() |
| 121 |
|
| 122 |
request.addfinalizer(fin) |
| 123 |
|
| 124 |
return user1 |