fix welcome-error signalling

The handler was calling _signal_error() incorrectly.
This commit is contained in:
Brian Warner 2016-05-26 15:37:24 -07:00
parent 80c88387ef
commit 905ec05696
4 changed files with 48 additions and 4 deletions

View File

@ -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

View File

@ -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):

View File

@ -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"))])

View File

@ -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")