Add basic unit tests for module_utils/acme.py. (#49103)

This commit is contained in:
Felix Fontein 2018-11-29 10:32:15 +01:00 committed by John R Barker
commit 1e0ab16247
2 changed files with 204 additions and 2 deletions

View file

@ -795,7 +795,7 @@ def cryptography_get_csr_domains(module, csr_filename):
return domains
def cryptography_get_cert_days(module, cert_file):
def cryptography_get_cert_days(module, cert_file, now=None):
'''
Return the days the certificate in cert_file remains valid and -1
if the file was not found. If cert_file contains more than one
@ -808,7 +808,8 @@ def cryptography_get_cert_days(module, cert_file):
cert = cryptography.x509.load_pem_x509_certificate(read_file(cert_file), _cryptography_backend)
except Exception as e:
raise ModuleFailException('Cannot parse certificate {0}: {1}'.format(cert_file, e))
now = datetime.datetime.now()
if now is None:
now = datetime.datetime.now()
return (cert.not_valid_after - now).days