| 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 BGPSpeakerAPITestCase(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(BGPSpeakerAPITestCase): |
| 35 |
|
| 36 |
def setUp(self): |
| 37 |
super().setUp() |
| 38 |
self.context = self.system_admin_ctx |
| 39 |
|
| 40 |
def test_create_bgp_speaker(self): |
| 41 |
self.assertRaises( |
| 42 |
base_policy.InvalidScope, |
| 43 |
policy.enforce, self.context, 'create_bgp_speaker', self.target) |
| 44 |
self.assertRaises( |
| 45 |
base_policy.InvalidScope, |
| 46 |
policy.enforce, self.context, 'create_bgp_speaker', |
| 47 |
self.alt_target) |
| 48 |
|
| 49 |
def test_update_bgp_speaker(self): |
| 50 |
self.assertRaises( |
| 51 |
base_policy.InvalidScope, |
| 52 |
policy.enforce, self.context, 'update_bgp_speaker', self.target) |
| 53 |
self.assertRaises( |
| 54 |
base_policy.InvalidScope, |
| 55 |
policy.enforce, self.context, 'update_bgp_speaker', |
| 56 |
self.alt_target) |
| 57 |
|
| 58 |
def test_delete_bgp_speaker(self): |
| 59 |
self.assertRaises( |
| 60 |
base_policy.InvalidScope, |
| 61 |
policy.enforce, self.context, 'delete_bgp_speaker', self.target) |
| 62 |
self.assertRaises( |
| 63 |
base_policy.InvalidScope, |
| 64 |
policy.enforce, self.context, 'delete_bgp_speaker', |
| 65 |
self.alt_target) |
| 66 |
|
| 67 |
def test_get_bgp_speaker(self): |
| 68 |
self.assertRaises( |
| 69 |
base_policy.InvalidScope, |
| 70 |
policy.enforce, self.context, 'get_bgp_speaker', self.target) |
| 71 |
self.assertRaises( |
| 72 |
base_policy.InvalidScope, |
| 73 |
policy.enforce, self.context, 'get_bgp_speaker', self.alt_target) |
| 74 |
|
| 75 |
def test_add_bgp_peer(self): |
| 76 |
self.assertRaises( |
| 77 |
base_policy.InvalidScope, |
| 78 |
policy.enforce, self.context, 'add_bgp_peer', self.target) |
| 79 |
self.assertRaises( |
| 80 |
base_policy.InvalidScope, |
| 81 |
policy.enforce, self.context, 'add_bgp_peer', self.alt_target) |
| 82 |
|
| 83 |
def test_remove_bgp_peer(self): |
| 84 |
self.assertRaises( |
| 85 |
base_policy.InvalidScope, |
| 86 |
policy.enforce, self.context, 'remove_bgp_peer', self.target) |
| 87 |
self.assertRaises( |
| 88 |
base_policy.InvalidScope, |
| 89 |
policy.enforce, self.context, 'remove_bgp_peer', self.alt_target) |
| 90 |
|
| 91 |
def test_add_gateway_network(self): |
| 92 |
self.assertRaises( |
| 93 |
base_policy.InvalidScope, |
| 94 |
policy.enforce, self.context, 'add_gateway_network', self.target) |
| 95 |
self.assertRaises( |
| 96 |
base_policy.InvalidScope, |
| 97 |
policy.enforce, self.context, 'add_gateway_network', |
| 98 |
self.alt_target) |
| 99 |
|
| 100 |
def test_remove_gateway_network(self): |
| 101 |
self.assertRaises( |
| 102 |
base_policy.InvalidScope, |
| 103 |
policy.enforce, self.context, 'remove_gateway_network', |
| 104 |
self.target) |
| 105 |
self.assertRaises( |
| 106 |
base_policy.InvalidScope, |
| 107 |
policy.enforce, self.context, 'remove_gateway_network', |
| 108 |
self.alt_target) |
| 109 |
|
| 110 |
def test_get_advertised_routes(self): |
| 111 |
self.assertRaises( |
| 112 |
base_policy.InvalidScope, |
| 113 |
policy.enforce, self.context, 'get_advertised_routes', |
| 114 |
self.target) |
| 115 |
self.assertRaises( |
| 116 |
base_policy.InvalidScope, |
| 117 |
policy.enforce, self.context, 'get_advertised_routes', |
| 118 |
self.alt_target) |
| 119 |
|
| 120 |
|
| 121 |
class SystemMemberTests(SystemAdminTests): |
| 122 |
|
| 123 |
def setUp(self): |
| 124 |
super().setUp() |
| 125 |
self.context = self.system_member_ctx |
| 126 |
|
| 127 |
|
| 128 |
class SystemReaderTests(SystemMemberTests): |
| 129 |
|
| 130 |
def setUp(self): |
| 131 |
super().setUp() |
| 132 |
self.context = self.system_reader_ctx |
| 133 |
|
| 134 |
|
| 135 |
class AdminTests(BGPSpeakerAPITestCase): |
| 136 |
|
| 137 |
def setUp(self): |
| 138 |
super().setUp() |
| 139 |
self.context = self.project_admin_ctx |
| 140 |
|
| 141 |
def test_create_bgp_speaker(self): |
| 142 |
self.assertTrue( |
| 143 |
policy.enforce( |
| 144 |
self.context, 'create_bgp_speaker', self.target)) |
| 145 |
self.assertTrue( |
| 146 |
policy.enforce( |
| 147 |
self.context, 'create_bgp_speaker', self.alt_target)) |
| 148 |
|
| 149 |
def test_update_bgp_speaker(self): |
| 150 |
self.assertTrue( |
| 151 |
policy.enforce( |
| 152 |
self.context, 'update_bgp_speaker', self.target)) |
| 153 |
self.assertTrue( |
| 154 |
policy.enforce( |
| 155 |
self.context, 'update_bgp_speaker', self.alt_target)) |
| 156 |
|
| 157 |
def test_delete_bgp_speaker(self): |
| 158 |
self.assertTrue( |
| 159 |
policy.enforce( |
| 160 |
self.context, 'delete_bgp_speaker', self.target)) |
| 161 |
self.assertTrue( |
| 162 |
policy.enforce( |
| 163 |
self.context, 'delete_bgp_speaker', self.alt_target)) |
| 164 |
|
| 165 |
def test_get_bgp_speaker(self): |
| 166 |
self.assertTrue( |
| 167 |
policy.enforce( |
| 168 |
self.context, 'get_bgp_speaker', self.target)) |
| 169 |
self.assertTrue( |
| 170 |
policy.enforce( |
| 171 |
self.context, 'get_bgp_speaker', self.alt_target)) |
| 172 |
|
| 173 |
def test_add_bgp_peer(self): |
| 174 |
self.assertTrue( |
| 175 |
policy.enforce( |
| 176 |
self.context, 'add_bgp_peer', self.target)) |
| 177 |
self.assertTrue( |
| 178 |
policy.enforce( |
| 179 |
self.context, 'add_bgp_peer', self.alt_target)) |
| 180 |
|
| 181 |
def test_remove_bgp_peer(self): |
| 182 |
self.assertTrue( |
| 183 |
policy.enforce( |
| 184 |
self.context, 'remove_bgp_peer', self.target)) |
| 185 |
self.assertTrue( |
| 186 |
policy.enforce( |
| 187 |
self.context, 'remove_bgp_peer', self.alt_target)) |
| 188 |
|
| 189 |
def test_add_gateway_network(self): |
| 190 |
self.assertTrue( |
| 191 |
policy.enforce( |
| 192 |
self.context, 'add_gateway_network', self.target)) |
| 193 |
self.assertTrue( |
| 194 |
policy.enforce( |
| 195 |
self.context, 'add_gateway_network', self.alt_target)) |
| 196 |
|
| 197 |
def test_remove_gateway_network(self): |
| 198 |
self.assertTrue( |
| 199 |
policy.enforce( |
| 200 |
self.context, 'remove_gateway_network', self.target)) |
| 201 |
self.assertTrue( |
| 202 |
policy.enforce( |
| 203 |
self.context, 'remove_gateway_network', self.alt_target)) |
| 204 |
|
| 205 |
def test_get_advertised_routes(self): |
| 206 |
self.assertTrue( |
| 207 |
policy.enforce( |
| 208 |
self.context, 'get_advertised_routes', self.target)) |
| 209 |
self.assertTrue( |
| 210 |
policy.enforce( |
| 211 |
self.context, 'get_advertised_routes', self.alt_target)) |
| 212 |
|
| 213 |
|
| 214 |
class ProjectManagerTests(BGPSpeakerAPITestCase): |
| 215 |
|
| 216 |
def setUp(self): |
| 217 |
super().setUp() |
| 218 |
self.context = self.project_manager_ctx |
| 219 |
|
| 220 |
def test_create_bgp_speaker(self): |
| 221 |
self.assertRaises( |
| 222 |
base_policy.PolicyNotAuthorized, |
| 223 |
policy.enforce, self.context, 'create_bgp_speaker', self.target) |
| 224 |
self.assertRaises( |
| 225 |
base_policy.PolicyNotAuthorized, |
| 226 |
policy.enforce, self.context, 'create_bgp_speaker', |
| 227 |
self.alt_target) |
| 228 |
|
| 229 |
def test_update_bgp_speaker(self): |
| 230 |
self.assertRaises( |
| 231 |
base_policy.PolicyNotAuthorized, |
| 232 |
policy.enforce, self.context, 'update_bgp_speaker', self.target) |
| 233 |
self.assertRaises( |
| 234 |
base_policy.PolicyNotAuthorized, |
| 235 |
policy.enforce, self.context, 'update_bgp_speaker', |
| 236 |
self.alt_target) |
| 237 |
|
| 238 |
def test_delete_bgp_speaker(self): |
| 239 |
self.assertRaises( |
| 240 |
base_policy.PolicyNotAuthorized, |
| 241 |
policy.enforce, self.context, 'delete_bgp_speaker', self.target) |
| 242 |
self.assertRaises( |
| 243 |
base_policy.PolicyNotAuthorized, |
| 244 |
policy.enforce, self.context, 'delete_bgp_speaker', |
| 245 |
self.alt_target) |
| 246 |
|
| 247 |
def test_get_bgp_speaker(self): |
| 248 |
self.assertRaises( |
| 249 |
base_policy.PolicyNotAuthorized, |
| 250 |
policy.enforce, self.context, 'get_bgp_speaker', self.target) |
| 251 |
self.assertRaises( |
| 252 |
base_policy.PolicyNotAuthorized, |
| 253 |
policy.enforce, self.context, 'get_bgp_speaker', self.alt_target) |
| 254 |
|
| 255 |
def test_add_bgp_peer(self): |
| 256 |
self.assertRaises( |
| 257 |
base_policy.PolicyNotAuthorized, |
| 258 |
policy.enforce, self.context, 'add_bgp_peer', self.target) |
| 259 |
self.assertRaises( |
| 260 |
base_policy.PolicyNotAuthorized, |
| 261 |
policy.enforce, self.context, 'add_bgp_peer', self.alt_target) |
| 262 |
|
| 263 |
def test_remove_bgp_peer(self): |
| 264 |
self.assertRaises( |
| 265 |
base_policy.PolicyNotAuthorized, |
| 266 |
policy.enforce, self.context, 'remove_bgp_peer', self.target) |
| 267 |
self.assertRaises( |
| 268 |
base_policy.PolicyNotAuthorized, |
| 269 |
policy.enforce, self.context, 'remove_bgp_peer', self.alt_target) |
| 270 |
|
| 271 |
def test_add_gateway_network(self): |
| 272 |
self.assertRaises( |
| 273 |
base_policy.PolicyNotAuthorized, |
| 274 |
policy.enforce, self.context, 'add_gateway_network', self.target) |
| 275 |
self.assertRaises( |
| 276 |
base_policy.PolicyNotAuthorized, |
| 277 |
policy.enforce, self.context, 'add_gateway_network', |
| 278 |
self.alt_target) |
| 279 |
|
| 280 |
def test_remove_gateway_network(self): |
| 281 |
self.assertRaises( |
| 282 |
base_policy.PolicyNotAuthorized, |
| 283 |
policy.enforce, self.context, 'remove_gateway_network', |
| 284 |
self.target) |
| 285 |
self.assertRaises( |
| 286 |
base_policy.PolicyNotAuthorized, |
| 287 |
policy.enforce, self.context, 'remove_gateway_network', |
| 288 |
self.alt_target) |
| 289 |
|
| 290 |
def test_get_advertised_routes(self): |
| 291 |
self.assertRaises( |
| 292 |
base_policy.PolicyNotAuthorized, |
| 293 |
policy.enforce, self.context, 'get_advertised_routes', |
| 294 |
self.target) |
| 295 |
self.assertRaises( |
| 296 |
base_policy.PolicyNotAuthorized, |
| 297 |
policy.enforce, self.context, 'get_advertised_routes', |
| 298 |
self.alt_target) |
| 299 |
|
| 300 |
|
| 301 |
class ProjectMemberTests(ProjectManagerTests): |
| 302 |
|
| 303 |
def setUp(self): |
| 304 |
super().setUp() |
| 305 |
self.context = self.project_member_ctx |
| 306 |
|
| 307 |
|
| 308 |
class ProjectReaderTests(ProjectMemberTests): |
| 309 |
|
| 310 |
def setUp(self): |
| 311 |
super().setUp() |
| 312 |
self.context = self.project_reader_ctx |
| 313 |
|
| 314 |
def test_create_bgp_speaker(self): |
| 315 |
self.assertRaises( |
| 316 |
base_policy.PolicyNotAuthorized, |
| 317 |
policy.enforce, self.context, 'create_bgp_speaker', self.target) |
| 318 |
self.assertRaises( |
| 319 |
base_policy.PolicyNotAuthorized, |
| 320 |
policy.enforce, self.context, 'create_bgp_speaker', |
| 321 |
self.alt_target) |
| 322 |
|
| 323 |
def test_update_bgp_speaker(self): |
| 324 |
self.assertRaises( |
| 325 |
base_policy.PolicyNotAuthorized, |
| 326 |
policy.enforce, self.context, 'update_bgp_speaker', self.target) |
| 327 |
self.assertRaises( |
| 328 |
base_policy.PolicyNotAuthorized, |
| 329 |
policy.enforce, self.context, 'update_bgp_speaker', |
| 330 |
self.alt_target) |
| 331 |
|
| 332 |
def test_delete_bgp_speaker(self): |
| 333 |
self.assertRaises( |
| 334 |
base_policy.PolicyNotAuthorized, |
| 335 |
policy.enforce, self.context, 'delete_bgp_speaker', self.target) |
| 336 |
self.assertRaises( |
| 337 |
base_policy.PolicyNotAuthorized, |
| 338 |
policy.enforce, self.context, 'delete_bgp_speaker', |
| 339 |
self.alt_target) |
| 340 |
|
| 341 |
def test_get_bgp_speaker(self): |
| 342 |
self.assertRaises( |
| 343 |
base_policy.PolicyNotAuthorized, |
| 344 |
policy.enforce, self.context, 'get_bgp_speaker', self.target) |
| 345 |
self.assertRaises( |
| 346 |
base_policy.PolicyNotAuthorized, |
| 347 |
policy.enforce, self.context, 'get_bgp_speaker', self.alt_target) |
| 348 |
|
| 349 |
def test_add_bgp_peer(self): |
| 350 |
self.assertRaises( |
| 351 |
base_policy.PolicyNotAuthorized, |
| 352 |
policy.enforce, self.context, 'add_bgp_peer', self.target) |
| 353 |
self.assertRaises( |
| 354 |
base_policy.PolicyNotAuthorized, |
| 355 |
policy.enforce, self.context, 'add_bgp_peer', self.alt_target) |
| 356 |
|
| 357 |
def test_remove_bgp_peer(self): |
| 358 |
self.assertRaises( |
| 359 |
base_policy.PolicyNotAuthorized, |
| 360 |
policy.enforce, self.context, 'remove_bgp_peer', self.target) |
| 361 |
self.assertRaises( |
| 362 |
base_policy.PolicyNotAuthorized, |
| 363 |
policy.enforce, self.context, 'remove_bgp_peer', self.alt_target) |
| 364 |
|
| 365 |
def test_add_gateway_network(self): |
| 366 |
self.assertRaises( |
| 367 |
base_policy.PolicyNotAuthorized, |
| 368 |
policy.enforce, self.context, 'add_gateway_network', self.target) |
| 369 |
self.assertRaises( |
| 370 |
base_policy.PolicyNotAuthorized, |
| 371 |
policy.enforce, self.context, 'add_gateway_network', |
| 372 |
self.alt_target) |
| 373 |
|
| 374 |
def test_remove_gateway_network(self): |
| 375 |
self.assertRaises( |
| 376 |
base_policy.PolicyNotAuthorized, |
| 377 |
policy.enforce, self.context, 'remove_gateway_network', |
| 378 |
self.target) |
| 379 |
self.assertRaises( |
| 380 |
base_policy.PolicyNotAuthorized, |
| 381 |
policy.enforce, self.context, 'remove_gateway_network', |
| 382 |
self.alt_target) |
| 383 |
|
| 384 |
def test_get_advertised_routes(self): |
| 385 |
self.assertRaises( |
| 386 |
base_policy.PolicyNotAuthorized, |
| 387 |
policy.enforce, self.context, 'get_advertised_routes', |
| 388 |
self.target) |
| 389 |
self.assertRaises( |
| 390 |
base_policy.PolicyNotAuthorized, |
| 391 |
policy.enforce, self.context, 'get_advertised_routes', |
| 392 |
self.alt_target) |
| 393 |
|
| 394 |
|
| 395 |
class ServiceRoleTests(BGPSpeakerAPITestCase): |
| 396 |
|
| 397 |
def setUp(self): |
| 398 |
super().setUp() |
| 399 |
self.context = self.service_ctx |
| 400 |
|
| 401 |
def test_create_bgp_speaker(self): |
| 402 |
self.assertRaises( |
| 403 |
base_policy.PolicyNotAuthorized, |
| 404 |
policy.enforce, self.context, 'create_bgp_speaker', self.target) |
| 405 |
|
| 406 |
def test_update_bgp_speaker(self): |
| 407 |
self.assertRaises( |
| 408 |
base_policy.PolicyNotAuthorized, |
| 409 |
policy.enforce, self.context, 'update_bgp_speaker', self.target) |
| 410 |
|
| 411 |
def test_delete_bgp_speaker(self): |
| 412 |
self.assertRaises( |
| 413 |
base_policy.PolicyNotAuthorized, |
| 414 |
policy.enforce, self.context, 'delete_bgp_speaker', self.target) |
| 415 |
|
| 416 |
def test_get_bgp_speaker(self): |
| 417 |
self.assertRaises( |
| 418 |
base_policy.PolicyNotAuthorized, |
| 419 |
policy.enforce, self.context, 'get_bgp_speaker', self.target) |
| 420 |
|
| 421 |
def test_add_bgp_peer(self): |
| 422 |
self.assertRaises( |
| 423 |
base_policy.PolicyNotAuthorized, |
| 424 |
policy.enforce, self.context, 'add_bgp_peer', self.target) |
| 425 |
|
| 426 |
def test_remove_bgp_peer(self): |
| 427 |
self.assertRaises( |
| 428 |
base_policy.PolicyNotAuthorized, |
| 429 |
policy.enforce, self.context, 'remove_bgp_peer', self.target) |
| 430 |
|
| 431 |
def test_add_gateway_network(self): |
| 432 |
self.assertRaises( |
| 433 |
base_policy.PolicyNotAuthorized, |
| 434 |
policy.enforce, self.context, 'add_gateway_network', self.target) |
| 435 |
|
| 436 |
def test_remove_gateway_network(self): |
| 437 |
self.assertRaises( |
| 438 |
base_policy.PolicyNotAuthorized, |
| 439 |
policy.enforce, self.context, 'remove_gateway_network', |
| 440 |
self.target) |
| 441 |
|
| 442 |
def test_get_advertised_routes(self): |
| 443 |
self.assertRaises( |
| 444 |
base_policy.PolicyNotAuthorized, |
| 445 |
policy.enforce, self.context, 'get_advertised_routes', self.target) |