37
38
super(PolicyFileTestCase, self).setUp()
39
_, self.tmpfilename = tempfile.mkstemp()
40
self.flags(policy_file=self.tmpfilename)
41
40
self.context = context.RequestContext('fake', 'fake')
48
47
def test_modified_policy_reloads(self):
49
action = "example:test"
50
with open(self.tmpfilename, "w") as policyfile:
51
policyfile.write("""{"example:test": []}""")
52
policy.enforce(self.context, action, self.target)
53
with open(self.tmpfilename, "w") as policyfile:
54
policyfile.write("""{"example:test": ["false:false"]}""")
55
# NOTE(vish): reset stored policy cache so we don't have to sleep(1)
56
policy._POLICY_CACHE = {}
57
self.assertRaises(exception.PolicyNotAuthorized, policy.enforce,
58
self.context, action, self.target)
48
with utils.tempdir() as tmpdir:
49
tmpfilename = os.path.join(tmpdir, 'policy')
50
self.flags(policy_file=tmpfilename)
52
action = "example:test"
53
with open(tmpfilename, "w") as policyfile:
54
policyfile.write("""{"example:test": []}""")
55
policy.enforce(self.context, action, self.target)
56
with open(tmpfilename, "w") as policyfile:
57
policyfile.write("""{"example:test": ["false:false"]}""")
58
# NOTE(vish): reset stored policy cache so we don't have to
60
policy._POLICY_CACHE = {}
61
self.assertRaises(exception.PolicyNotAuthorized, policy.enforce,
62
self.context, action, self.target)
61
65
class PolicyTestCase(test.TestCase):