assert url/realm is unicode; do not try to six.u unicode (fixes #470)
This commit is contained in:
@@ -107,6 +107,9 @@ class ApplicationRunner(object):
|
|||||||
kwarg.
|
kwarg.
|
||||||
:type ssl: :class:`ssl.SSLContext` or bool
|
: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.url = url
|
||||||
self.realm = realm
|
self.realm = realm
|
||||||
self.extra = extra or dict()
|
self.extra = extra or dict()
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ from autobahn.wamp.types import ComponentConfig
|
|||||||
from autobahn.websocket.protocol import parseWsUrl
|
from autobahn.websocket.protocol import parseWsUrl
|
||||||
from autobahn.twisted.websocket import WampWebSocketClientFactory
|
from autobahn.twisted.websocket import WampWebSocketClientFactory
|
||||||
|
|
||||||
import six
|
|
||||||
import txaio
|
import txaio
|
||||||
txaio.use_twisted()
|
txaio.use_twisted()
|
||||||
|
|
||||||
@@ -118,6 +117,9 @@ class ApplicationRunner(object):
|
|||||||
your distribution's CA certificates.
|
your distribution's CA certificates.
|
||||||
:type ssl: :class:`twisted.internet.ssl.CertificateOptions`
|
: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.url = url
|
||||||
self.realm = realm
|
self.realm = realm
|
||||||
self.extra = extra or dict()
|
self.extra = extra or dict()
|
||||||
@@ -190,7 +192,7 @@ class ApplicationRunner(object):
|
|||||||
context_factory = self.ssl
|
context_factory = self.ssl
|
||||||
elif isSecure:
|
elif isSecure:
|
||||||
from twisted.internet.ssl import optionsForClientTLS
|
from twisted.internet.ssl import optionsForClientTLS
|
||||||
context_factory = optionsForClientTLS(six.u(host))
|
context_factory = optionsForClientTLS(host)
|
||||||
|
|
||||||
if isSecure:
|
if isSecure:
|
||||||
from twisted.internet.endpoints import SSL4ClientEndpoint
|
from twisted.internet.endpoints import SSL4ClientEndpoint
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ if os.environ.get('USE_TWISTED', False):
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
raise unittest.SkipTest('No twisted')
|
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!")
|
exception = ConnectionRefusedError("It's a trap!")
|
||||||
|
|
||||||
with patch('twisted.internet.reactor', FakeReactor(exception)) as mockreactor:
|
with patch('twisted.internet.reactor', FakeReactor(exception)) as mockreactor:
|
||||||
@@ -117,7 +117,7 @@ else:
|
|||||||
loop.run_until_complete = Mock(return_value=(Mock(), Mock()))
|
loop.run_until_complete = Mock(return_value=(Mock(), Mock()))
|
||||||
with patch.object(asyncio, 'get_event_loop', return_value=loop):
|
with patch.object(asyncio, 'get_event_loop', return_value=loop):
|
||||||
ssl = {}
|
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)
|
ssl=ssl)
|
||||||
runner.run('_unused_')
|
runner.run('_unused_')
|
||||||
self.assertIs(ssl, loop.create_connection.call_args[1]['ssl'])
|
self.assertIs(ssl, loop.create_connection.call_args[1]['ssl'])
|
||||||
@@ -131,7 +131,7 @@ else:
|
|||||||
loop = Mock()
|
loop = Mock()
|
||||||
loop.run_until_complete = Mock(return_value=(Mock(), Mock()))
|
loop.run_until_complete = Mock(return_value=(Mock(), Mock()))
|
||||||
with patch.object(asyncio, 'get_event_loop', return_value=loop):
|
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_')
|
runner.run('_unused_')
|
||||||
self.assertIs(False, loop.create_connection.call_args[1]['ssl'])
|
self.assertIs(False, loop.create_connection.call_args[1]['ssl'])
|
||||||
|
|
||||||
@@ -144,7 +144,7 @@ else:
|
|||||||
loop = Mock()
|
loop = Mock()
|
||||||
loop.run_until_complete = Mock(return_value=(Mock(), Mock()))
|
loop.run_until_complete = Mock(return_value=(Mock(), Mock()))
|
||||||
with patch.object(asyncio, 'get_event_loop', return_value=loop):
|
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_')
|
runner.run('_unused_')
|
||||||
self.assertIs(True, loop.create_connection.call_args[1]['ssl'])
|
self.assertIs(True, loop.create_connection.call_args[1]['ssl'])
|
||||||
|
|
||||||
@@ -156,7 +156,7 @@ else:
|
|||||||
loop = Mock()
|
loop = Mock()
|
||||||
loop.run_until_complete = Mock(return_value=(Mock(), Mock()))
|
loop.run_until_complete = Mock(return_value=(Mock(), Mock()))
|
||||||
with patch.object(asyncio, 'get_event_loop', return_value=loop):
|
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)
|
ssl=True)
|
||||||
error = ('^ssl argument value passed to ApplicationRunner '
|
error = ('^ssl argument value passed to ApplicationRunner '
|
||||||
'conflicts with the "ws:" prefix of the url '
|
'conflicts with the "ws:" prefix of the url '
|
||||||
@@ -189,7 +189,7 @@ else:
|
|||||||
loop = Mock()
|
loop = Mock()
|
||||||
loop.run_until_complete = Mock(return_value=(Mock(), Mock()))
|
loop.run_until_complete = Mock(return_value=(Mock(), Mock()))
|
||||||
with patch.object(asyncio, 'get_event_loop', return_value=loop):
|
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)
|
ssl=context)
|
||||||
error = ('^ssl argument value passed to ApplicationRunner '
|
error = ('^ssl argument value passed to ApplicationRunner '
|
||||||
'conflicts with the "ws:" prefix of the url '
|
'conflicts with the "ws:" prefix of the url '
|
||||||
|
|||||||
Reference in New Issue
Block a user