示例#1
0
    def testPrepareSocketAcctFds(self):
        self.server._poll = MockPoll()
        self.server._fdmap = {}
        self.server.acctfds = [MockFd(12), MockFd(14)]
        self.server._PrepareSockets()

        self.assertEqual(list(self.server._fdmap.keys()), [12, 14])
        self.assertEqual(self.server._poll.registry,
                [(12, select.POLLIN | select.POLLPRI | select.POLLERR),
                 (14, select.POLLIN | select.POLLPRI | select.POLLERR)])
示例#2
0
    def testPrepareSocketAuthFds(self):
        self.server._poll = MockPoll()
        self.server._fdmap = {}
        self.server.authfds = [MockFd(12), MockFd(14)]
        self.server._PrepareSockets()

        self.assertEqual(list(self.server._fdmap.keys()), [12, 14])
        self.assertEqual(
            self.server._poll.registry, {
                12: select.POLLIN | select.POLLPRI | select.POLLERR,
                14: select.POLLIN | select.POLLPRI | select.POLLERR
            })
示例#3
0
    def testGrabPacket(self):
        def gen(data):
            res = TrivialObject()
            res.data = data
            return res

        fd = MockFd()
        fd.source = object()
        pkt = self.server._GrabPacket(gen, fd)
        self.failUnless(isinstance(pkt, TrivialObject))
        self.failUnless(pkt.fd is fd)
        self.failUnless(pkt.source is fd.source)
        self.failUnless(pkt.data is fd.data)
示例#4
0
 def testRunIgnoresPacketErrors(self):
     def RaisePacketError(self, fd):
         raise PacketError
     MockClassMethod(Server, '_ProcessInput', RaisePacketError)
     self.server.authfds = [MockFd()]
     MockPoll.results = [(0, select.POLLIN)]
     self.assertRaises(MockFinished, self.server.Run)
示例#5
0
 def testRunRunsProcessInput(self):
     MockClassMethod(Server, '_ProcessInput')
     self.server.authfds = fd = [MockFd()]
     MockPoll.results = [(0, select.POLLIN)]
     self.assertRaises(MockFinished, self.server.Run)
     self.assertEqual(self.server.called,
                      [('_ProcessInput', (fd[0], ), {})])
示例#6
0
    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)
示例#7
0
 def testRunIgnoresPollErrors(self):
     self.server.authfds = [MockFd()]
     MockPoll.results = [(0, select.POLLERR)]
     self.assertRaises(MockFinished, self.server.Run)
示例#8
0
 def testProcessInputNonProxyPort(self):
     fd = MockFd(fd=111)
     MockClassMethod(Server, '_ProcessInput')
     self.proxy._ProcessInput(fd)
     self.assertEqual(self.proxy.called,
             [('_ProcessInput', (fd,), {})])
示例#9
0
 def setUp(self):
     self.proxy = Proxy()
     self.proxy._proxyfd = MockFd()