From d1f14e882b924b7bde14cee21ee146fe202eaba9 Mon Sep 17 00:00:00 2001 From: Tobias Oberstein Date: Sat, 5 Sep 2015 02:42:07 +0200 Subject: [PATCH] assert url/realm is unicode; do not try to six.u unicode (fixes #470) --- autobahn/asyncio/wamp.py | 3 +++ autobahn/twisted/wamp.py | 6 ++++-- autobahn/wamp/test/test_runner.py | 12 ++++++------ 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/autobahn/asyncio/wamp.py b/autobahn/asyncio/wamp.py index a9e2f025..60ab4075 100644 --- a/autobahn/asyncio/wamp.py +++ b/autobahn/asyncio/wamp.py @@ -107,6 +107,9 @@ class ApplicationRunner(object): kwarg. :type ssl: :class:`ssl.SSLContext` or bool """ + assert(type(url) == unicode) + assert(type(realm) == unicode) + assert(extra is None or type(extra) == dict) self.url = url self.realm = realm self.extra = extra or dict() diff --git a/autobahn/twisted/wamp.py b/autobahn/twisted/wamp.py index 544b6fd8..d561dee7 100644 --- a/autobahn/twisted/wamp.py +++ b/autobahn/twisted/wamp.py @@ -37,7 +37,6 @@ from autobahn.wamp.types import ComponentConfig from autobahn.websocket.protocol import parseWsUrl from autobahn.twisted.websocket import WampWebSocketClientFactory -import six import txaio txaio.use_twisted() @@ -118,6 +117,9 @@ class ApplicationRunner(object): your distribution's CA certificates. :type ssl: :class:`twisted.internet.ssl.CertificateOptions` """ + assert(type(url) == unicode) + assert(type(realm) == unicode) + assert(extra is None or type(extra) == dict) self.url = url self.realm = realm self.extra = extra or dict() @@ -190,7 +192,7 @@ class ApplicationRunner(object): context_factory = self.ssl elif isSecure: from twisted.internet.ssl import optionsForClientTLS - context_factory = optionsForClientTLS(six.u(host)) + context_factory = optionsForClientTLS(host) if isSecure: from twisted.internet.endpoints import SSL4ClientEndpoint diff --git a/autobahn/wamp/test/test_runner.py b/autobahn/wamp/test/test_runner.py index 755167a4..31b2e3e0 100644 --- a/autobahn/wamp/test/test_runner.py +++ b/autobahn/wamp/test/test_runner.py @@ -72,7 +72,7 @@ if os.environ.get('USE_TWISTED', False): except ImportError: raise unittest.SkipTest('No twisted') - runner = ApplicationRunner('ws://localhost:1', 'realm') + runner = ApplicationRunner(u'ws://localhost:1', u'realm') exception = ConnectionRefusedError("It's a trap!") with patch('twisted.internet.reactor', FakeReactor(exception)) as mockreactor: @@ -117,7 +117,7 @@ else: loop.run_until_complete = Mock(return_value=(Mock(), Mock())) with patch.object(asyncio, 'get_event_loop', return_value=loop): ssl = {} - runner = ApplicationRunner('ws://127.0.0.1:8080/ws', 'realm', + runner = ApplicationRunner(u'ws://127.0.0.1:8080/ws', u'realm', ssl=ssl) runner.run('_unused_') self.assertIs(ssl, loop.create_connection.call_args[1]['ssl']) @@ -131,7 +131,7 @@ else: loop = Mock() loop.run_until_complete = Mock(return_value=(Mock(), Mock())) with patch.object(asyncio, 'get_event_loop', return_value=loop): - runner = ApplicationRunner('ws://127.0.0.1:8080/ws', 'realm') + runner = ApplicationRunner(u'ws://127.0.0.1:8080/ws', u'realm') runner.run('_unused_') self.assertIs(False, loop.create_connection.call_args[1]['ssl']) @@ -144,7 +144,7 @@ else: loop = Mock() loop.run_until_complete = Mock(return_value=(Mock(), Mock())) with patch.object(asyncio, 'get_event_loop', return_value=loop): - runner = ApplicationRunner('wss://127.0.0.1:8080/wss', 'realm') + runner = ApplicationRunner(u'wss://127.0.0.1:8080/wss', u'realm') runner.run('_unused_') self.assertIs(True, loop.create_connection.call_args[1]['ssl']) @@ -156,7 +156,7 @@ else: loop = Mock() loop.run_until_complete = Mock(return_value=(Mock(), Mock())) with patch.object(asyncio, 'get_event_loop', return_value=loop): - runner = ApplicationRunner('ws://127.0.0.1:8080/wss', 'realm', + runner = ApplicationRunner(u'ws://127.0.0.1:8080/wss', u'realm', ssl=True) error = ('^ssl argument value passed to ApplicationRunner ' 'conflicts with the "ws:" prefix of the url ' @@ -189,7 +189,7 @@ else: loop = Mock() loop.run_until_complete = Mock(return_value=(Mock(), Mock())) with patch.object(asyncio, 'get_event_loop', return_value=loop): - runner = ApplicationRunner('ws://127.0.0.1:8080/wss', 'realm', + runner = ApplicationRunner(u'ws://127.0.0.1:8080/wss', u'realm', ssl=context) error = ('^ssl argument value passed to ApplicationRunner ' 'conflicts with the "ws:" prefix of the url '