Merge "Remove policy file from source and refactor tests"
This commit is contained in:
commit
539b6e8074
|
@ -1,2 +0,0 @@
|
|||
{
|
||||
}
|
|
@ -173,25 +173,21 @@ class DefaultPolicyTestCase(unit.TestCase):
|
|||
|
||||
class PolicyJsonTestCase(unit.TestCase):
|
||||
|
||||
def _load_entries(self, filename):
|
||||
return set(json.load(open(filename)))
|
||||
def _get_default_policy_rules(self):
|
||||
"""Return a dictionary of all in-code policies.
|
||||
|
||||
def _add_missing_default_rules(self, rules):
|
||||
"""Add default rules and their values to the given rules dict.
|
||||
|
||||
The given rules dict may have an incomplete set of policy rules.
|
||||
This method will add the default policy rules and their values to the
|
||||
dict. It will not override the existing rules. This method is temporary
|
||||
and is only needed until we move all policy.json rules into code.
|
||||
All policies have a default value that is maintained in code.
|
||||
This method returns a dictionary containing all default policies.
|
||||
"""
|
||||
rules = dict()
|
||||
for rule in policies.list_rules():
|
||||
if rule.name not in rules:
|
||||
rules[rule.name] = rule.check_str
|
||||
rules[rule.name] = rule.check_str
|
||||
return rules
|
||||
|
||||
def test_json_examples_have_matching_entries(self):
|
||||
policy_keys = self._load_entries(unit.dirs.etc('policy.json'))
|
||||
cloud_policy_keys = self._load_entries(
|
||||
unit.dirs.etc('policy.v3cloudsample.json'))
|
||||
policy_keys = self._get_default_policy_rules()
|
||||
cloud_policy_keys = set(
|
||||
json.load(open(unit.dirs.etc('policy.v3cloudsample.json'))))
|
||||
|
||||
policy_extra_keys = ['admin_or_token_subject',
|
||||
'service_admin_or_token_subject',
|
||||
|
@ -228,10 +224,7 @@ class PolicyJsonTestCase(unit.TestCase):
|
|||
self.assertTrue(result)
|
||||
|
||||
def test_all_targets_documented(self):
|
||||
# All the targets in the sample policy file must be documented in
|
||||
# doc/source/policy_mapping.rst.
|
||||
policy_keys = json.load(open((unit.dirs.etc('policy.json'))))
|
||||
self._add_missing_default_rules(policy_keys)
|
||||
policy_keys = self._get_default_policy_rules()
|
||||
|
||||
# These keys are in the policy.json but aren't targets.
|
||||
policy_rule_keys = [
|
||||
|
|
Loading…
Reference in New Issue