Merge "Replace use of deprecated cert.not_valid_after"

This commit is contained in:
Zuul 2024-06-06 15:06:30 +00:00 committed by Gerrit Code Review
commit fcc61e9ca8
2 changed files with 5 additions and 2 deletions

View File

@ -300,7 +300,7 @@ def get_cert_expiration(certificate_pem):
try:
cert = x509.load_pem_x509_certificate(certificate_pem,
backends.default_backend())
return cert.not_valid_after
return cert.not_valid_after_utc
except Exception as e:
LOG.exception('Unreadable Certificate.')
raise exceptions.UnreadableCert from e

View File

@ -246,7 +246,10 @@ class TestTLSParseUtils(base.TestCase):
def test_get_cert_expiration(self):
exp_date = cert_parser.get_cert_expiration(sample_certs.X509_EXPIRED)
self.assertEqual(datetime.datetime(2016, 9, 25, 18, 1, 54), exp_date)
self.assertEqual(
datetime.datetime(2016, 9, 25, 18, 1, 54,
tzinfo=datetime.timezone.utc),
exp_date)
# test the exception
self.assertRaises(exceptions.UnreadableCert,