class OtherTests(unittest.TestCase): def setUp(self): self.server = Server() def tearDown(self): UnmockClassMethods(Server) def testCreateReplyPacket(self): class TrivialPacket: source = object() def CreateReply(self, **kw): reply = TrivialObject() reply.kw = kw return reply reply = self.server.CreateReplyPacket(TrivialPacket(), one='one', two='two') self.failUnless(isinstance(reply, TrivialObject)) self.failUnless(reply.source is TrivialPacket.source) self.assertEqual(reply.kw, dict(one='one', two='two')) def testAuthProcessInput(self): fd = MockFd(1) self.server._realauthfds = [1] MockClassMethod(Server, '_GrabPacket') MockClassMethod(Server, '_HandleAuthPacket') self.server._ProcessInput(fd) self.assertEqual([x[0] for x in self.server.called], ['_GrabPacket', '_HandleAuthPacket']) self.assertEqual(self.server.called[0][1][1], fd) def testAcctProcessInput(self): fd = MockFd(1) self.server._realauthfds = [] self.server._realacctfds = [1] MockClassMethod(Server, '_GrabPacket') MockClassMethod(Server, '_HandleAcctPacket') self.server._ProcessInput(fd) self.assertEqual([x[0] for x in self.server.called], ['_GrabPacket', '_HandleAcctPacket']) self.assertEqual(self.server.called[0][1][1], fd)
def _ProcessInput(self, fd): """Process available data. If this packet should be dropped instead of processed a `ServerPacketError` exception should be raised. The main loop will drop the packet and log the reason. This function calls either :obj:`HandleAuthPacket`, :obj:`HandleAcctPacket` or :obj:`_HandleProxyPacket` depending on which socket is being processed. :param fd: socket to read packet from :type fd: socket class instance :param pkt: packet to process :type pkt: Packet class instance """ if fd.fileno() == self._proxyfd.fileno(): pkt = self._GrabPacket( lambda data, s=self: s.CreatePacket(packet=data), fd) self._HandleProxyPacket(pkt) else: Server._ProcessInput(self, fd)