Debian Codegraph @

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