Debian Codegraph @

dirsrvtests/tests/suites/plugins/dna_interval_test.py

raw
1 # --- BEGIN COPYRIGHT BLOCK ---
2 # Copyright (C) 2021 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 """Test DNA plugin functionality"""
10
11 import logging
12 import pytest
13 from lib389._constants import DEFAULT_SUFFIX
14 from lib389.plugins import DNAPlugin, DNAPluginConfigs
15 from lib389.idm.organizationalunit import OrganizationalUnits
16 from lib389.idm.user import UserAccounts
17 from test389.topologies import topology_st
18 from lib389.utils import *
19
20 pytestmark = pytest.mark.tier1
21
22 log = logging.getLogger(__name__)
23
24
25 @pytest.fixture(scope="function")
26 def dna_plugin(topology_st, request):
27 inst = topology_st.standalone
28 plugin = DNAPlugin(inst)
29 ous = OrganizationalUnits(inst, DEFAULT_SUFFIX)
30 ou_people = ous.get("People")
31
32 log.info("Add dna plugin config entry...")
33 configs = DNAPluginConfigs(inst, plugin.dn)
34 dna_config = configs.create(properties={'cn': 'dna config',
35 'dnaType': 'uidNumber',
36 'dnaMaxValue': '1000',
37 'dnaMagicRegen': '-1',
38 'dnaFilter': '(objectclass=top)',
39 'dnaScope': ou_people.dn,
40 'dnaNextValue': '10',
41 'dnaInterval': '10'})
42
43 log.info("Enable the DNA plugin and restart...")
44 plugin.enable()
45 inst.restart()
46
47 def fin():
48 inst.stop()
49 dse_ldif = DSEldif(inst)
50 dse_ldif.delete_dn(f'cn=dna config,{plugin.dn}')
51 inst.start()
52 request.addfinalizer(fin)
53
54 return dna_config
55
56
57 def test_dna_interval(topology_st, dna_plugin):
58 """Test the dna interval works
59
60 :id: 3982d698-e16b-4945-9eb4-eecaa4bac5f7
61 :customerscenario: True
62 :setup: Standalone Instance
63 :steps:
64 1. Set DNAZZ interval to 10
65 2. Create user that trigger DNA to assign a value
66 3. Verify DNA is working
67 4. Make update to entry that triggers DNA again
68 5. Verify interval is applied as expected
69 :expectedresults:
70 1. Success
71 2. Success
72 3. Success
73 4. Success
74 5. Success
75 """
76
77 # Create user and check interval
78 log.info("Test DNA is working...")
79 users = UserAccounts(topology_st.standalone, DEFAULT_SUFFIX)
80 log.info('Adding user1')
81 user = users.create(properties={
82 'sn': 'interval',
83 'cn': 'interval',
84 'uid': 'interval',
85 'uidNumber': '-1', # Magic regen value
86 'gidNumber': '111',
87 'givenname': 'interval',
88 'homePhone': '0861234567',
89 'carLicense': '131D16674',
90 'mail': '[email protected]',
91 'homeDirectory': '/home/interval'})
92
93 # Verify DNA works
94 assert user.get_attr_val_utf8_l('uidNumber') == '10'
95
96 # Make update and verify interval was applied
97 log.info("Test DNA interval assignment is working...")
98 user.replace('uidNumber', '-1')
99 assert user.get_attr_val_utf8_l('uidNumber') == '20'
100
101
102 def test_dna_max_value(topology_st, dna_plugin):
103 """Test the dna max value works with dna interval
104
105 :id: cc979ea8-3cd0-4d52-af35-9cea7cf8cb5f
106 :customerscenario: True
107 :setup: Standalone Instance
108 :steps:
109 1. Set dnaMaxValue, dnaNextValue, dnaInterval values to 100, 90, 50 respectively
110 2. Create user that trigger DNA to assign a value
111 3. Try to make an update to entry that triggers DNA again
112 :expectedresults:
113 1. Success
114 2. Success
115 3. Operation should fail with OPERATIONS_ERROR
116 """
117 log.info("Make the config changes needed to test dnaMaxValue")
118 dna_plugin.replace_many(('dnaMaxValue', '100'), ('dnaNextValue', '90'), ('dnaInterval', '50'))
119 # Create user2
120 users = UserAccounts(topology_st.standalone, DEFAULT_SUFFIX)
121 log.info('Adding user2')
122 user = users.create(properties={
123 'sn': 'interval2',
124 'cn': 'interval2',
125 'uid': 'interval2',
126 'uidNumber': '-1', # Magic regen value
127 'gidNumber': '222',
128 'givenname': 'interval2',
129 'homePhone': '0861234567',
130 'carLicense': '131D16674',
131 'mail': '[email protected]',
132 'homeDirectory': '/home/interval2'})
133
134 # Verify DNA works
135 assert user.get_attr_val_utf8_l('uidNumber') == '90'
136
137 log.info("Make an update and verify it raises error as the new interval value is more than dnaMaxValue")
138 with pytest.raises(ldap.OPERATIONS_ERROR):
139 user.replace('uidNumber', '-1')
140
141
142 @pytest.mark.parametrize('attr_value', ('0', 'abc', '2000'))
143 def test_dna_interval_with_different_values(topology_st, dna_plugin, attr_value):
144 """Test the dna interval with different values
145
146 :id: 1a3f69fd-1d8d-4046-ba68-b6aa7cafbd37
147 :customerscenario: True
148 :parametrized: yes
149 :setup: Standalone Instance
150 :steps:
151 1. Set dnaInterval value to 0
152 2. Set dnaInterval value to 'abc'
153 3. Set dnaInterval value to 2000 and dnaMaxValue to 1000
154 4. Create user that trigger DNA to assign a value
155 5. Try to make an update to entry that triggers DNA again when dnaInerval is greater than dnaMaxValue
156 :expectedresults:
157 1. Success
158 2. Operation should fail with INVALID_SYNTAX
159 3. Success
160 4. Success
161 5. Operation should fail with OPERATIONS_ERROR
162 """
163 log.info("Make the config changes needed to test dnaInterval")
164 if attr_value == '0':
165 dna_plugin.replace('dnaInterval', attr_value)
166 elif attr_value == 'abc':
167 with pytest.raises(ldap.INVALID_SYNTAX):
168 dna_plugin.replace('dnaInterval', attr_value)
169 else:
170 dna_plugin.replace_many(('dnaInterval', attr_value), ('dnaMaxValue', '1000'))
171 # Create user3
172 users = UserAccounts(topology_st.standalone, DEFAULT_SUFFIX)
173 log.info('Adding user3')
174 user = users.create(properties={
175 'sn': 'interval3',
176 'cn': 'interval3',
177 'uid': 'interval3',
178 'uidNumber': '-1', # Magic regen value
179 'gidNumber': '333',
180 'givenname': 'interval3',
181 'homePhone': '0861234567',
182 'carLicense': '131D16674',
183 'mail': '[email protected]',
184 'homeDirectory': '/home/interval3'})
185
186 # Verify DNA works
187 assert user.get_attr_val_utf8_l('uidNumber') == '10'
188
189 log.info("Make an update and verify it raises error as the new interval value is more than dnaMaxValue")
190 with pytest.raises(ldap.OPERATIONS_ERROR):
191 user.replace('uidNumber', '-1')
192
193 # Check that instance did not crashed
194 assert topology_st.standalone.status()