Add a test for DOWNLOADER_CLIENT_TLS_VERBOSE_LOGGING.

This commit is contained in:
Andrey Rakhmatullin 2019-07-12 18:44:45 +05:00
parent 98689b27a8
commit a96a07bc76
1 changed files with 21 additions and 0 deletions

View File

@ -8,6 +8,7 @@ try:
except ImportError:
import mock
from testfixtures import LogCapture
from twisted.trial import unittest
from twisted.protocols.policies import WrappingFactory
from twisted.python.filepath import FilePath
@ -503,6 +504,24 @@ class Http11TestCase(HttpTestCase):
class Https11TestCase(Http11TestCase):
scheme = 'https'
tls_log_message = 'SSL connection certificate: issuer "/C=IE/O=Scrapy/CN=localhost", subject "/C=IE/O=Scrapy/CN=localhost"'
@defer.inlineCallbacks
def test_tls_logging(self):
download_handler = self.download_handler_cls(Settings({
'DOWNLOADER_CLIENT_TLS_VERBOSE_LOGGING': True,
}))
try:
with LogCapture() as log_capture:
request = Request(self.getURL('file'))
d = download_handler.download_request(request, Spider('foo'))
d.addCallback(lambda r: r.body)
d.addCallback(self.assertEqual, b"0123456789")
yield d
log_capture.check_present(('scrapy.core.downloader.tls', 'DEBUG', self.tls_log_message))
finally:
yield download_handler.close()
class Https11WrongHostnameTestCase(Http11TestCase):
scheme = 'https'
@ -523,6 +542,7 @@ class Https11InvalidDNSId(Https11TestCase):
super(Https11InvalidDNSId, self).setUp()
self.host = '127.0.0.1'
class Https11InvalidDNSPattern(Https11TestCase):
"""Connect to HTTPS hosts where the certificate are issued to an ip instead of a domain."""
@ -534,6 +554,7 @@ class Https11InvalidDNSPattern(Https11TestCase):
from service_identity.exceptions import CertificateError
except ImportError:
raise unittest.SkipTest("cryptography lib is too old")
self.tls_log_message = 'SSL connection certificate: issuer "/C=IE/O=Scrapy/CN=127.0.0.1", subject "/C=IE/O=Scrapy/CN=127.0.0.1"'
super(Https11InvalidDNSPattern, self).setUp()