diff options
author | Joanna Jeremicz <joanna.jeremicz@nokia.com> | 2020-06-15 16:21:55 +0200 |
---|---|---|
committer | Joanna Jeremicz <joanna.jeremicz@nokia.com> | 2020-06-19 11:37:41 +0200 |
commit | c21b0084bfbe44af90047f23141e90a8bdb41482 (patch) | |
tree | d3d22a49e57f4448ad21568f64bbefa31763af5e /tests/aaf/certservice/libraries/PemArtifactsValidator.py | |
parent | da61def8bfefd1000a882e7108f3f1943392f914 (diff) |
Add testcases for PEM and JKS output type
Issue-ID: AAF-1152
Change-Id: I99f7fadf7e4e890ff86011226dbcf3761c185072
Signed-off-by: Joanna Jeremicz <joanna.jeremicz@nokia.com>
Diffstat (limited to 'tests/aaf/certservice/libraries/PemArtifactsValidator.py')
-rw-r--r-- | tests/aaf/certservice/libraries/PemArtifactsValidator.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/aaf/certservice/libraries/PemArtifactsValidator.py b/tests/aaf/certservice/libraries/PemArtifactsValidator.py new file mode 100644 index 00000000..46e0357e --- /dev/null +++ b/tests/aaf/certservice/libraries/PemArtifactsValidator.py @@ -0,0 +1,39 @@ +import os +from OpenSSL import crypto +from cryptography import x509 +from cryptography.hazmat.backends import default_backend +from EnvsReader import EnvsReader +from ArtifactParser import ArtifactParser + +class PemArtifactsValidator: + + def __init__(self, mount_path): + self.parser = ArtifactParser(mount_path, "pem") + self.key = mount_path + '/key.pem' + + def get_and_compare_data_pem(self, path_to_env): + data = self.get_data_pem(path_to_env) + return data, self.parser.contains_expected_data(data) + + def artifacts_exist_and_are_not_empty(self): + keystoreExists = self.file_exists_and_is_not_empty(self.parser.keystorePath) + truststoreExists = self.file_exists_and_is_not_empty(self.parser.truststorePath) + keyExists = self.file_exists_and_is_not_empty(self.key) + return keystoreExists and truststoreExists and keyExists + + def file_exists_and_is_not_empty(self, pathToFile): + return os.path.isfile(pathToFile) and os.path.getsize(pathToFile) > 0 + + def get_data_pem(self, path_to_env): + envs = self.parser.get_envs_as_dict(EnvsReader().read_env_list_from_file(path_to_env)) + certificate = self.get_keystore_certificate() + data = self.parser.get_owner_data_from_certificate(certificate) + data['SANS'] = self.parser.get_sans(certificate) + return type('', (object,), {"expectedData": envs, "actualData": data}) + + def get_keystore_certificate(self): + return crypto.X509.from_cryptography(self.load_x509_certificate()) + + def load_x509_certificate(self): + cert = x509.load_pem_x509_certificate(open(self.parser.keystorePath, 'rb').read(), default_backend()) + return cert |