Debian Codegraph @

neutron_fwaas/tests/unit/policies/test_firewall_policy.py

raw symbols SCIP
1 # Copyright (c) 2025 Red Hat Inc.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12 # implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 from oslo_policy import policy as base_policy
17
18 from neutron import policy
19 from neutron.tests.unit.conf.policies import test_base as base
20
21
22 class FirewallPolicyAPITestCase(base.PolicyBaseTestCase):
23
24 def setUp(self):
25 super().setUp()
26 self.target = {
27 'project_id': self.project_id,
28 'tenant_id': self.project_id}
29 self.alt_target = {
30 'project_id': self.alt_project_id,
31 'tenant_id': self.alt_project_id}
32
33
34 class SystemAdminTests(FirewallPolicyAPITestCase):
35
36 def setUp(self):
37 super().setUp()
38 self.context = self.system_admin_ctx
39
40 def test_create_firewall_policy(self):
41 self.assertRaises(
42 base_policy.InvalidScope,
43 policy.enforce, self.context, 'create_firewall_policy',
44 self.target)
45 self.assertRaises(
46 base_policy.InvalidScope,
47 policy.enforce, self.context, 'create_firewall_policy',
48 self.alt_target)
49
50 def test_update_firewall_policy(self):
51 self.assertRaises(
52 base_policy.InvalidScope,
53 policy.enforce, self.context, 'update_firewall_policy',
54 self.target)
55 self.assertRaises(
56 base_policy.InvalidScope,
57 policy.enforce, self.context, 'update_firewall_policy',
58 self.alt_target)
59
60 def test_delete_firewall_policy(self):
61 self.assertRaises(
62 base_policy.InvalidScope,
63 policy.enforce, self.context, 'delete_firewall_policy',
64 self.target)
65 self.assertRaises(
66 base_policy.InvalidScope,
67 policy.enforce, self.context, 'delete_firewall_policy',
68 self.alt_target)
69
70 def test_create_firewall_policy_shared(self):
71 self.assertRaises(
72 base_policy.InvalidScope,
73 policy.enforce, self.context, 'create_firewall_policy:shared',
74 self.target)
75 self.assertRaises(
76 base_policy.InvalidScope,
77 policy.enforce, self.context, 'create_firewall_policy:shared',
78 self.alt_target)
79
80 def test_update_firewall_policy_shared(self):
81 self.assertRaises(
82 base_policy.InvalidScope,
83 policy.enforce, self.context, 'update_firewall_policy:shared',
84 self.target)
85 self.assertRaises(
86 base_policy.InvalidScope,
87 policy.enforce, self.context, 'update_firewall_policy:shared',
88 self.alt_target)
89
90 def test_delete_firewall_policy_shared(self):
91 self.assertRaises(
92 base_policy.InvalidScope,
93 policy.enforce, self.context, 'delete_firewall_policy:shared',
94 self.target)
95 self.assertRaises(
96 base_policy.InvalidScope,
97 policy.enforce, self.context, 'delete_firewall_policy:shared',
98 self.alt_target)
99
100 def test_get_firewall_policy(self):
101 self.assertRaises(
102 base_policy.InvalidScope,
103 policy.enforce, self.context, 'get_firewall_policy', self.target)
104 self.assertRaises(
105 base_policy.InvalidScope,
106 policy.enforce, self.context, 'get_firewall_policy',
107 self.alt_target)
108
109
110 class SystemMemberTests(SystemAdminTests):
111
112 def setUp(self):
113 super().setUp()
114 self.context = self.system_member_ctx
115
116
117 class SystemReaderTests(SystemMemberTests):
118
119 def setUp(self):
120 super().setUp()
121 self.context = self.system_reader_ctx
122
123
124 class AdminTests(FirewallPolicyAPITestCase):
125
126 def setUp(self):
127 super().setUp()
128 self.context = self.project_admin_ctx
129
130 def test_create_firewall_policy(self):
131 self.assertTrue(
132 policy.enforce(
133 self.context, 'create_firewall_policy', self.target))
134 self.assertTrue(
135 policy.enforce(
136 self.context, 'create_firewall_policy', self.alt_target))
137
138 def test_update_firewall_policy(self):
139 self.assertTrue(
140 policy.enforce(
141 self.context, 'update_firewall_policy', self.target))
142 self.assertTrue(
143 policy.enforce(
144 self.context, 'update_firewall_policy', self.alt_target))
145
146 def test_delete_firewall_policy(self):
147 self.assertTrue(
148 policy.enforce(
149 self.context, 'delete_firewall_policy', self.target))
150 self.assertTrue(
151 policy.enforce(
152 self.context, 'delete_firewall_policy', self.alt_target))
153
154 def test_create_firewall_policy_shared(self):
155 self.assertTrue(
156 policy.enforce(
157 self.context, 'create_firewall_policy:shared', self.target))
158 self.assertTrue(
159 policy.enforce(
160 self.context, 'create_firewall_policy:shared',
161 self.alt_target))
162
163 def test_update_firewall_policy_shared(self):
164 self.assertTrue(
165 policy.enforce(
166 self.context, 'update_firewall_policy:shared', self.target))
167 self.assertTrue(
168 policy.enforce(
169 self.context, 'update_firewall_policy:shared',
170 self.alt_target))
171
172 def test_delete_firewall_policy_shared(self):
173 self.assertTrue(
174 policy.enforce(
175 self.context, 'delete_firewall_policy:shared', self.target))
176 self.assertTrue(
177 policy.enforce(
178 self.context, 'delete_firewall_policy:shared',
179 self.alt_target))
180
181 def test_get_firewall_policy(self):
182 self.assertTrue(
183 policy.enforce(self.context, 'get_firewall_policy', self.target))
184 self.assertTrue(
185 policy.enforce(
186 self.context, 'get_firewall_policy', self.alt_target))
187
188
189 class ProjectManagerTests(AdminTests):
190
191 def setUp(self):
192 super().setUp()
193 self.context = self.project_manager_ctx
194
195 def test_create_firewall_policy(self):
196 self.assertTrue(
197 policy.enforce(
198 self.context, 'create_firewall_policy', self.target))
199 self.assertRaises(
200 base_policy.PolicyNotAuthorized,
201 policy.enforce, self.context, 'create_firewall_policy',
202 self.alt_target)
203
204 def test_update_firewall_policy(self):
205 self.assertTrue(
206 policy.enforce(
207 self.context, 'update_firewall_policy', self.target))
208 self.assertRaises(
209 base_policy.PolicyNotAuthorized,
210 policy.enforce, self.context, 'update_firewall_policy',
211 self.alt_target)
212
213 def test_delete_firewall_policy(self):
214 self.assertTrue(
215 policy.enforce(
216 self.context, 'delete_firewall_policy', self.target))
217 self.assertRaises(
218 base_policy.PolicyNotAuthorized,
219 policy.enforce, self.context, 'delete_firewall_policy',
220 self.alt_target)
221
222 def test_create_firewall_policy_shared(self):
223 self.assertRaises(
224 base_policy.PolicyNotAuthorized,
225 policy.enforce, self.context, 'create_firewall_policy:shared',
226 self.target)
227 self.assertRaises(
228 base_policy.PolicyNotAuthorized,
229 policy.enforce, self.context, 'create_firewall_policy:shared',
230 self.alt_target)
231
232 def test_update_firewall_policy_shared(self):
233 self.assertRaises(
234 base_policy.PolicyNotAuthorized,
235 policy.enforce, self.context, 'update_firewall_policy:shared',
236 self.target)
237 self.assertRaises(
238 base_policy.PolicyNotAuthorized,
239 policy.enforce, self.context, 'create_firewall_policy:shared',
240 self.alt_target)
241
242 def test_delete_firewall_policy_shared(self):
243 self.assertRaises(
244 base_policy.PolicyNotAuthorized,
245 policy.enforce, self.context, 'delete_firewall_policy:shared',
246 self.target)
247 self.assertRaises(
248 base_policy.PolicyNotAuthorized,
249 policy.enforce, self.context, 'create_firewall_policy:shared',
250 self.alt_target)
251
252 def test_get_firewall_policy(self):
253 self.assertTrue(
254 policy.enforce(self.context, 'get_firewall_policy', self.target))
255 self.assertRaises(
256 base_policy.PolicyNotAuthorized,
257 policy.enforce, self.context, 'get_firewall_policy',
258 self.alt_target)
259
260
261 class ProjectMemberTests(ProjectManagerTests):
262
263 def setUp(self):
264 super().setUp()
265 self.context = self.project_member_ctx
266
267
268 class ProjectReaderTests(ProjectMemberTests):
269
270 def setUp(self):
271 super().setUp()
272 self.context = self.project_reader_ctx
273
274 def test_create_firewall_policy(self):
275 self.assertRaises(
276 base_policy.PolicyNotAuthorized,
277 policy.enforce, self.context, 'create_firewall_policy',
278 self.target)
279 self.assertRaises(
280 base_policy.PolicyNotAuthorized,
281 policy.enforce, self.context, 'create_firewall_policy',
282 self.alt_target)
283
284 def test_update_firewall_policy(self):
285 self.assertRaises(
286 base_policy.PolicyNotAuthorized,
287 policy.enforce, self.context, 'update_firewall_policy',
288 self.target)
289 self.assertRaises(
290 base_policy.PolicyNotAuthorized,
291 policy.enforce, self.context, 'update_firewall_policy',
292 self.alt_target)
293
294 def test_delete_firewall_policy(self):
295 self.assertRaises(
296 base_policy.PolicyNotAuthorized,
297 policy.enforce, self.context, 'delete_firewall_policy',
298 self.target)
299 self.assertRaises(
300 base_policy.PolicyNotAuthorized,
301 policy.enforce, self.context, 'delete_firewall_policy',
302 self.alt_target)
303
304
305 class ServiceRoleTests(FirewallPolicyAPITestCase):
306
307 def setUp(self):
308 super().setUp()
309 self.context = self.service_ctx
310
311 def test_create_firewall_policy(self):
312 self.assertRaises(
313 base_policy.PolicyNotAuthorized,
314 policy.enforce, self.context, 'create_firewall_policy',
315 self.target)
316
317 def test_update_firewall_policy(self):
318 self.assertRaises(
319 base_policy.PolicyNotAuthorized,
320 policy.enforce, self.context, 'update_firewall_policy',
321 self.target)
322
323 def test_delete_firewall_policy(self):
324 self.assertRaises(
325 base_policy.PolicyNotAuthorized,
326 policy.enforce, self.context, 'delete_firewall_policy',
327 self.target)
328
329 def test_create_firewall_policy_shared(self):
330 self.assertRaises(
331 base_policy.PolicyNotAuthorized,
332 policy.enforce, self.context, 'create_firewall_policy:shared',
333 self.target)
334
335 def test_update_firewall_policy_shared(self):
336 self.assertRaises(
337 base_policy.PolicyNotAuthorized,
338 policy.enforce, self.context, 'update_firewall_policy:shared',
339 self.target)
340
341 def test_delete_firewall_policy_shared(self):
342 self.assertRaises(
343 base_policy.PolicyNotAuthorized,
344 policy.enforce, self.context, 'delete_firewall_policy:shared',
345 self.target)
346
347 def test_get_firewall_policy(self):
348 self.assertRaises(
349 base_policy.PolicyNotAuthorized,
350 policy.enforce, self.context, 'get_firewall_policy',
351 self.target)