blob: 942d7d07e51d1aeb9148d60ddae0024cee602547 [file] [log] [blame]
DavidPurcell029d8c32017-01-06 15:27:41 -05001# Copyright 2017 AT&T Inc.
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# 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, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
15import os
16
17from tempest import config
18from tempest.tests import base
19
20from patrole_tempest_plugin import rbac_role_converter
21
22CONF = config.CONF
23
24
25class RbacPolicyTest(base.TestCase):
26
27 def setUp(self):
28 super(RbacPolicyTest, self).setUp()
29
30 current_directory = os.path.dirname(os.path.realpath(__file__))
31 self.custom_policy_file = os.path.join(current_directory,
32 'custom_rbac_policy.json')
33
34 def test_custom_policy(self):
35 default_roles = ['zero', 'one', 'two', 'three', 'four',
36 'five', 'six', 'seven', 'eight', 'nine']
37 CONF.set_override('rbac_roles', default_roles, group='rbac',
38 enforce_type=True)
39
40 self.converter = rbac_role_converter.RbacPolicyConverter(
41 "custom",
42 self.custom_policy_file
43 )
44 self.roles_dict = self.converter.rules
45
46 expected = {
47 'policy_action_1': ['two', 'four', 'six', 'eight'],
48 'policy_action_2': ['one', 'three', 'five', 'seven', 'nine'],
49 'policy_action_3': ['zero'],
50 'policy_action_4': ['one', 'two', 'three', 'five', 'seven'],
51 'policy_action_5': ['zero', 'one', 'two', 'three', 'four', 'five',
52 'six', 'seven', 'eight', 'nine'],
53 'policy_action_6': ['eight'],
54 }
55
56 fake_rule = 'fake_rule'
57
58 self.assertFalse(fake_rule in self.roles_dict.keys())
59
60 for rule in expected.keys():
61 self.assertTrue(rule in self.roles_dict.keys())
62 expected_roles = expected[rule]
63 unexpected_roles = set(default_roles) - set(expected[rule])
64 for role in expected_roles:
65 self.assertTrue(role in self.roles_dict[rule])
66 for role in unexpected_roles:
67 self.assertFalse(role in self.roles_dict[rule])