Debian Codegraph @

dirsrvtests/tests/suites/acl/syntax_test.py

raw
1 # --- BEGIN COPYRIGHT BLOCK ---
2 # Copyright (C) 2020 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 pytest
11 from lib389._constants import DEFAULT_SUFFIX
12 from lib389.idm.domain import Domain
13 from test389.topologies import topology_st as topo
14 from lib389.utils import ds_is_older
15
16 import ldap
17
18 pytestmark = pytest.mark.tier1
19
20 INVALID = [('test_targattrfilters_1',
21 f'(targattrfilters ="add=title:title=fred),del=cn:(cn!=harry)")'
22 f'(version 3.0; acl "Name of the ACI"; deny absolute (all)userdn="ldap:///anyone";)'),
23 ('test_targattrfilters_2',
24 f'(targattrfilters ="add=:(title=fred),del=cn:(cn!=harry)")'
25 f'(version 3.0; acl "Name of the ACI"; deny absolute (all)userdn="ldap:///anyone";)'),
26 ('test_targattrfilters_3',
27 f'(targattrfilters ="add=:(title=fred),del=cn:(cn!=harry))'
28 f'(version 3.0; acl "Name of the ACI"; deny absolute (all)userdn="ldap:///anyone";)'),
29 ('test_targattrfilters_4',
30 f'(targattrfilters ="add=title:(title=fred),=cn:(cn!=harry")'
31 f'(version 3.0; acl "Name of the ACI"; deny absolute (all)userdn="ldap:///anyone";)'),
32 ('test_targattrfilters_5',
33 f'(targattrfilters ="add=title:(|(title=fred)(cn=harry)),del=cn:(cn=harry)")'
34 f'(version 3.0; acl "Name of the ACI"; deny absolute (all)userdn="ldap:///anyone";)'),
35 ('test_targattrfilters_6',
36 f'(targattrfilters ="add=title:(|(title=fred)(title=harry)),del=cn:(title=harry)")'
37 f'(version 3.0; acl "Name of the ACI"; deny absolute (all)userdn="ldap:///anyone";)'),
38 ('test_targattrfilters_7',
39 f'(targattrfilters ="add=title:(cn=architect), '
40 f'del=title:(title=architect) && l:(l=cn=Meylan,dc=example,dc=com")")'
41 f'(version 3.0; acl "Name of the ACI"; deny absolute (all)userdn="ldap:///anyone";)'),
42 ('test_targattrfilters_8',
43 f'(targattrfilters ="add=title:(cn=architect)")'
44 f'(version 3.0; acl "Name of the ACI"; deny absolute (all)userdn="ldap:///anyone";)'),
45 ('test_targattrfilters_9',
46 f'(targattrfilters ="add=title:(cn=arch*)")'
47 f'(version 3.0; acl "Name of the ACI"; deny absolute (all)userdn="ldap:///anyone";)'),
48 ('test_targattrfilters_10',
49 f'(targattrfilters ="add=title:(cn >= 1)")'
50 f'(version 3.0; acl "Name of the ACI"; deny absolute (all)userdn="ldap:///anyone";)'),
51 ('test_targattrfilters_11',
52 f'(targattrfilters ="add=title:(cn <= 1)")'
53 f'(version 3.0; acl "Name of the ACI"; deny absolute (all)userdn="ldap:///anyone";)'),
54 ('test_targattrfilters_12',
55 f'(targattrfilters ="add=title:(cn ~= 1)")'
56 f'(version 3.0; acl "Name of the ACI"; deny absolute (all)userdn="ldap:///anyone";)'),
57 ('test_targattrfilters_13',
58 f'(targattrfilters ="add=title:(!(cn ~= 1))")'
59 f'(version 3.0; acl "Name of the ACI"; deny absolute (all)userdn="ldap:///anyone";)'),
60 ('test_targattrfilters_14',
61 f'(targattrfilters ="add=title:(&(cn=fred)(cn ~= 1))")'
62 f'(version 3.0; acl "Name of the ACI"; deny absolute (all)userdn="ldap:///anyone";)'),
63 ('test_targattrfilters_15',
64 f'(targattrfilters ="add=title:(|(cn=fred)(cn ~= 1))")'
65 f'(version 3.0; acl "Name of the ACI"; deny absolute (all)userdn="ldap:///anyone";)'),
66 ('test_targattrfilters_16',
67 f'(targattrfilters ="add=title:(&(|(title=fred)(title=harry))(cn ~= 1))")'
68 f'(version 3.0; acl "Name of the ACI"; deny absolute (all)userdn="ldap:///anyone";)'),
69 ('test_targattrfilters_17',
70 f'\(targattrfilters ="add=title:(&(|(&(title=harry)(title=fred))'
71 f'(title=harry))(title ~= 1))")'
72 f'(version 3.0; acl "Name of the ACI"; deny absolute (all)userdn="ldap:///anyone";)'),
73 ('test_targattrfilters_19',
74 f'(target = ldap:///cn=Jeff Vedder,ou=Product Development,{DEFAULT_SUFFIX})'
75 f'(targetattr="*")'
76 f'(version 3.0; acl "Name of the ACI"; deny(write)gropdn="ldap:///anyone";)'),
77 ('test_targattrfilters_21',
78 f'(target = ldap:///cn=Jeff Vedder,ou=Product Development,{DEFAULT_SUFFIX})'
79 f'(targetattr="*")'
80 f'(version 3.0; acl "Name of the ACI"; deny(rite)userdn="ldap:///anyone";)'),
81 ('test_targattrfilters_22',
82 f'(targt = ldap:///cn=Jeff Vedder,ou=Product Development,{DEFAULT_SUFFIX})'
83 f'(targetattr="*")'
84 f'(version 3.0; acl "Name of the ACI"; deny absolute (all)userdn="ldap:///anyone";)'),
85 ('test_targattrfilters_23',
86 f'(target = ldap:///cn=Jeff Vedder,ou=Product Development,{DEFAULT_SUFFIX})'
87 f'(targetattr="*")'
88 f'(version 3.0; acl "Name of the ACI"; absolute (all)userdn="ldap:///anyone";)'),
89 ('test_Missing_acl_mispel',
90 f'(target = ldap:///cn=Jeff Vedder,ou=Product Development,{DEFAULT_SUFFIX})'
91 f'(targetattr="*")'
92 f'(version 3.0; alc "Name of the ACI"; deny absolute (all)userdn="ldap:///anyone";)'),
93 ('test_Missing_acl_string',
94 f'(target = ldap:///cn=Jeff Vedder,ou=Product Development,{DEFAULT_SUFFIX})'
95 f'(targetattr="*")'
96 f'(version 3.0; "Name of the ACI"; deny absolute (all)userdn="ldap:///anyone";)'),
97 ('test_Wrong_version_string',
98 f'(target = ldap:///cn=Jeff Vedder,ou=Product Development,{DEFAULT_SUFFIX})'
99 f'(targetattr="*")'
100 f'(version 2.0; acl "Name of the ACI"; deny absolute (all)userdn="ldap:///anyone";)'),
101 ('test_Missing_version_string',
102 f'(target = ldap:///cn=Jeff Vedder,ou=Product Development,{DEFAULT_SUFFIX})'
103 f'(targetattr="*")'
104 f'(; acl "Name of the ACI"; deny absolute (all)userdn="ldap:///anyone";)'),
105 ('test_Authenticate_statement',
106 f'(target = ldap:///cn=Jeff Vedder,ou=Product Development,{DEFAULT_SUFFIX})'
107 f'(targetattr != "uid")'
108 f'(targetattr="*")(version 3.0; acl "Name of the ACI"; deny absolute (all)'
109 f'userdn="ldap:///anyone";)'),
110 ('test_Multiple_targets',
111 f'(target = ldap:///ou=Product Development,{DEFAULT_SUFFIX})'
112 f'(target = ldap:///ou=Product Testing,{DEFAULT_SUFFIX})(targetattr="*")'
113 f'(version 3.0; acl "Name of the ACI"; deny absolute (all)userdn="ldap:///anyone";)'),
114 ('test_Target_set_to_self',
115 f'(target = ldap:///self)(targetattr="*")'
116 f'(version 3.0; acl "Name of the ACI"; deny absolute (all)userdn="ldap:///anyone";)'),
117 ('test_target_set_with_ldap_instead_of_ldap',
118 f'(target = ldap:\\\{DEFAULT_SUFFIX})(targetattr="*")'
119 f'(version 3.0; acl "Name of the ACI"; deny absolute (all)userdn="ldap:///anyone";)'),
120 ('test_target_set_with_more_than_three',
121 f'(target = ldap:////{DEFAULT_SUFFIX})(targetattr="*")'
122 f'(version 3.0; acl "Name of the ACI"; deny absolute (all)userdn="ldap:///anyone";)'),
123 ('test_target_set_with_less_than_three',
124 f'(target = ldap://{DEFAULT_SUFFIX})(targetattr="*")'
125 f'(version 3.0; acl "Name of the ACI"; deny absolute (all)userdn="ldap:///anyone";)'),
126 ('test_bind_rule_set_with_less_than_three',
127 f'(target = ldap:///{DEFAULT_SUFFIX})(targetattr="*")'
128 f'(version 3.0; acl "Name of the ACI"; deny absolute (all)userdn="ldap:/anyone";)'),
129 ('test_Use_semicolon_instead_of_comma_in_permission',
130 f'(target = ldap:///{DEFAULT_SUFFIX})(targetattr="*")'
131 f'(version 3.0; acl "Name of the ACI"; deny '
132 f'(read; search; compare; write)userdn="ldap:///anyone";)'),
133 ('test_Use_double_equal_instead_of_equal_in_the_target',
134 f'(target == ldap:///{DEFAULT_SUFFIX})(targetattr="*")'
135 f'(version 3.0; acl "Name of the ACI"; deny absolute (all)userdn="ldap:///anyone";)'),
136 ('test_use_double_equal_instead_of_equal_in_user_and_group_access',
137 f'(target = ldap:///{DEFAULT_SUFFIX})'
138 f'(version 3.0; acl "Name of the ACI"; deny absolute (all)'
139 f'userdn == "ldap:///anyone";)'),
140 ('test_donot_cote_the_name_of_the_aci',
141 f'(target = ldap:///{DEFAULT_SUFFIX})'
142 f'(version 3.0; acl Name of the ACI ; deny absolute (all)userdn = "ldap:///anyone";)'),
143 ('test_extra_parentheses_case_1',
144 f'( )(target = ldap:///{DEFAULT_SUFFIX}) (targetattr="*")'
145 f'(version 3.0; acl "Name of the ACI"; deny absolute (all)userdn = "ldap:///anyone";)'),
146 ('test_extra_parentheses_case_2',
147 f'(((((target = ldap:///{DEFAULT_SUFFIX})(targetattr="*")'
148 f'(version 3.0; acl "Name of the ACI"; deny absolute (all)'
149 f'userdn == "ldap:///anyone";)'),
150 ('test_extra_parentheses_case_3',
151 f'(((target = ldap:///{DEFAULT_SUFFIX}) (targetattr="*")'
152 f'(version 3.0; acl "Name of the ACI"; deny absolute '
153 f'(all)userdn = "ldap:///anyone";)))'),
154 ('test_no_semicolon_at_the_end_of_the_aci',
155 f'(target = ldap:///{DEFAULT_SUFFIX}) (targetattr="*")'
156 f'(version 3.0; acl "Name of the ACI"; deny absolute (all)userdn = "ldap:///anyone")'),
157 ('test_a_character_different_of_a_semicolon_at_the_end_of_the_aci',
158 f'(target = ldap:///{DEFAULT_SUFFIX}) (targetattr="*")'
159 f'(version 3.0; acl "Name of the ACI"; deny absolute (all)userdn = "ldap:///anyone"%)'),
160 ('test_bad_filter',
161 f'(target = ldap:///{DEFAULT_SUFFIX}) '
162 f'(targetattr="cn |&| sn |(|) uid")'
163 f'(version 3.0; acl "Name of the ACI"; deny absolute (all)userdn = "ldap:///anyone";)'),
164 ('test_Use_double_equal_instead_of_equal_in_the_targattrfilters',
165 f'(target = ldap:///{DEFAULT_SUFFIX})(targattrfilters== "add=title:(title=architect)")'
166 f'(version 3.0; acl "Name of the ACI"; deny absolute (all)userdn="ldap:///anyone";)'),
167 ('test_Use_double_equal_instead_of_equal_inside_the_targattrfilters',
168 f'(target = ldap:///{DEFAULT_SUFFIX})(targattrfilters="add==title:(title==architect)")'
169 f'(version 3.0; acl "Name of the ACI"; deny absolute (all)userdn="ldap:///anyone";)'),]
170
171
172 FAILED = [('test_targattrfilters_18',
173 f'(target = ldap:///cn=Jeff Vedder,ou=Product Development,{DEFAULT_SUFFIX})'
174 f'(targetattr="*")'
175 f'(version 3.0; acl "Name of the ACI"; deny(write)userdn="ldap:///{"123" * 300}";)'),
176 ('test_targattrfilters_20',
177 f'(target = ldap:///cn=Jeff Vedder,ou=Product Development,{DEFAULT_SUFFIX})'
178 f'(targetattr="*")'
179 f'(version 3.0; acl "Name of the ACI"; deny(write)userdns="ldap:///anyone";)'),
180 ('test_bind_rule_set_with_more_than_three',
181 f'(target = ldap:///{DEFAULT_SUFFIX})(targetattr="*")'
182 f'(version 3.0; acl "Name of the ACI"; deny absolute (all)'
183 f'userdn="ldap:////////anyone";)'),
184 ('test_Use_double_equal_instead_of_equal_in_the_targetattr',
185 f'(target = ldap:///{DEFAULT_SUFFIX})(targetattr==*)'
186 f'(version 3.0; acl "Name of the ACI"; deny absolute (all)userdn="ldap:///anyone";)'),
187 ('test_Use_double_equal_instead_of_equal_in_the_targetfilter',
188 f'(target = ldap:///{DEFAULT_SUFFIX})(targetfilter==*)'
189 f'(version 3.0; acl "Name of the ACI"; deny absolute '
190 f'(all)userdn="ldap:///anyone";)'), ]
191
192
193 @pytest.mark.parametrize("real_value", [a[1] for a in FAILED],
194 ids=[a[0] for a in FAILED])
195 def test_aci_invalid_syntax_fail(topo, real_value, request):
196 """Try to set wrong ACI syntax.
197
198 :id: 83c40784-fff5-49c8-9535-7064c9c19e7e
199 :parametrized: yes
200 :setup: Standalone Instance
201 :steps:
202 1. Create ACI
203 2. Try to setup the ACI with Instance
204 :expectedresults:
205 1. It should pass
206 2. It should not pass
207 """
208 # Mark specific test cases as xfail
209 xfail_cases = [
210 'test_targattrfilters_18',
211 'test_targattrfilters_20',
212 'test_bind_rule_set_with_more_than_three'
213 ]
214
215 if request.node.callspec.id in xfail_cases:
216 pytest.xfail("DS6913 - This test case is expected to fail")
217
218 domain = Domain(topo.standalone, DEFAULT_SUFFIX)
219 with pytest.raises(ldap.INVALID_SYNTAX):
220 domain.add("aci", real_value)
221
222
223 @pytest.mark.parametrize("real_value", [a[1] for a in INVALID],
224 ids=[a[0] for a in INVALID])
225 def test_aci_invalid_syntax(topo, real_value):
226 """Try to set wrong ACI syntax.
227
228 :id: e8bf20b6-48be-4574-8300-056e42a0f0a8
229 :parametrized: yes
230 :setup: Standalone Instance
231 :steps:
232 1. Create ACI
233 2. Try to setup the ACI with Instance
234 :expectedresults:
235 1. It should pass
236 2. It should not pass
237 """
238 domain = Domain(topo.standalone, DEFAULT_SUFFIX)
239 with pytest.raises(ldap.INVALID_SYNTAX):
240 domain.add("aci", real_value)
241
242
243 def test_target_set_above_the_entry_test(topo):
244 """
245 Try to set wrong ACI syntax.
246
247 :id: d544d09a-6ed1-11e8-8872-8c16451d917b
248 :setup: Standalone Instance
249 :steps:
250 1. Create ACI
251 2. Try to setup the ACI with Instance
252 :expectedresults:
253 1. It should pass
254 2. It should not pass
255 """
256 domain = Domain(topo.standalone, "ou=People,{}".format(DEFAULT_SUFFIX))
257 with pytest.raises(ldap.INVALID_SYNTAX):
258 domain.add("aci", f'(target = ldap:///{DEFAULT_SUFFIX})'
259 f'(targetattr="*")(version 3.0; acl "Name of the ACI"; deny absolute '
260 f'(all)userdn="ldap:///anyone";)')
261
262
263 if __name__ == "__main__":
264 CURRENT_FILE = os.path.realpath(__file__)
265 pytest.main("-s -v %s" % CURRENT_FILE)