2322
2322
self.assertEqual(('error', 'abc'), exc.error_tuple)
2325
class TestMessageHandlerErrors(tests.TestCase):
2326
"""Tests for v3 that unrecognised (but well-formed) requests/responses are
2327
still fully read off the wire, so that subsequent requests/responses on the
2328
same medium can be decoded.
2331
def test_non_conventional_request(self):
2332
"""ConventionalRequestHandler (the default message handler on the
2333
server side) will reject an unconventional message, but still consume
2334
all the bytes of that message and signal when it has done so.
2336
This is what allows a server to continue to accept requests after the
2337
client sends a completely unrecognised request.
2339
# Define an invalid request (but one that is a well-formed message).
2340
# This particular invalid request not only lacks the mandatory
2341
# verb+args tuple, it has a single-byte part, which is forbidden. In
2342
# fact it has that part twice, to trigger multiple errors.
2344
protocol.MESSAGE_VERSION_THREE + # protocol version marker
2345
'\0\0\0\x02de' + # empty headers
2346
'oX' + # a single byte part: 'X'. ConventionalRequestHandler will
2347
# error at this part.
2349
'e' # end of message
2352
to_server = StringIO(invalid_request)
2353
from_server = StringIO()
2354
transport = memory.MemoryTransport('memory:///')
2355
server = medium.SmartServerPipeStreamMedium(
2356
to_server, from_server, transport)
2357
proto = server._build_protocol()
2358
message_handler = proto.message_handler
2359
server._serve_one_request(proto)
2360
# All the bytes have been read from the medium...
2361
self.assertEqual('', to_server.read())
2362
# ...and the protocol decoder has consumed all the bytes, and has
2364
self.assertEqual('', proto.unused_data)
2365
self.assertEqual(0, proto.next_read_size())
2325
2368
class InstrumentedRequestHandler(object):
2326
2369
"""Test Double of SmartServerRequestHandler."""