示例#1
0
 def test_context_is_admin_undefined(self):
     rules = {
         "admin_or_owner": [["role:admin"], ["project_id:%(project_id)s"]],
         "default": [["rule:admin_or_owner"]],
     }
     brain = common_policy.Brain(rules, CONF.policy_default_rule)
     common_policy.set_brain(brain)
     ctx = context.RequestContext('fake', 'fake')
     self.assertFalse(ctx.is_admin)
     ctx = context.RequestContext('fake', 'fake', roles=['admin'])
     self.assert_(ctx.is_admin)
示例#2
0
 def test_custom_admin_role_is_admin(self):
     # define explict rules for context_is_admin
     rules = {
         'context_is_admin': [["role:administrator"], ["role:johnny-admin"]]
     }
     brain = common_policy.Brain(rules, CONF.policy_default_rule)
     common_policy.set_brain(brain)
     ctx = context.RequestContext('fake', 'fake', roles=['johnny-admin'])
     self.assert_(ctx.is_admin)
     ctx = context.RequestContext('fake', 'fake', roles=['administrator'])
     self.assert_(ctx.is_admin)
     # default rule no longer applies
     ctx = context.RequestContext('fake', 'fake', roles=['admin'])
     self.assertFalse(ctx.is_admin)
示例#3
0
 def setUp(self):
     super(PolicyTestCase, self).setUp()
     policy.reset()
     # NOTE(vish): preload rules to circumvent reloading from file
     policy.init()
     rules = {
         "true": [],
         "example:allowed": [],
         "example:denied": [["false:false"]],
         "example:get_http": [["http:http://www.example.com"]],
         "example:my_file": [["role:compute_admin"],
                             ["project_id:%(project_id)s"]],
         "example:early_and_fail": [["false:false", "rule:true"]],
         "example:early_or_success": [["rule:true"], ["false:false"]],
         "example:lowercase_admin": [["role:admin"], ["role:sysadmin"]],
         "example:uppercase_admin": [["role:ADMIN"], ["role:sysadmin"]],
     }
     # NOTE(vish): then overload underlying brain
     common_policy.set_brain(common_policy.HttpBrain(rules))
     self.context = context.RequestContext('fake', 'fake', roles=['member'])
     self.target = {}
示例#4
0
def _set_brain(data):
    default_rule = CONF.policy_default_rule
    policy.set_brain(policy.HttpBrain.load_json(data, default_rule))