コード例 #1
0
ファイル: base.py プロジェクト: zhangjm12/monasca-common
 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)
コード例 #2
0
ファイル: base.py プロジェクト: openstack/monasca-common
 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(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 = {}
コード例 #4
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 = {}
コード例 #5
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)
コード例 #6
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)
コード例 #7
0
ファイル: test_helpers.py プロジェクト: openstack/monasca-api
 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)
コード例 #8
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)
コード例 #9
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_admin",
                               "role:admin or role:sysadmin"),
         os_policy.RuleDefault("example:uppercase_admin",
                               "role:ADMIN or role:sysadmin"),
     ]
     policy.reset()
     policy.init()
     policy._ENFORCER.register_defaults(rules)
コード例 #10
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 = {}
コード例 #11
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 = {}
コード例 #12
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)
コード例 #13
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_engine.reset()
        policy_engine.init()

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

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

        with open(tmp_file, 'w') as policy_file:
            policy_file.write('{"example:test": "!"}')
        policy_engine._ENFORCER.load_rules(True)
        self.assertRaises(os_policy.PolicyNotAuthorized,
                          policy_engine.authorize,
                          self.context, action, self.target)
コード例 #14
0
ファイル: base.py プロジェクト: zhanghongyuanzzhy/monasca-api
 def setUp(self):
     super(PolicyFixture, self).setUp()
     self._prepare_policy()
     policy.reset()
     policy.init()
コード例 #15
0
 def setUp(self):
     super(IsAdminCheckTestCase, self).setUp()
     policy_engine.init()
コード例 #16
0
 def setUp(self):
     super(IsAdminCheckTestCase, self).setUp()
     policy_engine.init()
コード例 #17
0
ファイル: base.py プロジェクト: openstack/monasca-api
 def setUp(self):
     super(PolicyFixture, self).setUp()
     self._prepare_policy()
     policy.reset()
     policy.init()