| 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 IpsecSiteConnectionAPITestCase(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(IpsecSiteConnectionAPITestCase): |
| 35 |
|
| 36 |
def setUp(self): |
| 37 |
super().setUp() |
| 38 |
self.context = self.system_admin_ctx |
| 39 |
|
| 40 |
def test_create_ipsec_site_connection(self): |
| 41 |
self.assertRaises( |
| 42 |
base_policy.InvalidScope, |
| 43 |
policy.enforce, self.context, 'create_ipsec_site_connection', |
| 44 |
self.target) |
| 45 |
self.assertRaises( |
| 46 |
base_policy.InvalidScope, |
| 47 |
policy.enforce, self.context, 'create_ipsec_site_connection', |
| 48 |
self.alt_target) |
| 49 |
|
| 50 |
def test_update_ipsec_site_connection(self): |
| 51 |
self.assertRaises( |
| 52 |
base_policy.InvalidScope, |
| 53 |
policy.enforce, self.context, 'update_ipsec_site_connection', |
| 54 |
self.target) |
| 55 |
self.assertRaises( |
| 56 |
base_policy.InvalidScope, |
| 57 |
policy.enforce, self.context, 'update_ipsec_site_connection', |
| 58 |
self.alt_target) |
| 59 |
|
| 60 |
def test_delete_ipsec_site_connection(self): |
| 61 |
self.assertRaises( |
| 62 |
base_policy.InvalidScope, |
| 63 |
policy.enforce, self.context, 'delete_ipsec_site_connection', |
| 64 |
self.target) |
| 65 |
self.assertRaises( |
| 66 |
base_policy.InvalidScope, |
| 67 |
policy.enforce, self.context, 'delete_ipsec_site_connection', |
| 68 |
self.alt_target) |
| 69 |
|
| 70 |
def test_get_ipsec_site_connection(self): |
| 71 |
self.assertRaises( |
| 72 |
base_policy.InvalidScope, |
| 73 |
policy.enforce, self.context, 'get_ipsec_site_connection', |
| 74 |
self.target) |
| 75 |
self.assertRaises( |
| 76 |
base_policy.InvalidScope, |
| 77 |
policy.enforce, self.context, 'get_ipsec_site_connection', |
| 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(IpsecSiteConnectionAPITestCase): |
| 96 |
|
| 97 |
def setUp(self): |
| 98 |
super().setUp() |
| 99 |
self.context = self.project_admin_ctx |
| 100 |
|
| 101 |
def test_create_ipsec_site_connection(self): |
| 102 |
self.assertTrue( |
| 103 |
policy.enforce( |
| 104 |
self.context, 'create_ipsec_site_connection', |
| 105 |
self.target)) |
| 106 |
self.assertTrue( |
| 107 |
policy.enforce( |
| 108 |
self.context, 'create_ipsec_site_connection', |
| 109 |
self.alt_target)) |
| 110 |
|
| 111 |
def test_update_ipsec_site_connection(self): |
| 112 |
self.assertTrue( |
| 113 |
policy.enforce( |
| 114 |
self.context, 'update_ipsec_site_connection', |
| 115 |
self.target)) |
| 116 |
self.assertTrue( |
| 117 |
policy.enforce( |
| 118 |
self.context, 'update_ipsec_site_connection', |
| 119 |
self.alt_target)) |
| 120 |
|
| 121 |
def test_delete_ipsec_site_connection(self): |
| 122 |
self.assertTrue( |
| 123 |
policy.enforce( |
| 124 |
self.context, 'delete_ipsec_site_connection', |
| 125 |
self.target)) |
| 126 |
self.assertTrue( |
| 127 |
policy.enforce( |
| 128 |
self.context, 'delete_ipsec_site_connection', |
| 129 |
self.alt_target)) |
| 130 |
|
| 131 |
def test_get_ipsec_site_connection(self): |
| 132 |
self.assertTrue( |
| 133 |
policy.enforce( |
| 134 |
self.context, 'get_ipsec_site_connection', |
| 135 |
self.target)) |
| 136 |
self.assertTrue( |
| 137 |
policy.enforce( |
| 138 |
self.context, 'get_ipsec_site_connection', |
| 139 |
self.alt_target)) |
| 140 |
|
| 141 |
|
| 142 |
class ProjectManagerTests(AdminTests): |
| 143 |
|
| 144 |
def setUp(self): |
| 145 |
super().setUp() |
| 146 |
self.context = self.project_manager_ctx |
| 147 |
|
| 148 |
def test_create_ipsec_site_connection(self): |
| 149 |
self.assertTrue( |
| 150 |
policy.enforce( |
| 151 |
self.context, 'create_ipsec_site_connection', |
| 152 |
self.target)) |
| 153 |
self.assertRaises( |
| 154 |
base_policy.PolicyNotAuthorized, |
| 155 |
policy.enforce, self.context, 'create_ipsec_site_connection', |
| 156 |
self.alt_target) |
| 157 |
|
| 158 |
def test_update_ipsec_site_connection(self): |
| 159 |
self.assertTrue( |
| 160 |
policy.enforce( |
| 161 |
self.context, 'update_ipsec_site_connection', |
| 162 |
self.target)) |
| 163 |
self.assertRaises( |
| 164 |
base_policy.PolicyNotAuthorized, |
| 165 |
policy.enforce, self.context, 'update_ipsec_site_connection', |
| 166 |
self.alt_target) |
| 167 |
|
| 168 |
def test_delete_ipsec_site_connection(self): |
| 169 |
self.assertTrue( |
| 170 |
policy.enforce( |
| 171 |
self.context, 'delete_ipsec_site_connection', |
| 172 |
self.target)) |
| 173 |
self.assertRaises( |
| 174 |
base_policy.PolicyNotAuthorized, |
| 175 |
policy.enforce, self.context, 'delete_ipsec_site_connection', |
| 176 |
self.alt_target) |
| 177 |
|
| 178 |
def test_get_ipsec_site_connection(self): |
| 179 |
self.assertTrue( |
| 180 |
policy.enforce( |
| 181 |
self.context, 'get_ipsec_site_connection', |
| 182 |
self.target)) |
| 183 |
self.assertRaises( |
| 184 |
base_policy.PolicyNotAuthorized, |
| 185 |
policy.enforce, self.context, 'get_ipsec_site_connection', |
| 186 |
self.alt_target) |
| 187 |
|
| 188 |
|
| 189 |
class ProjectMemberTests(ProjectManagerTests): |
| 190 |
|
| 191 |
def setUp(self): |
| 192 |
super().setUp() |
| 193 |
self.context = self.project_member_ctx |
| 194 |
|
| 195 |
|
| 196 |
class ServiceRoleTests(IpsecSiteConnectionAPITestCase): |
| 197 |
|
| 198 |
def setUp(self): |
| 199 |
super().setUp() |
| 200 |
self.context = self.service_ctx |
| 201 |
|
| 202 |
def test_create_ipsec_site_connection(self): |
| 203 |
self.assertRaises( |
| 204 |
base_policy.PolicyNotAuthorized, |
| 205 |
policy.enforce, self.context, 'create_ipsec_site_connection', |
| 206 |
self.target) |
| 207 |
|
| 208 |
def test_update_ipsec_site_connection(self): |
| 209 |
self.assertRaises( |
| 210 |
base_policy.PolicyNotAuthorized, |
| 211 |
policy.enforce, self.context, 'update_ipsec_site_connection', |
| 212 |
self.target) |
| 213 |
|
| 214 |
def test_delete_ipsec_site_connection(self): |
| 215 |
self.assertRaises( |
| 216 |
base_policy.PolicyNotAuthorized, |
| 217 |
policy.enforce, self.context, 'delete_ipsec_site_connection', |
| 218 |
self.target) |
| 219 |
|
| 220 |
def test_get_ipsec_site_connection(self): |
| 221 |
self.assertRaises( |
| 222 |
base_policy.PolicyNotAuthorized, |
| 223 |
policy.enforce, self.context, 'get_ipsec_site_connection', |
| 224 |
self.target) |