Enable integration tests for the crypto/ namespace (#26684)

Crypto namespace contains the openssl modules. It has no integration
testing as of now.

This commits aims to add integration tests for the crypto namespace.
This will make it easier to spot breaking changes in the future.

This tests currently apply to:

  * openssl_privatekey
  * openssl_publickey
  * openssl_csr
This commit is contained in:
Yanis Guenane 2017-07-25 13:18:18 +02:00 committed by John R Barker
commit 8b22c45a45
20 changed files with 152 additions and 14 deletions

View file

@ -179,6 +179,7 @@ except ImportError:
else:
pyopenssl_found = True
from ansible.module_utils import crypto as crypto_utils
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils._text import to_native
@ -231,10 +232,11 @@ class CertificateSigningRequest(object):
if self.subjectAltName is not None:
req.add_extensions([crypto.X509Extension(b"subjectAltName", False, self.subjectAltName.encode('ascii'))])
privatekey_content = open(self.privatekey_path).read()
self.privatekey = crypto.load_privatekey(crypto.FILETYPE_PEM,
privatekey_content,
self.privatekey_passphrase)
self.privatekey = crypto_utils.load_privatekey(
self.privatekey_path,
self.privatekey_passphrase
)
req.set_pubkey(self.privatekey)
req.sign(self.privatekey, self.digest)
self.request = req

View file

@ -187,7 +187,7 @@ class PublicKey(object):
self.privatekey = crypto.load_privatekey(crypto.FILETYPE_PEM, privatekey_content)
publickey_content = crypto.dump_publickey(crypto.FILETYPE_PEM, self.privatekey)
publickey_file = open(self.path, 'w')
publickey_file = open(self.path, 'wb')
publickey_file.write(publickey_content)
publickey_file.close()