diff options
author | Jenkins <jenkins@review.openstack.org> | 2015-10-16 20:48:52 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2015-10-16 20:48:52 +0000 |
commit | 767776f643da3173dc98c0ef6ad74f33df5f077a (patch) | |
tree | 8a58b25cfa75848d3767e1b859af4ebb16d82bb5 | |
parent | ef46c0db50af6107a5bca6d9c80ca5939f4cbec0 (diff) | |
parent | 3ce9b0c10cac2f8eadf48f9957a6d9da9079a210 (diff) | |
download | oslo-policy-767776f643da3173dc98c0ef6ad74f33df5f077a.tar.gz |
Merge "Add test for enforce with rule doesn't exist"
-rw-r--r-- | oslo_policy/tests/test_policy.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/oslo_policy/tests/test_policy.py b/oslo_policy/tests/test_policy.py index 52a793c..ccfcdf5 100644 --- a/oslo_policy/tests/test_policy.py +++ b/oslo_policy/tests/test_policy.py @@ -481,6 +481,16 @@ class CheckFunctionTestCase(base.PolicyBaseTestCase): self.assertEqual(('target', 'creds', self.enforcer), result) + def test_check_rule_not_exist_not_empty_policy_file(self): + # If the rule doesn't exist, then enforce() fails rather than KeyError. + + # This test needs a non-empty file otherwise the code short-circuits. + self.create_config_file('policy.json', jsonutils.dumps({"a_rule": []})) + self.enforcer.default_rule = None + self.enforcer.load_rules() + result = self.enforcer.enforce('rule', 'target', 'creds') + self.assertFalse(result) + def test_check_raise_default(self): # When do_raise=True and exc is not used then PolicyNotAuthorized is # raised. |