Skip to content

Commit 4f0c8cd

Browse files
authored
Merge pull request #98 from Venafi/test-coverage
Test coverage
2 parents 182adb9 + 12099fd commit 4f0c8cd

5 files changed

Lines changed: 99 additions & 31 deletions

File tree

.github/version_history.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[![Venafi](./images/Venafi_logo.png)](https://www.venafi.com/)
2+
3+
[![Apache 2.0 License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
4+
![Community Supported](https://img.shields.io/badge/Support%20Level-Community-brightgreen)
5+
![Compatible with TPP 17.3+ & VaaS](https://img.shields.io/badge/Compatibility-TPP%2017.3+%20%26%20VaaS-f9a90c)
6+
[![pypi Downloads](https://img.shields.io/pypi/dw/vcert)](https://pypi.org/project/vcert/)
7+
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=Venafi_vcert-python&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=Venafi_vcert-python)
8+
9+
_**This open source project is community-supported.** To report a problem or share an idea, use
10+
**[Issues](../../issues)**; and if you have a suggestion for fixing the issue, please include those details, too.
11+
In addition, use **[Pull Requests](../../pulls)** to contribute actual bug fixes or proposed enhancements.
12+
We welcome and appreciate all contributions. Got questions or want to discuss something with our team?
13+
**[Join us on Slack](https://join.slack.com/t/venafi-integrations/shared_invite/zt-i8fwc379-kDJlmzU8OiIQOJFSwiA~dg)**!_
14+
15+
# Venafi Collection for Ansible
16+
## Version History
17+
18+
#### 0.14.0
19+
* **Dropped support for Python2. New baseline is Python 3.6+**
20+
* Minor bug fixes on Policy Management
21+
* Added integration with sonarcloud for code analysis
22+
* Created version history file

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ NOTE: While developing with vcert-python, it is helpful if you are using a virtu
100100
install the vcert-python library from source in development mode with `pip install --editable`.
101101
See https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/
102102

103+
## Version History
104+
105+
[Check version history here](.github/version_history.md)
106+
103107
## License
104108

105109
Copyright © Venafi, Inc. All rights reserved.

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: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@
2828
PolicySpecification)
2929
from 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'
3334
CA_TYPE_TPP = 'TPP'
3435

3536
log = logger.get_child("test-pm")
@@ -38,14 +39,12 @@
3839
class 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

6885
class 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):
108125
class 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

tests/test_ssh.py

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
import unittest
2020

2121
from assets import SSH_CERT_DATA, SSH_PRIVATE_KEY, SSH_PUBLIC_KEY
22-
from test_env import TPP_TOKEN_URL, TPP_USER, TPP_PASSWORD, TPP_SSH_CADN
22+
from test_env import TPP_TOKEN_URL, TPP_USER, TPP_PASSWORD, TPP_SSH_CADN, TPP_URL
2323
from test_utils import timestamp
2424
from vcert import (CommonConnection, SSHCertRequest, TPPTokenConnection, Authentication,
25-
SCOPE_SSH, write_ssh_files, logger, venafi_connection, VenafiPlatform)
25+
SCOPE_SSH, write_ssh_files, logger, venafi_connection, VenafiPlatform, TPPConnection)
2626
from vcert.ssh_utils import SSHRetrieveResponse, SSHKeyPair, SSHCATemplateRequest
2727

2828
log = logger.get_child("test-ssh")
@@ -31,12 +31,12 @@
3131
SSH_CERT_DATA_ERROR = "Certificate data is empty for Certificate {}" # type: str
3232

3333

34-
class TestTPPSSHCertificate(unittest.TestCase):
34+
class TestTPPTokenSSHCertificate(unittest.TestCase):
3535
def __init__(self, *args, **kwargs):
3636
self.tpp_conn = TPPTokenConnection(url=TPP_TOKEN_URL, http_request_kwargs={'verify': "/tmp/chain.pem"})
3737
auth = Authentication(user=TPP_USER, password=TPP_PASSWORD, scope=SCOPE_SSH)
3838
self.tpp_conn.get_access_token(auth)
39-
super(TestTPPSSHCertificate, self).__init__(*args, **kwargs)
39+
super(TestTPPTokenSSHCertificate, self).__init__(*args, **kwargs)
4040

4141
def test_enroll_local_generated_keypair(self):
4242
keypair = SSHKeyPair()
@@ -75,8 +75,20 @@ def test_retrieve_ca_public_key(self):
7575
log.debug(f"{TPP_SSH_CADN} Public Key data:\n{ssh_config.ca_public_key}")
7676

7777
def test_retrieve_ca_public_key_and_principals(self):
78-
request = SSHCATemplateRequest(ca_template=TPP_SSH_CADN)
79-
ssh_config = self.tpp_conn.retrieve_ssh_config(ca_request=request)
78+
ssh_config = _retrieve_ssh_config(self.tpp_conn)
79+
self.assertIsNotNone(ssh_config.ca_public_key, f"{TPP_SSH_CADN} Public Key data is empty")
80+
self.assertIsNotNone(ssh_config.ca_principals, f"{TPP_SSH_CADN} default principals is empty")
81+
log.debug(f"{TPP_SSH_CADN} Public Key data: {ssh_config.ca_public_key}")
82+
log.debug(f"{TPP_SSH_CADN} default principals: {ssh_config.ca_principals}")
83+
84+
85+
class TestTPPSSHCertificate(unittest.TestCase):
86+
def __init__(self, *args, **kwargs):
87+
self.tpp_conn = TPPConnection(TPP_USER, TPP_PASSWORD, TPP_URL, http_request_kwargs={'verify': "/tmp/chain.pem"})
88+
super(TestTPPSSHCertificate, self).__init__(*args, **kwargs)
89+
90+
def test_retrieve_ca_public_key_and_principals(self):
91+
ssh_config = _retrieve_ssh_config(self.tpp_conn)
8092
self.assertIsNotNone(ssh_config.ca_public_key, f"{TPP_SSH_CADN} Public Key data is empty")
8193
self.assertIsNotNone(ssh_config.ca_principals, f"{TPP_SSH_CADN} default principals is empty")
8294
log.debug(f"{TPP_SSH_CADN} Public Key data: {ssh_config.ca_public_key}")
@@ -122,5 +134,16 @@ def _enroll_ssh_cert(connector, request):
122134
return response
123135

124136

137+
def _retrieve_ssh_config(connection):
138+
"""
139+
140+
:param vcert.AbstractTPPConnection connection:
141+
:rtype: vcert.SSHConfig
142+
"""
143+
request = SSHCATemplateRequest(ca_template=TPP_SSH_CADN)
144+
ssh_config = connection.retrieve_ssh_config(ca_request=request)
145+
return ssh_config
146+
147+
125148
def _random_key_id():
126149
return f"vcert-python-ssh-{timestamp()}"

0 commit comments

Comments
 (0)