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 = <local> None
      datetime = <global> <class 'datetime.datetime'>
      datetime.strptime = <global> <built-in method strptime of type object at 0x7fa39064dda0>
      timestr = <local> b'20191106202117Z'
      timeformat = <local> '%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
This commit is contained in:
Chris Mayo 2019-11-11 20:12:25 +00:00
parent dee4be4b1d
commit ecd06776ab

View file

@ -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")