Пример #1
0
    def setUp(self):
        super(PolicyTestCase, self).setUp()
        rules = [
            os_policy.RuleDefault("true", "@"),
            os_policy.RuleDefault("example:allowed", "@"),
            os_policy.RuleDefault("example:denied", "!"),
            os_policy.RuleDefault("old_action_not_default", "@"),
            os_policy.RuleDefault("new_action", "@"),
            os_policy.RuleDefault("old_action_default", "rule:admin_api"),
            os_policy.RuleDefault("example:lowercase_admin",
                                  "role:admin or role:sysadmin"),
            os_policy.RuleDefault("example:uppercase_admin",
                                  "role:ADMIN or role:sysadmin"),
            os_policy.RuleDefault("example:get_http",
                                  "http://www.example.com"),
            os_policy.RuleDefault(
                "example:my_file", "role:compute_admin or "
                "project_id:%(project_id)s"),
            os_policy.RuleDefault("example:early_and_fail", "! and @"),
            os_policy.RuleDefault("example:early_or_success", "@ or !"),
        ]
        policy_engine.reset()
        policy_engine.init()

        self.context = context.RequestContext(user='******',
                                              tenant='fake',
                                              is_admin=False)
        policy_engine._ENFORCER.register_defaults(rules)
        self.target = {}
Пример #2
0
 def setUp(self):
     super(EmptyPolicyFixture, self).setUp()
     self._prepare_policy()
     policy_engine.POLICIES = FakePolicy()
     policy_engine.reset()
     policy_engine.init()
     self.addCleanup(policy_engine.reset)
Пример #3
0
 def setUp(self):
     super(TestRequest, self).setUp()
     rules = [
         os_policy.RuleDefault("example:allowed", "user_id:222"),
     ]
     policy.reset()
     policy.init()
     policy._ENFORCER.register_defaults(rules)
Пример #4
0
 def setUp(self):
     super(TestGetXTenantOrTenantId, self).setUp()
     rules = [
         os_policy.RuleDefault("example:allowed", "@"),
         os_policy.RuleDefault("example:denied", "!"),
         os_policy.RuleDefault("example:authorized",
                               "role:role_1 or role:role_2")
     ]
     policy.reset()
     policy.init()
     policy._ENFORCER.register_defaults(rules)
Пример #5
0
 def setUp(self):
     super(TestPolicyCase, self).setUp()
     rules = [
         os_policy.RuleDefault("true", "@"),
         os_policy.RuleDefault("example:allowed", "@"),
         os_policy.RuleDefault("example:denied", "!"),
         os_policy.RuleDefault("example:lowercase_monasca_user",
                               "role:monasca_user or role:sysadmin"),
         os_policy.RuleDefault("example:uppercase_monasca_user",
                               "role:MONASCA_USER or role:sysadmin"),
     ]
     policy.reset()
     policy.init()
     policy._ENFORCER.register_defaults(rules)
Пример #6
0
    def setUp(self):
        super(AdminRolePolicyTestCase, self).setUp()
        self.noadmin_context = context.RequestContext('fake', 'fake',
                                                      roles=['member'])
        self.admin_context = context.RequestContext('fake', 'fake',
                                                    roles=['admin'])

        admin_rule = [
            os_policy.RuleDefault('example.admin', 'role:admin'),
        ]
        policy_engine.reset()
        policy_engine.init(policy_file=None)
        policy_engine._ENFORCER.register_defaults(admin_rule)
        policy_engine._ENFORCER.load_rules(True)
        self.target = {}
Пример #7
0
    def test_modified_policy_reloads(self):
        tmp_file = \
            self.create_tempfiles(files=[('policies', '{}')], ext='.yaml')[0]
        base.BaseTestCase.conf_override(policy_file=tmp_file,
                                        group='oslo_policy')

        policy.reset()
        policy.init()
        action = 'example:test'
        rule = os_policy.RuleDefault(action, '')
        policy._ENFORCER.register_defaults([rule])

        with open(tmp_file, 'w') as policy_file:
            policy_file.write('{"example:test": ""}')
        policy.authorize(self.context, action, self.target)

        with open(tmp_file, 'w') as policy_file:
            policy_file.write('{"example:test": "!"}')
        policy._ENFORCER.load_rules(True)
        self.assertRaises(os_policy.PolicyNotAuthorized, policy.authorize,
                          self.context, action, self.target)
Пример #8
0
 def setUp(self):
     super(IsAdminCheckTestCase, self).setUp()
     policy_engine.init()
Пример #9
0
 def setUp(self):
     super(PolicyFixture, self).setUp()
     self._prepare_policy()
     policy.reset()
     policy.init()