mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-01-31 08:25:35 +00:00
Move the last three mock-using tests to test_tor_provider
where they can be rewritten later
This commit is contained in:
parent
3d82ca0d25
commit
9f28ccb2a4
@ -1,8 +1,6 @@
|
||||
import mock
|
||||
|
||||
from twisted.trial import unittest
|
||||
from twisted.internet import reactor
|
||||
from twisted.internet.interfaces import IStreamClientEndpoint
|
||||
|
||||
from foolscap.connections import tcp
|
||||
|
||||
@ -66,48 +64,6 @@ class CreateConnectionHandlersTests(SyncTestCase):
|
||||
|
||||
class Tor(unittest.TestCase):
|
||||
|
||||
def test_socksport_unix_endpoint(self):
|
||||
h1 = mock.Mock()
|
||||
with mock.patch("foolscap.connections.tor.socks_endpoint",
|
||||
return_value=h1) as f:
|
||||
config = config_from_string(
|
||||
"fake.port",
|
||||
"no-basedir",
|
||||
BASECONFIG + "[tor]\nsocks.port = unix:/var/lib/fw-daemon/tor_socks.socket\n",
|
||||
)
|
||||
tor_provider = create_tor_provider(reactor, config)
|
||||
h = tor_provider.get_tor_handler()
|
||||
self.assertTrue(IStreamClientEndpoint.providedBy(f.mock_calls[0][1][0]))
|
||||
self.assertIdentical(h, h1)
|
||||
|
||||
def test_socksport_endpoint(self):
|
||||
h1 = mock.Mock()
|
||||
with mock.patch("foolscap.connections.tor.socks_endpoint",
|
||||
return_value=h1) as f:
|
||||
config = config_from_string(
|
||||
"fake.port",
|
||||
"no-basedir",
|
||||
BASECONFIG + "[tor]\nsocks.port = tcp:127.0.0.1:1234\n",
|
||||
)
|
||||
tor_provider = create_tor_provider(reactor, config)
|
||||
h = tor_provider.get_tor_handler()
|
||||
self.assertTrue(IStreamClientEndpoint.providedBy(f.mock_calls[0][1][0]))
|
||||
self.assertIdentical(h, h1)
|
||||
|
||||
def test_socksport_endpoint_otherhost(self):
|
||||
h1 = mock.Mock()
|
||||
with mock.patch("foolscap.connections.tor.socks_endpoint",
|
||||
return_value=h1) as f:
|
||||
config = config_from_string(
|
||||
"no-basedir",
|
||||
"fake.port",
|
||||
BASECONFIG + "[tor]\nsocks.port = tcp:otherhost:1234\n",
|
||||
)
|
||||
tor_provider = create_tor_provider(reactor, config)
|
||||
h = tor_provider.get_tor_handler()
|
||||
self.assertTrue(IStreamClientEndpoint.providedBy(f.mock_calls[0][1][0]))
|
||||
self.assertIdentical(h, h1)
|
||||
|
||||
def test_socksport_bad_endpoint(self):
|
||||
config = config_from_string(
|
||||
"fake.port",
|
||||
|
@ -369,6 +369,46 @@ class Provider(unittest.TestCase):
|
||||
tor.socks_endpoint.assert_called_with(ep)
|
||||
self.assertIs(h, handler)
|
||||
|
||||
def test_handler_socks_unix_endpoint(self):
|
||||
"""
|
||||
``socks.port`` can be configured as a UNIX client endpoint.
|
||||
"""
|
||||
tor = mock.Mock()
|
||||
handler = object()
|
||||
tor.socks_endpoint = mock.Mock(return_value=handler)
|
||||
ep = object()
|
||||
cfs = mock.Mock(return_value=ep)
|
||||
reactor = object()
|
||||
|
||||
with mock_tor(tor):
|
||||
p = tor_provider.create(reactor,
|
||||
FakeConfig(**{"socks.port": "unix:path"}))
|
||||
with mock.patch("allmydata.util.tor_provider.clientFromString", cfs):
|
||||
h = p.get_tor_handler()
|
||||
cfs.assert_called_with(reactor, "unix:path")
|
||||
tor.socks_endpoint.assert_called_with(ep)
|
||||
self.assertIs(h, handler)
|
||||
|
||||
def test_handler_socks_tcp_endpoint(self):
|
||||
"""
|
||||
``socks.port`` can be configured as a UNIX client endpoint.
|
||||
"""
|
||||
tor = mock.Mock()
|
||||
handler = object()
|
||||
tor.socks_endpoint = mock.Mock(return_value=handler)
|
||||
ep = object()
|
||||
cfs = mock.Mock(return_value=ep)
|
||||
reactor = object()
|
||||
|
||||
with mock_tor(tor):
|
||||
p = tor_provider.create(reactor,
|
||||
FakeConfig(**{"socks.port": "tcp:127.0.0.1:1234"}))
|
||||
with mock.patch("allmydata.util.tor_provider.clientFromString", cfs):
|
||||
h = p.get_tor_handler()
|
||||
cfs.assert_called_with(reactor, "tcp:127.0.0.1:1234")
|
||||
tor.socks_endpoint.assert_called_with(ep)
|
||||
self.assertIs(h, handler)
|
||||
|
||||
def test_handler_control_endpoint(self):
|
||||
tor = mock.Mock()
|
||||
handler = object()
|
||||
|
Loading…
x
Reference in New Issue
Block a user