Index: twisted/conch/test/test_telnet.py =================================================================== --- twisted/conch/test/test_telnet.py (revision 38313) +++ twisted/conch/test/test_telnet.py (working copy) @@ -12,6 +12,7 @@ from twisted.internet import defer from twisted.conch import telnet +from twisted.conch.insults import insults from twisted.trial import unittest from twisted.test import proto_helpers @@ -765,3 +766,79 @@ self._deliver( 'z' + telnet.IAC + telnet.SB + 'Qx' + telnet.IAC + telnet.SE, ('bytes', 'z'), ('negotiate', 'Q', ['x'])) + + +class TelnetBootstrapProtocolTestCase(unittest.TestCase): + """ + Tests for L{telnet.TelnetBootstrapProtocol}. + """ + def setUp(self): + self.protocol = telnet.TelnetBootstrapProtocol(TestTelnet) + self.transport = telnet.TelnetTransport(TestProtocol) + t = proto_helpers.StringTransport() + self.transport.makeConnection(t) + self.protocol.makeConnection(self.transport) + + def test_protocolFactoryAssigned(self): + """ + The factory for the L{telnet.TelnetBootstrapProtocol} should be passed + to each protocol created on a connection. + """ + self.assertFalse(hasattr(self.protocol.protocol, 'factory')) + + self.protocol.factory = proto_helpers.StringTransport + new_transport = telnet.TelnetTransport(TestProtocol) + new_t = proto_helpers.StringTransport() + new_transport.makeConnection(new_t) + self.protocol.makeConnection(new_transport) + self.assertEqual(self.protocol.factory, self.protocol.protocol.factory) + + def test_connectionLost(self): + """ + Just test that the protocol has been deleted, as the call gets passed along. + """ + self.protocol.connectionLost(Exception("It's gone!")) + self.assertEqual(self.protocol.protocol, None) + + def test_dataReceived(self): + bytes = ["I'm some data!", "More data!", "And some more!"] + for b in bytes: + self.protocol.dataReceived(b) + expected = [('bytes', "I'm some data!"), + ('bytes', "More data!"), + ('bytes', "And some more!")] + self.assertEqual(self.protocol.protocol.events, expected) + + def test_enableLocal(self): + self.assertTrue(self.protocol.enableLocal('\x01')) + self.assertTrue(self.protocol.enableLocal('\x03')) + self.assertFalse(self.protocol.enableLocal('\x00')) + + def test_enableRemote(self): + self.assertTrue(self.protocol.enableRemote('\x22')) + self.assertEqual( + self.transport.transport.value(), + '\xff\xfd\x22\xff\xfd\x1f\xff\xfd\x03\xff\xfb\x01\xff\xfa\x22\x01\x02\xff\xf0') + + self.assertTrue(self.protocol.enableRemote('\x1f')) + self.assertTrue(self.protocol.enableRemote('\x03')) + self.assertFalse(self.protocol.enableRemote('\x00')) + + def test_telnet_NAWS(self): + """ + The terminal size can be negotiated, but changing it is not currently + implemented, so just make sure that it stays the same. + """ + p = telnet.TelnetBootstrapProtocol(insults.ServerProtocol, insults.TerminalProtocol) + naws_transport = telnet.TelnetTransport(TestProtocol) + naws_t = proto_helpers.StringTransport() + naws_transport.makeConnection(naws_t) + p.makeConnection(naws_transport) + + expected = insults.Vector(80, 24) + p.telnet_NAWS('1111') + self.assertEqual(p.protocol.termSize.x, expected.x) + self.assertEqual(p.protocol.termSize.y, expected.y) + + # Does the log file need to be tested when provided with the wrong + # number of bytes?