Debian Codegraph @

neutron_dynamic_routing/tests/unit/policies/test_bgp_dragent.py

raw
1 # Copyright (c) Ericsson Software Technology 2025 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 BGPDragentAPITestCase(base.PolicyBaseTestCase):
23
24 def setUp(self):
25 super().setUp()
26 self.target = {
27 'project_id': self.project_id,
28 }
29 self.alt_target = {
30 'project_id': self.alt_project_id,
31 }
32
33
34 class SystemAdminTests(BGPDragentAPITestCase):
35
36 def setUp(self):
37 super().setUp()
38 self.context = self.system_admin_ctx
39
40 def test_add_bgp_speaker_to_dragent(self):
41 self.assertRaises(
42 base_policy.InvalidScope,
43 policy.enforce, self.context, 'add_bgp_speaker_to_dragent',
44 self.target)
45 self.assertRaises(
46 base_policy.InvalidScope,
47 policy.enforce, self.context, 'add_bgp_speaker_to_dragent',
48 self.alt_target)
49
50 def test_remove_bgp_speaker_from_dragent(self):
51 self.assertRaises(
52 base_policy.InvalidScope,
53 policy.enforce, self.context, 'remove_bgp_speaker_from_dragent',
54 self.target)
55 self.assertRaises(
56 base_policy.InvalidScope,
57 policy.enforce, self.context, 'remove_bgp_speaker_from_dragent',
58 self.alt_target)
59
60 def test_list_bgp_speaker_on_dragent(self):
61 self.assertRaises(
62 base_policy.InvalidScope,
63 policy.enforce, self.context, 'list_bgp_speaker_on_dragent',
64 self.target)
65 self.assertRaises(
66 base_policy.InvalidScope,
67 policy.enforce, self.context, 'list_bgp_speaker_on_dragent',
68 self.alt_target)
69
70 def test_list_dragent_hosting_bgp_speaker(self):
71 self.assertRaises(
72 base_policy.InvalidScope,
73 policy.enforce, self.context, 'list_dragent_hosting_bgp_speaker',
74 self.target)
75 self.assertRaises(
76 base_policy.InvalidScope,
77 policy.enforce, self.context, 'list_dragent_hosting_bgp_speaker',
78 self.alt_target)
79
80
81 class SystemMemberTests(SystemAdminTests):
82
83 def setUp(self):
84 super().setUp()
85 self.context = self.system_member_ctx
86
87
88 class SystemReaderTests(SystemMemberTests):
89
90 def setUp(self):
91 super().setUp()
92 self.context = self.system_reader_ctx
93
94
95 class AdminTests(BGPDragentAPITestCase):
96
97 def setUp(self):
98 super().setUp()
99 self.context = self.project_admin_ctx
100
101 def test_add_bgp_speaker_to_dragent(self):
102 self.assertTrue(
103 policy.enforce(
104 self.context, 'add_bgp_speaker_to_dragent', self.target))
105 self.assertTrue(
106 policy.enforce(
107 self.context, 'add_bgp_speaker_to_dragent', self.alt_target))
108
109 def test_remove_bgp_speaker_from_dragent(self):
110 self.assertTrue(
111 policy.enforce(
112 self.context, 'remove_bgp_speaker_from_dragent', self.target))
113 self.assertTrue(
114 policy.enforce(
115 self.context, 'remove_bgp_speaker_from_dragent',
116 self.alt_target))
117
118 def test_list_bgp_speaker_on_dragent(self):
119 self.assertTrue(
120 policy.enforce(
121 self.context, 'list_bgp_speaker_on_dragent', self.target))
122 self.assertTrue(
123 policy.enforce(
124 self.context, 'list_bgp_speaker_on_dragent', self.alt_target))
125
126 def test_list_dragent_hosting_bgp_speaker(self):
127 self.assertTrue(
128 policy.enforce(
129 self.context, 'list_dragent_hosting_bgp_speaker',
130 self.target))
131 self.assertTrue(
132 policy.enforce(
133 self.context, 'list_dragent_hosting_bgp_speaker',
134 self.alt_target))
135
136
137 class ProjectManagerTests(BGPDragentAPITestCase):
138
139 def setUp(self):
140 super().setUp()
141 self.context = self.project_manager_ctx
142
143 def test_add_bgp_speaker_to_dragent(self):
144 self.assertRaises(
145 base_policy.PolicyNotAuthorized,
146 policy.enforce, self.context, 'add_bgp_speaker_to_dragent',
147 self.target)
148 self.assertRaises(
149 base_policy.PolicyNotAuthorized,
150 policy.enforce, self.context, 'add_bgp_speaker_to_dragent',
151 self.alt_target)
152
153 def test_remove_bgp_speaker_from_dragent(self):
154 self.assertRaises(
155 base_policy.PolicyNotAuthorized,
156 policy.enforce, self.context, 'remove_bgp_speaker_from_dragent',
157 self.target)
158 self.assertRaises(
159 base_policy.PolicyNotAuthorized,
160 policy.enforce, self.context, 'remove_bgp_speaker_from_dragent',
161 self.alt_target)
162
163 def test_list_bgp_speaker_on_dragent(self):
164 self.assertRaises(
165 base_policy.PolicyNotAuthorized,
166 policy.enforce, self.context, 'list_bgp_speaker_on_dragent',
167 self.target)
168 self.assertRaises(
169 base_policy.PolicyNotAuthorized,
170 policy.enforce, self.context, 'list_bgp_speaker_on_dragent',
171 self.alt_target)
172
173 def test_list_dragent_hosting_bgp_speaker(self):
174 self.assertRaises(
175 base_policy.PolicyNotAuthorized,
176 policy.enforce, self.context, 'list_dragent_hosting_bgp_speaker',
177 self.target)
178 self.assertRaises(
179 base_policy.PolicyNotAuthorized,
180 policy.enforce, self.context, 'list_dragent_hosting_bgp_speaker',
181 self.alt_target)
182
183
184 class ProjectMemberTests(ProjectManagerTests):
185
186 def setUp(self):
187 super().setUp()
188 self.context = self.project_member_ctx
189
190
191 class ProjectReaderTests(ProjectMemberTests):
192
193 def setUp(self):
194 super().setUp()
195 self.context = self.project_reader_ctx
196
197 def test_add_bgp_speaker_to_dragent(self):
198 self.assertRaises(
199 base_policy.PolicyNotAuthorized,
200 policy.enforce, self.context, 'add_bgp_speaker_to_dragent',
201 self.target)
202 self.assertRaises(
203 base_policy.PolicyNotAuthorized,
204 policy.enforce, self.context, 'add_bgp_speaker_to_dragent',
205 self.alt_target)
206
207 def test_remove_bgp_speaker_from_dragent(self):
208 self.assertRaises(
209 base_policy.PolicyNotAuthorized,
210 policy.enforce, self.context, 'remove_bgp_speaker_from_dragent',
211 self.target)
212 self.assertRaises(
213 base_policy.PolicyNotAuthorized,
214 policy.enforce, self.context, 'remove_bgp_speaker_from_dragent',
215 self.alt_target)
216
217 def test_list_bgp_speaker_on_dragent(self):
218 self.assertRaises(
219 base_policy.PolicyNotAuthorized,
220 policy.enforce, self.context, 'list_bgp_speaker_on_dragent',
221 self.target)
222 self.assertRaises(
223 base_policy.PolicyNotAuthorized,
224 policy.enforce, self.context, 'list_bgp_speaker_on_dragent',
225 self.alt_target)
226
227 def test_list_dragent_hosting_bgp_speaker(self):
228 self.assertRaises(
229 base_policy.PolicyNotAuthorized,
230 policy.enforce, self.context, 'list_dragent_hosting_bgp_speaker',
231 self.target)
232 self.assertRaises(
233 base_policy.PolicyNotAuthorized,
234 policy.enforce, self.context, 'list_dragent_hosting_bgp_speaker',
235 self.alt_target)
236
237
238 class ServiceRoleTests(BGPDragentAPITestCase):
239
240 def setUp(self):
241 super().setUp()
242 self.context = self.service_ctx
243
244 def test_add_bgp_speaker_to_dragent(self):
245 self.assertRaises(
246 base_policy.PolicyNotAuthorized,
247 policy.enforce, self.context, 'add_bgp_speaker_to_dragent',
248 self.target)
249
250 def test_remove_bgp_speaker_from_dragent(self):
251 self.assertRaises(
252 base_policy.PolicyNotAuthorized,
253 policy.enforce, self.context, 'remove_bgp_speaker_from_dragent',
254 self.target)
255
256 def test_list_bgp_speaker_on_dragent(self):
257 self.assertRaises(
258 base_policy.PolicyNotAuthorized,
259 policy.enforce, self.context, 'list_bgp_speaker_on_dragent',
260 self.target)
261
262 def test_list_dragent_hosting_bgp_speaker(self):
263 self.assertRaises(
264 base_policy.PolicyNotAuthorized,
265 policy.enforce, self.context, 'list_dragent_hosting_bgp_speaker',
266 self.target)