Skip to content

Commit

Permalink
Merge pull request #73 from markrwilliams/72-verifyingcontext-test
Browse files Browse the repository at this point in the history
test_ssl_hostname_verification honors its docstring.
  • Loading branch information
mithrandi authored Jun 11, 2017
2 parents 8127b45 + b08a5e8 commit e64d2ec
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
try:
from setuptools import find_packages
extra_setup_args['install_requires'] = [
'attrs', 'python-dateutil', 'twisted[tls]>=15.5.0,!=17.1.0', 'venusian', 'lxml',
'attrs', 'python-dateutil', 'twisted[tls]>=15.5.0', 'venusian', 'lxml',
'incremental', 'pyrsistent', 'constantly',
]
except ImportError:
Expand Down
31 changes: 19 additions & 12 deletions txaws/client/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import attr

from twisted.internet import reactor
from twisted.internet import reactor, ssl
from twisted.internet.defer import Deferred
from twisted.internet.error import ConnectionRefusedError
from twisted.protocols.policies import WrappingFactory
Expand All @@ -41,6 +41,8 @@
from txaws.service import AWSServiceEndpoint
from txaws.testing.producers import StringBodyProducer

from zope.interface.verify import verifyClass


class URLContextTests(TestCase):
"""
Expand Down Expand Up @@ -268,25 +270,30 @@ def test_ssl_hostname_verification(self):
sets to C{True}, a L{VerifyingContextFactory} is passed to
C{connectSSL}.
"""
agent_creations = []

class FakeReactor(object):
@implementer(IAgent)
class FakeAgent(object):
def __init__(self, reactor, contextFactory,
connectTimeout=None, bindAddress=None, pool=None):
agent_creations.append((reactor, contextFactory,
connectTimeout, bindAddress, pool))

def __init__(self):
self.connects = []
def request(self, method, uri, headers=None, bodyProducer=None):
return Deferred()

def connectSSL(self, host, port, factory, contextFactory, timeout,
bindAddress):
self.connects.append((host, port, factory, contextFactory))
verifyClass(IAgent, FakeAgent)

certs = [makeCertificate(O="Test Certificate", CN="something")[1]]
self.patch(base, "Agent", FakeAgent)
self.patch(ssl, "_ca_certs", certs)
fake_reactor = FakeReactor()
endpoint = AWSServiceEndpoint(ssl_hostname_verification=True)
query = BaseQuery("an action", "creds", endpoint, fake_reactor)
query = BaseQuery("an action", "creds", endpoint, reactor="ignored")
query.get_page("https://example.com/file")
[(host, port, factory, contextFactory)] = fake_reactor.connects
self.assertEqual("example.com", host)
self.assertEqual(443, port)

self.assertEqual(len(agent_creations), 1)
[(_, contextFactory, _, _, _)] = agent_creations
self.assertIsInstance(contextFactory, ssl.VerifyingContextFactory)


class StreamingBodyReceiverTestCase(TestCase):
Expand Down
Empty file added txaws/newsfragments/72.misc
Empty file.

0 comments on commit e64d2ec

Please sign in to comment.