From 6655f7d62347f96bf4fe8673faf26c0c3e2b2e0b Mon Sep 17 00:00:00 2001 From: Slawek Kaplonski Date: Mon, 22 Mar 2021 12:16:47 +0100 Subject: [PATCH] Add tests for floatingip pools API's new policy rules Related-blueprint: bp/secure-rbac-roles Change-Id: I3f4f668866a7d1dacb583a177e8475617a762bf7 --- .../conf/policies/test_floatingip_pools.py | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 neutron/tests/unit/conf/policies/test_floatingip_pools.py diff --git a/neutron/tests/unit/conf/policies/test_floatingip_pools.py b/neutron/tests/unit/conf/policies/test_floatingip_pools.py new file mode 100644 index 00000000000..574ef0bf2e0 --- /dev/null +++ b/neutron/tests/unit/conf/policies/test_floatingip_pools.py @@ -0,0 +1,85 @@ +# Copyright (c) 2021 Red Hat Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from oslo_policy import policy as base_policy + +from neutron import policy +from neutron.tests.unit.conf.policies import base + + +class FloatingipPoolsAPITestCase(base.PolicyBaseTestCase): + + def setUp(self): + super(FloatingipPoolsAPITestCase, self).setUp() + self.target = {'project_id': self.project_id} + + +class SystemAdminTests(FloatingipPoolsAPITestCase): + + def setUp(self): + super(SystemAdminTests, self).setUp() + self.context = self.system_admin_ctx + + def test_get_floatingip_pool(self): + self.assertTrue( + policy.enforce(self.context, 'get_floatingip_pool', + self.target)) + + +class SystemMemberTests(SystemAdminTests): + + def setUp(self): + super(SystemMemberTests, self).setUp() + self.context = self.system_member_ctx + + +class SystemReaderTests(SystemAdminTests): + + def setUp(self): + super(SystemReaderTests, self).setUp() + self.context = self.system_reader_ctx + + +class ProjectAdminTests(FloatingipPoolsAPITestCase): + + def setUp(self): + super(ProjectAdminTests, self).setUp() + self.alt_target = {'project_id': self.alt_project_id} + self.context = self.project_admin_ctx + + def test_get_floatingip_pool(self): + self.assertTrue( + policy.enforce(self.context, 'get_floatingip_pool', + self.target)) + + def test_get_floatingip_pool_other_project(self): + self.assertRaises( + base_policy.PolicyNotAuthorized, + policy.enforce, + self.context, 'get_floatingip_pool', self.alt_target) + + +class ProjectMemberTests(ProjectAdminTests): + + def setUp(self): + super(ProjectMemberTests, self).setUp() + self.context = self.project_member_ctx + + +class ProjectReaderTests(ProjectAdminTests): + + def setUp(self): + super(ProjectReaderTests, self).setUp() + self.context = self.project_reader_ctx