def createTransport(self, skt, peer, data, protocol): """ Create a TCP transport, from a socket object passed by the parent. """ self._connectionCount += 1 transport = Server(skt, protocol, peer, JustEnoughLikeAPort, self._connectionCount, reactor) if data == 'SSL': transport.startTLS(self.contextFactory) transport.startReading() return transport
def setUp(self): self.reactor = _FakeFDSetReactor() class FakePort(object): _realPortNumber = 3 self.skt = FakeSocket("") self.protocol = Protocol() self.server = Server( self.skt, self.protocol, ("", 0), FakePort(), None, self.reactor)
class TCPServerTests(TestCase): """ Whitebox tests for L{twisted.internet.tcp.Server}. """ def setUp(self): self.reactor = _FakeFDSetReactor() class FakePort(object): _realPortNumber = 3 self.skt = FakeSocket("") self.protocol = Protocol() self.server = Server( self.skt, self.protocol, ("", 0), FakePort(), None, self.reactor) def test_writeAfterDisconnect(self): """ L{Server.write} discards bytes passed to it if called after it has lost its connection. """ self.server.connectionLost( Failure(Exception("Simulated lost connection"))) self.server.write("hello world") self.assertEqual(self.skt.sendBuffer, []) def test_writeAfteDisconnectAfterTLS(self): """ L{Server.write} discards bytes passed to it if called after it has lost its connection when the connection had started TLS. """ self.server.TLS = True self.test_writeAfterDisconnect() def test_writeSequenceAfterDisconnect(self): """ L{Server.writeSequence} discards bytes passed to it if called after it has lost its connection. """ self.server.connectionLost( Failure(Exception("Simulated lost connection"))) self.server.writeSequence(["hello world"]) self.assertEqual(self.skt.sendBuffer, []) def test_writeSequenceAfteDisconnectAfterTLS(self): """ L{Server.writeSequence} discards bytes passed to it if called after it has lost its connection when the connection had started TLS. """ self.server.TLS = True self.test_writeSequenceAfterDisconnect()
def createTransport(self, skt, peer, data, protocol): """ Create a TCP transport, from a socket object passed by the parent. """ self._connectionCount += 1 transport = Server(skt, protocol, peer, JustEnoughLikeAPort, self._connectionCount, reactor) if data == 'SSL': if self.usingSocketFile: # Mark the transport as "secure", enough for getHostInfo() to # think so transport.getPeerCertificate = lambda _: None directlyProvides(transport, ISSLTransport) else: transport.startTLS(self.contextFactory) transport.startReading() return transport
def createTransport(self, skt, peer, data, protocol): """ Create a TCP transport, from a socket object passed by the parent. """ self._connectionCount += 1 transport = Server(skt, protocol, peer, JustEnoughLikeAPort, self._connectionCount, reactor) if data == 'SSL': if self.usingSocketFile: # Mark the transport as "secure", enough for getHostInfo() to # think so transport.getPeerCertificate = lambda _ : None directlyProvides(transport, ISSLTransport) else: transport.startTLS(self.contextFactory) transport.startReading() return transport