From 905ec056964708e4197927beb55a3f35586b9694 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Thu, 26 May 2016 15:37:24 -0700 Subject: [PATCH] fix welcome-error signalling The handler was calling _signal_error() incorrectly. --- src/wormhole/test/common.py | 6 ++++- src/wormhole/test/test_scripts.py | 39 +++++++++++++++++++++++++++++- src/wormhole/test/test_wormhole.py | 4 ++- src/wormhole/wormhole.py | 3 ++- 4 files changed, 48 insertions(+), 4 deletions(-) diff --git a/src/wormhole/test/common.py b/src/wormhole/test/common.py index 46ffe90..18008a1 100644 --- a/src/wormhole/test/common.py +++ b/src/wormhole/test/common.py @@ -7,13 +7,17 @@ from .. import __version__ class ServerBase: def setUp(self): + self._setup_relay(None) + + def _setup_relay(self, error): self.sp = service.MultiService() self.sp.startService() relayport = allocate_tcp_port() transitport = allocate_tcp_port() s = RelayServer("tcp:%d:interface=127.0.0.1" % relayport, "tcp:%s:interface=127.0.0.1" % transitport, - __version__) + advertise_version=__version__, + signal_error=error) s.setServiceParent(self.sp) self._rendezvous = s._rendezvous self._transit_server = s._transit diff --git a/src/wormhole/test/test_scripts.py b/src/wormhole/test/test_scripts.py index a2d042b..5bf89be 100644 --- a/src/wormhole/test/test_scripts.py +++ b/src/wormhole/test/test_scripts.py @@ -7,7 +7,7 @@ from twisted.internet.defer import gatherResults, inlineCallbacks from .. import __version__ from .common import ServerBase from ..cli import runner, cmd_send, cmd_receive -from ..errors import TransferError, WrongPasswordError +from ..errors import TransferError, WrongPasswordError, WelcomeError from ..timing import DebugTiming def build_offer(args): @@ -517,6 +517,43 @@ class PregeneratedCode(ServerBase, ScriptsBase, unittest.TestCase): with open(fn, "r") as f: self.failUnlessEqual(f.read(), PRESERVE) +class NotWelcome(ServerBase, unittest.TestCase): + def setUp(self): + self._setup_relay(error=u"please upgrade XYZ") + + @inlineCallbacks + def test_sender(self): + common_args = ["--hide-progress", "--no-listen", + "--relay-url", self.relayurl, + "--transit-helper", ""] + send_args = common_args + [ "send", "--text", "hi", + "--code", u"1-abc" ] + sargs = runner.parser.parse_args(send_args) + sargs.cwd = self.mktemp() + sargs.stdout = io.StringIO() + sargs.stderr = io.StringIO() + sargs.timing = DebugTiming() + + send_d = cmd_send.send(sargs) + f = yield self.assertFailure(send_d, WelcomeError) + self.assertEqual(str(f), "please upgrade XYZ") + + @inlineCallbacks + def test_receiver(self): + common_args = ["--hide-progress", "--no-listen", + "--relay-url", self.relayurl, + "--transit-helper", ""] + receive_args = common_args + [ "receive", u"1-abc" ] + rargs = runner.parser.parse_args(receive_args) + rargs.cwd = self.mktemp() + rargs.stdout = io.StringIO() + rargs.stderr = io.StringIO() + rargs.timing = DebugTiming() + + receive_d = cmd_receive.receive(rargs) + f = yield self.assertFailure(receive_d, WelcomeError) + self.assertEqual(str(f), "please upgrade XYZ") + class Cleanup(ServerBase, unittest.TestCase): @inlineCallbacks def test_text(self): diff --git a/src/wormhole/test/test_wormhole.py b/src/wormhole/test/test_wormhole.py index 26c7d87..efff68e 100644 --- a/src/wormhole/test/test_wormhole.py +++ b/src/wormhole/test/test_wormhole.py @@ -87,10 +87,12 @@ class Welcome(unittest.TestCase): w.handle_welcome({u"error": u"oops"}) self.assertEqual(len(se.mock_calls), 1) - self.assertEqual(len(se.mock_calls[0][1]), 1) # posargs + self.assertEqual(len(se.mock_calls[0][1]), 2) # posargs we = se.mock_calls[0][1][0] self.assertIsInstance(we, WelcomeError) self.assertEqual(we.args, (u"oops",)) + mood = se.mock_calls[0][1][1] + self.assertEqual(mood, u"unwelcome") # alas WelcomeError instances don't compare against each other #self.assertEqual(se.mock_calls, [mock.call(WelcomeError(u"oops"))]) diff --git a/src/wormhole/wormhole.py b/src/wormhole/wormhole.py index 00833d7..ec47cbf 100644 --- a/src/wormhole/wormhole.py +++ b/src/wormhole/wormhole.py @@ -205,7 +205,8 @@ class _WelcomeHandler: self._version_warning_displayed = True if "error" in welcome: - return self._signal_error(WelcomeError(welcome["error"])) + return self._signal_error(WelcomeError(welcome["error"]), + u"unwelcome") # states for nameplates, mailboxes, and the websocket connection (CLOSED, OPENING, OPEN, CLOSING) = ("closed", "opening", "open", "closing")