Skip to content

Scrapy, a fast high-level web crawling & scraping framework for Python.

Add a test for DOWNLOADER_CLIENT_TLS_VERBOSE_LOGGING.

Andrey Rakhmatullina96a07bc7622
diff --git a/tests/test_downloader_handlers.py b/tests/test_downloader_handlers.py
index 81235a16f..8d0df6b5b 100644
--- a/tests/test_downloader_handlers.py
+++ b/tests/test_downloader_handlers.py
@@ -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()