Skip to content

Commit b182b41

Browse files
committed
- Added tests for json/yaml parsing of a PolicySpecification file
1 parent 182adb9 commit b182b41

2 files changed

Lines changed: 26 additions & 10 deletions

File tree

tests/resources/policy_specification.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ policy:
88
maxValidDays: 120
99
subject:
1010
orgs:
11-
- venafi_yaml
11+
- venafi.com
1212
orgUnits:
13-
- DevOps_yaml
13+
- DevOps
1414
localities:
1515
- Merida
1616
states:

tests/test_pm.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,8 @@ def __init__(self, *args, **kwargs):
4242
self.yaml_file = _resolve_resources_path(POLICY_SPEC_YAML)
4343

4444
def test_json_parsing(self):
45-
# data = json_parser.parse_file(self.json_file)
46-
# print_data = parse_policy_spec(data)
47-
# pprint(print_data)
48-
pass
45+
ps = json_parser.parse_file(self.json_file)
46+
self._assert_policy_spec(ps)
4947

5048
def test_json_serialization(self):
5149
ps = PolicySpecification(policy=_get_policy_obj(), defaults=_get_defaults_obj())
@@ -55,15 +53,33 @@ def test_yaml_11_parsing(self):
5553
pass
5654

5755
def test_yaml_12_parsing(self):
58-
# data = yaml_parser.parse_file(self.yaml_file)
59-
# print_data = parse_policy_spec(data)
60-
# pprint(print_data)
61-
pass
56+
ps = yaml_parser.parse_file(self.yaml_file)
57+
self._assert_policy_spec(ps)
6258

6359
def test_yaml_serialization(self):
6460
ps = PolicySpecification(policy=_get_policy_obj(), defaults=_get_defaults_obj())
6561
yaml_parser.serialize(ps, 'test_yaml_serialization.yaml')
6662

63+
def _assert_policy_spec(self, ps):
64+
"""
65+
66+
:param vcert.policy.PolicySpecification ps:
67+
:return:
68+
"""
69+
self.assertIsNotNone(ps)
70+
self.assertIn("venafi.com", ps.policy.domains)
71+
self.assertIn("kwan.com", ps.policy.domains)
72+
self.assertIn("venafi.com", ps.policy.subject.orgs)
73+
self.assertTrue(len(ps.policy.subject.orgs) == 1)
74+
self.assertIn("DevOps", ps.policy.subject.org_units)
75+
self.assertTrue(len(ps.policy.subject.org_units) == 1)
76+
self.assertIn("Merida", ps.policy.subject.localities)
77+
self.assertTrue(len(ps.policy.subject.localities) == 1)
78+
self.assertIn("RSA", ps.policy.key_pair.key_types)
79+
self.assertTrue(len(ps.policy.key_pair.key_types) == 1)
80+
self.assertIn(2048, ps.policy.key_pair.rsa_key_sizes)
81+
self.assertTrue(len(ps.policy.key_pair.rsa_key_sizes) == 1)
82+
6783

6884
class TestTPPPolicyManagement(unittest.TestCase):
6985
def __init__(self, *args, **kwargs):

0 commit comments

Comments
 (0)