Debian Codegraph @

neutron_vpnaas/tests/unit/policies/test_ike_policy.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 IkePolicyAPITestCase(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(IkePolicyAPITestCase):
35
36 def setUp(self):
37 super().setUp()
38 self.context = self.system_admin_ctx
39
40 def test_create_ikepolicy(self):
41 self.assertRaises(
42 base_policy.InvalidScope,
43 policy.enforce, self.context, 'create_ikepolicy', self.target)
44 self.assertRaises(
45 base_policy.InvalidScope,
46 policy.enforce, self.context, 'create_ikepolicy', self.alt_target)
47
48 def test_update_ikepolicy(self):
49 self.assertRaises(
50 base_policy.InvalidScope,
51 policy.enforce, self.context, 'update_ikepolicy', self.target)
52 self.assertRaises(
53 base_policy.InvalidScope,
54 policy.enforce, self.context, 'update_ikepolicy', self.alt_target)
55
56 def test_delete_ikepolicy(self):
57 self.assertRaises(
58 base_policy.InvalidScope,
59 policy.enforce, self.context, 'delete_ikepolicy', self.target)
60 self.assertRaises(
61 base_policy.InvalidScope,
62 policy.enforce, self.context, 'delete_ikepolicy', self.alt_target)
63
64 def test_get_ikepolicy(self):
65 self.assertRaises(
66 base_policy.InvalidScope,
67 policy.enforce, self.context, 'get_ikepolicy', self.target)
68 self.assertRaises(
69 base_policy.InvalidScope,
70 policy.enforce, self.context, 'get_ikepolicy', self.alt_target)
71
72
73 class SystemMemberTests(SystemAdminTests):
74
75 def setUp(self):
76 super().setUp()
77 self.context = self.system_member_ctx
78
79
80 class SystemReaderTests(SystemMemberTests):
81
82 def setUp(self):
83 super().setUp()
84 self.context = self.system_reader_ctx
85
86
87 class AdminTests(IkePolicyAPITestCase):
88
89 def setUp(self):
90 super().setUp()
91 self.context = self.project_admin_ctx
92
93 def test_create_ikepolicy(self):
94 self.assertTrue(
95 policy.enforce(
96 self.context, 'create_ikepolicy', self.target))
97 self.assertTrue(
98 policy.enforce(
99 self.context, 'create_ikepolicy', self.alt_target))
100
101 def test_update_ikepolicy(self):
102 self.assertTrue(
103 policy.enforce(
104 self.context, 'update_ikepolicy', self.target))
105 self.assertTrue(
106 policy.enforce(
107 self.context, 'update_ikepolicy', self.alt_target))
108
109 def test_delete_ikepolicy(self):
110 self.assertTrue(
111 policy.enforce(
112 self.context, 'delete_ikepolicy', self.target))
113 self.assertTrue(
114 policy.enforce(
115 self.context, 'delete_ikepolicy', self.alt_target))
116
117 def test_get_ikepolicy(self):
118 self.assertTrue(
119 policy.enforce(
120 self.context, 'get_ikepolicy', self.target))
121 self.assertTrue(
122 policy.enforce(
123 self.context, 'get_ikepolicy', self.alt_target))
124
125
126 class ProjectManagerTests(AdminTests):
127
128 def setUp(self):
129 super().setUp()
130 self.context = self.project_manager_ctx
131
132 def test_create_ikepolicy(self):
133 self.assertTrue(
134 policy.enforce(
135 self.context, 'create_ikepolicy', self.target))
136 self.assertRaises(
137 base_policy.PolicyNotAuthorized,
138 policy.enforce, self.context, 'create_ikepolicy', self.alt_target)
139
140 def test_update_ikepolicy(self):
141 self.assertTrue(
142 policy.enforce(
143 self.context, 'update_ikepolicy', self.target))
144 self.assertRaises(
145 base_policy.PolicyNotAuthorized,
146 policy.enforce, self.context, 'update_ikepolicy', self.alt_target)
147
148 def test_delete_ikepolicy(self):
149 self.assertTrue(
150 policy.enforce(
151 self.context, 'delete_ikepolicy', self.target))
152 self.assertRaises(
153 base_policy.PolicyNotAuthorized,
154 policy.enforce, self.context, 'delete_ikepolicy', self.alt_target)
155
156 def test_get_ikepolicy(self):
157 self.assertTrue(
158 policy.enforce(
159 self.context, 'get_ikepolicy', self.target))
160 self.assertRaises(
161 base_policy.PolicyNotAuthorized,
162 policy.enforce, self.context, 'get_ikepolicy', self.alt_target)
163
164
165 class ProjectMemberTests(ProjectManagerTests):
166
167 def setUp(self):
168 super().setUp()
169 self.context = self.project_member_ctx
170
171
172 class ServiceRoleTests(IkePolicyAPITestCase):
173
174 def setUp(self):
175 super().setUp()
176 self.context = self.service_ctx
177
178 def test_create_ikepolicy(self):
179 self.assertRaises(
180 base_policy.PolicyNotAuthorized,
181 policy.enforce, self.context, 'create_ikepolicy', self.target)
182
183 def test_update_ikepolicy(self):
184 self.assertRaises(
185 base_policy.PolicyNotAuthorized,
186 policy.enforce, self.context, 'update_ikepolicy', self.target)
187
188 def test_delete_ikepolicy(self):
189 self.assertRaises(
190 base_policy.PolicyNotAuthorized,
191 policy.enforce, self.context, 'delete_ikepolicy', self.target)
192
193 def test_get_ikepolicy(self):
194 self.assertRaises(
195 base_policy.PolicyNotAuthorized,
196 policy.enforce, self.context, 'get_ikepolicy', self.target)