Debian Codegraph @

dirsrvtests/tests/suites/acl/conftest.py

raw
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 This is the config file for keywords test scripts.
11
12 """
13
14 import pytest
15
16 from lib389._constants import DEFAULT_SUFFIX, PW_DM
17 from lib389.idm.user import UserAccounts
18 from lib389.idm.organizationalunit import OrganizationalUnit, OrganizationalUnits
19 from test389.topologies import topology_st as topo
20 from lib389.idm.domain import Domain
21
22
23 @pytest.fixture(scope="function")
24 def aci_of_user(request, topo):
25 """
26 Removes and Restores ACIs after the test.
27 """
28 aci_list = Domain(topo.standalone, DEFAULT_SUFFIX).get_attr_vals_utf8('aci')
29
30 def finofaci():
31 """
32 Removes and Restores ACIs after the test.
33 """
34 domain = Domain(topo.standalone, DEFAULT_SUFFIX)
35 domain.remove_all('aci')
36 for aci in aci_list:
37 domain.add("aci", aci)
38
39 request.addfinalizer(finofaci)
40
41
42 @pytest.fixture(scope="module")
43 def add_user(request, topo):
44 """
45 This function will create user for the test and in the end entries will be deleted .
46 """
47 ous_origin = OrganizationalUnits(topo.standalone, DEFAULT_SUFFIX)
48 ou_origin = ous_origin.create(properties={'ou': 'Keywords'})
49
50 ous_next = OrganizationalUnits(topo.standalone, ou_origin.dn)
51 for ou in ['Authmethod', 'Dayofweek', 'DNS', 'IP', 'Timeofday']:
52 ous_next.create(properties={'ou': ou})
53
54 users_day_of_week = UserAccounts(topo.standalone, f"ou=Dayofweek,ou=Keywords,{DEFAULT_SUFFIX}", rdn=None)
55 for user in ['EVERYDAY_KEY', 'TODAY_KEY', 'NODAY_KEY']:
56 users_day_of_week.create(properties={
57 'uid': user,
58 'cn': user,
59 'sn': 'user',
60 'uidNumber': '1000',
61 'gidNumber': '2000',
62 'homeDirectory': '/home/' + user,
63 'userPassword': PW_DM
64 })
65
66 users_ip = UserAccounts(topo.standalone, f"ou=IP,ou=Keywords,{DEFAULT_SUFFIX}", rdn=None)
67 for user in ['FULLIP_KEY', 'NETSCAPEIP_KEY', 'NOIP_KEY']:
68 users_ip.create(properties={
69 'uid': user,
70 'cn': user,
71 'sn': 'user',
72 'uidNumber': '1000',
73 'gidNumber': '2000',
74 'homeDirectory': '/home/' + user,
75 'userPassword': PW_DM
76 })
77
78 users_timeof_day = UserAccounts(topo.standalone, f"ou=Timeofday,ou=Keywords,{DEFAULT_SUFFIX}", rdn=None)
79 for user in ['FULLWORKER_KEY', 'DAYWORKER_KEY', 'NOWORKER_KEY', 'NIGHTWORKER_KEY']:
80 users_timeof_day.create(properties={
81 'uid': user,
82 'cn': user,
83 'sn': 'user',
84 'uidNumber': '1000',
85 'gidNumber': '2000',
86 'homeDirectory': '/home/' + user,
87 'userPassword': PW_DM
88 })
89
90 users_authmethod = UserAccounts(topo.standalone, f"ou=Authmethod,ou=Keywords,{DEFAULT_SUFFIX}", rdn=None)
91 for user in ['NONE_1_KEY', 'NONE_2_KEY', 'SIMPLE_1_KEY']:
92 users_authmethod.create(properties={
93 'uid': user,
94 'cn': user,
95 'sn': 'user',
96 'uidNumber': '1000',
97 'gidNumber': '2000',
98 'homeDirectory': '/home/' + user,
99 'userPassword': PW_DM
100 })
101
102 users_dns = UserAccounts(topo.standalone, f"ou=DNS,ou=Keywords,{DEFAULT_SUFFIX}", rdn=None)
103 for user in ['FULLDNS_KEY', 'SUNDNS_KEY', 'NODNS_KEY', 'NETSCAPEDNS_KEY']:
104 users_dns.create(properties={
105 'uid': user,
106 'cn': user,
107 'sn': 'user',
108 'uidNumber': '1000',
109 'gidNumber': '2000',
110 'homeDirectory': '/home/' + user,
111 'userPassword': PW_DM
112 })
113
114 def fin():
115 """
116 Deletes entries after the test.
117 """
118 for user in users_day_of_week.list() + users_ip.list() + users_timeof_day.list() + \
119 users_authmethod.list() + users_dns.list():
120 user.delete()
121
122 for ou in sorted(ous_next.list(), key=lambda x: len(x.dn), reverse=True):
123 ou.delete()
124
125 request.addfinalizer(fin)