Extend test coverage for openssl modules (#27548)

* openssl_privatekey: Extend test coverage

Extend the coverage of the integration test for the module
openssl_privatekey.

New tests have been added:

  * passphrase
  * idempotence
  * removal

Co-Authored-By: Pierre-Louis Bonicoli <pierre-louis.bonicoli@gmx.fr>

* openssl_publickey: Extend test coverage

Extend the coverage on the integration test for the module
openssl_publickey.

New tests have been added:

  * OpenSSH format
  * passphrase
  * idempotence
  * removal
This commit is contained in:
Yanis Guenane 2017-08-21 13:19:41 +02:00 committed by John R Barker
parent 4653f892c8
commit d4e7b045b7
7 changed files with 183 additions and 15 deletions

View file

@ -134,7 +134,7 @@ else:
pyopenssl_found = True
from ansible.module_utils import crypto as crypto_utils
from ansible.module_utils._text import to_native
from ansible.module_utils._text import to_native, to_bytes
from ansible.module_utils.basic import AnsibleModule
@ -181,11 +181,11 @@ class PrivateKey(crypto_utils.OpenSSLObject):
os.O_WRONLY | os.O_CREAT | os.O_TRUNC,
self.mode)
extras = {}
if self.cipher and self.passphrase:
extras = {'cipher': self.cipher, 'passphrase': self.passphrase}
os.write(privatekey_file, crypto.dump_privatekey(crypto.FILETYPE_PEM, self.privatekey, **extras))
os.write(privatekey_file, crypto.dump_privatekey(crypto.FILETYPE_PEM, self.privatekey,
self.cipher, to_bytes(self.passphrase)))
else:
os.write(privatekey_file, crypto.dump_privatekey(crypto.FILETYPE_PEM, self.privatekey))
os.close(privatekey_file)
self.changed = True
except IOError as exc: