|
19 | 19 | import unittest |
20 | 20 |
|
21 | 21 | 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 |
23 | 23 | from test_utils import timestamp |
24 | 24 | 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) |
26 | 26 | from vcert.ssh_utils import SSHRetrieveResponse, SSHKeyPair, SSHCATemplateRequest |
27 | 27 |
|
28 | 28 | log = logger.get_child("test-ssh") |
|
31 | 31 | SSH_CERT_DATA_ERROR = "Certificate data is empty for Certificate {}" # type: str |
32 | 32 |
|
33 | 33 |
|
34 | | -class TestTPPSSHCertificate(unittest.TestCase): |
| 34 | +class TestTPPTokenSSHCertificate(unittest.TestCase): |
35 | 35 | def __init__(self, *args, **kwargs): |
36 | 36 | self.tpp_conn = TPPTokenConnection(url=TPP_TOKEN_URL, http_request_kwargs={'verify': "/tmp/chain.pem"}) |
37 | 37 | auth = Authentication(user=TPP_USER, password=TPP_PASSWORD, scope=SCOPE_SSH) |
38 | 38 | self.tpp_conn.get_access_token(auth) |
39 | | - super(TestTPPSSHCertificate, self).__init__(*args, **kwargs) |
| 39 | + super(TestTPPTokenSSHCertificate, self).__init__(*args, **kwargs) |
40 | 40 |
|
41 | 41 | def test_enroll_local_generated_keypair(self): |
42 | 42 | keypair = SSHKeyPair() |
@@ -75,8 +75,20 @@ def test_retrieve_ca_public_key(self): |
75 | 75 | log.debug(f"{TPP_SSH_CADN} Public Key data:\n{ssh_config.ca_public_key}") |
76 | 76 |
|
77 | 77 | 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) |
80 | 92 | self.assertIsNotNone(ssh_config.ca_public_key, f"{TPP_SSH_CADN} Public Key data is empty") |
81 | 93 | self.assertIsNotNone(ssh_config.ca_principals, f"{TPP_SSH_CADN} default principals is empty") |
82 | 94 | log.debug(f"{TPP_SSH_CADN} Public Key data: {ssh_config.ca_public_key}") |
@@ -122,5 +134,16 @@ def _enroll_ssh_cert(connector, request): |
122 | 134 | return response |
123 | 135 |
|
124 | 136 |
|
| 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 | + |
125 | 148 | def _random_key_id(): |
126 | 149 | return f"vcert-python-ssh-{timestamp()}" |
0 commit comments