2828 PolicySpecification )
2929from vcert .policy .pm_cloud import CA_TYPE_DIGICERT , CA_TYPE_ENTRUST
3030
31- POLICY_SPEC_JSON = 'resources/policy_specification.json'
32- POLICY_SPEC_YAML = 'resources/policy_specification.yaml'
31+ # This values are loaded from the project root which is vcert-python, not tests folder
32+ POLICY_SPEC_JSON = './tests/resources/policy_specification.json'
33+ POLICY_SPEC_YAML = './tests/resources/policy_specification.yaml'
3334CA_TYPE_TPP = 'TPP'
3435
3536log = logger .get_child ("test-pm" )
3839class TestParsers (unittest .TestCase ):
3940 def __init__ (self , * args , ** kwargs ):
4041 super (TestParsers , self ).__init__ (* args , ** kwargs )
41- self .json_file = _resolve_resources_path ( POLICY_SPEC_JSON )
42- self .yaml_file = _resolve_resources_path ( POLICY_SPEC_YAML )
42+ self .json_file = POLICY_SPEC_JSON
43+ self .yaml_file = POLICY_SPEC_YAML
4344
4445 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
46+ ps = json_parser .parse_file (self .json_file )
47+ self ._assert_policy_spec (ps )
4948
5049 def test_json_serialization (self ):
5150 ps = PolicySpecification (policy = _get_policy_obj (), defaults = _get_defaults_obj ())
@@ -55,23 +54,41 @@ def test_yaml_11_parsing(self):
5554 pass
5655
5756 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
57+ ps = yaml_parser .parse_file (self .yaml_file )
58+ self ._assert_policy_spec (ps )
6259
6360 def test_yaml_serialization (self ):
6461 ps = PolicySpecification (policy = _get_policy_obj (), defaults = _get_defaults_obj ())
6562 yaml_parser .serialize (ps , 'test_yaml_serialization.yaml' )
6663
64+ def _assert_policy_spec (self , ps ):
65+ """
66+
67+ :param vcert.policy.PolicySpecification ps:
68+ :return:
69+ """
70+ self .assertIsNotNone (ps )
71+ self .assertIn ("venafi.com" , ps .policy .domains )
72+ self .assertIn ("kwan.com" , ps .policy .domains )
73+ self .assertIn ("venafi.com" , ps .policy .subject .orgs )
74+ self .assertTrue (len (ps .policy .subject .orgs ) == 1 )
75+ self .assertIn ("DevOps" , ps .policy .subject .org_units )
76+ self .assertTrue (len (ps .policy .subject .org_units ) == 1 )
77+ self .assertIn ("Merida" , ps .policy .subject .localities )
78+ self .assertTrue (len (ps .policy .subject .localities ) == 1 )
79+ self .assertIn ("RSA" , ps .policy .key_pair .key_types )
80+ self .assertTrue (len (ps .policy .key_pair .key_types ) == 1 )
81+ self .assertIn (2048 , ps .policy .key_pair .rsa_key_sizes )
82+ self .assertTrue (len (ps .policy .key_pair .rsa_key_sizes ) == 1 )
83+
6784
6885class TestTPPPolicyManagement (unittest .TestCase ):
6986 def __init__ (self , * args , ** kwargs ):
7087 self .tpp_conn = TPPTokenConnection (url = TPP_TOKEN_URL , http_request_kwargs = {'verify' : "/tmp/chain.pem" })
7188 auth = Authentication (user = TPP_USER , password = TPP_PASSWORD , scope = SCOPE_PM )
7289 self .tpp_conn .get_access_token (auth )
73- self .json_file = _resolve_resources_path ( POLICY_SPEC_JSON )
74- self .yaml_file = _resolve_resources_path ( POLICY_SPEC_YAML )
90+ self .json_file = POLICY_SPEC_JSON
91+ self .yaml_file = POLICY_SPEC_YAML
7592 super (TestTPPPolicyManagement , self ).__init__ (* args , ** kwargs )
7693
7794 def test_create_policy_from_json (self ):
@@ -108,8 +125,8 @@ def _create_policy_tpp(self, policy_spec=None, policy=None, defaults=None):
108125class TestCloudPolicyManagement (unittest .TestCase ):
109126 def __init__ (self , * args , ** kwargs ):
110127 self .cloud_conn = CloudConnection (token = CLOUD_APIKEY , url = CLOUD_URL )
111- self .json_file = _resolve_resources_path ( POLICY_SPEC_JSON )
112- self .yaml_file = _resolve_resources_path ( POLICY_SPEC_YAML )
128+ self .json_file = POLICY_SPEC_JSON
129+ self .yaml_file = POLICY_SPEC_YAML
113130 super (TestCloudPolicyManagement , self ).__init__ (* args , ** kwargs )
114131
115132 def test_create_policy_from_json (self ):
@@ -246,10 +263,12 @@ def _get_tpp_policy_name():
246263 time = timestamp ()
247264 return f"{ _get_app_name ().format (time )} "
248265
249-
250- def _resolve_resources_path (path ):
251- resources_dir = os .path .dirname (__file__ )
252- log .debug (f"Testing root folder: [{ resources_dir } ]" )
253- resolved_path = f"./{ path } " if resources_dir .endswith ('tests' ) else f"./tests/{ path } "
254- log .debug (f"resolved path: [{ resolved_path } ]" )
255- return resolved_path
266+ # def _resolve_resources_path(path):
267+ # resources_dir = os.path.dirname(__file__)
268+ # log.debug(f"Testing root folder: [{resources_dir}]")
269+ # if resources_dir.endswith('tests'):
270+ # resolved_path = f"./{path}"
271+ # else:
272+ # resolved_path = f"./tests/{path}"
273+ # log.debug(f"resolved path: [{resolved_path}]")
274+ # return resolved_path
0 commit comments