From ecd06776ab60159ff288520f57933a8491a2b42c Mon Sep 17 00:00:00 2001 From: Chris Mayo Date: Mon, 11 Nov 2019 20:12:25 +0000 Subject: [PATCH] Fix TypeError when checking https link and test File "/usr/lib/python3.7/site-packages/linkcheck/httputil.py", line 68, in asn1_generaltime_to_seconds line: res = datetime.strptime(timestr, timeformat + 'Z') locals: res = None datetime = datetime.strptime = timestr = b'20191106202117Z' timeformat = '%Y%m%d%H%M%S' TypeError: strptime() argument 1 must be str, not bytes pyOpenSSL OpenSSL.crypto.X509.get_notAfter() returns bytes: https://www.pyopenssl.org/en/stable/api/crypto.html#OpenSSL.crypto.X509.get_notAfter --- tests/checker/test_https.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/checker/test_https.py b/tests/checker/test_https.py index efd0e221..dc8fcc01 100644 --- a/tests/checker/test_https.py +++ b/tests/checker/test_https.py @@ -23,6 +23,8 @@ from tests import need_network from .httpserver import HttpsServerTest, CookieRedirectHttpRequestHandler from .. import get_file +from linkcheck import httputil + class TestHttps(HttpsServerTest): """ @@ -63,3 +65,9 @@ class TestHttps(HttpsServerTest): sslverify=False ) self.direct(url, resultlines, recursionlevel=0, confargs=confargs) + + def test_x509_to_dict(self): + with open(get_file("https_cert.pem"), "rb") as f: + cert = crypto.load_certificate(crypto.FILETYPE_PEM, f.read()) + self.assertEqual(httputil.x509_to_dict(cert)["notAfter"], + "Jan 02 03:04:05 2119 GMT")