示例#1
0
 def setUp(self):
     self.proxy = Proxy()
     self.proxy.hosts['host'] = TrivialObject()
     self.proxy.hosts['host'].secret = 'supersecret'
     self.packet = TrivialObject()
     self.packet.code = AccessAccept
     self.packet.source = ('host', 'port')
示例#2
0
 def setUp(self):
     self.proxy = Proxy()
     self.proxy.hosts["host"] = TrivialObject()
     self.proxy.hosts["host"].secret = "supersecret"
     self.packet = TrivialObject()
     self.packet.code = AccessAccept
     self.packet.source = ("host", "port")
示例#3
0
class SocketTests(unittest.TestCase):
    def setUp(self):
        self.orgsocket = socket.socket
        socket.socket = MockSocket
        self.proxy = Proxy()
        self.proxy._fdmap = {}

    def tearDown(self):
        socket.socket = self.orgsocket

    def testProxyFd(self):
        self.proxy._poll = MockPoll()
        self.proxy._PrepareSockets()
        self.failUnless(isinstance(self.proxy._proxyfd, MockSocket))
        self.assertEqual(list(self.proxy._fdmap.keys()), [1])
        self.assertEqual(self.proxy._poll.registry, [(1, select.POLLIN | select.POLLPRI | select.POLLERR)])
示例#4
0
class SocketTests(unittest.TestCase):
    def setUp(self):
        self.orgsocket = socket.socket
        socket.socket = MockSocket
        self.proxy = Proxy()
        self.proxy._fdmap = {}

    def tearDown(self):
        socket.socket = self.orgsocket

    def testProxyFd(self):
        self.proxy._poll = MockPoll()
        self.proxy._PrepareSockets()
        self.failUnless(isinstance(self.proxy._proxyfd, MockSocket))
        self.assertEqual(list(self.proxy._fdmap.keys()), [1])
        self.assertEqual(self.proxy._poll.registry,
                {1: select.POLLIN | select.POLLPRI | select.POLLERR})
示例#5
0
class OtherTests(unittest.TestCase):
    def setUp(self):
        self.proxy = Proxy()
        self.proxy._proxyfd = MockFd()

    def tearDown(self):
        UnmockClassMethods(Proxy)
        UnmockClassMethods(Server)

    def testProcessInputNonProxyPort(self):
        fd = MockFd(fd=111)
        MockClassMethod(Server, "_ProcessInput")
        self.proxy._ProcessInput(fd)
        self.assertEqual(self.proxy.called, [("_ProcessInput", (fd,), {})])

    def testProcessInput(self):
        MockClassMethod(Proxy, "_GrabPacket")
        MockClassMethod(Proxy, "_HandleProxyPacket")
        self.proxy._ProcessInput(self.proxy._proxyfd)
        self.assertEqual([x[0] for x in self.proxy.called], ["_GrabPacket", "_HandleProxyPacket"])
示例#6
0
class OtherTests(unittest.TestCase):
    def setUp(self):
        self.proxy = Proxy()
        self.proxy._proxyfd = MockFd()

    def tearDown(self):
        UnmockClassMethods(Proxy)
        UnmockClassMethods(Server)

    def testProcessInputNonProxyPort(self):
        fd = MockFd(fd=111)
        MockClassMethod(Server, '_ProcessInput')
        self.proxy._ProcessInput(fd)
        self.assertEqual(self.proxy.called, [('_ProcessInput', (fd, ), {})])

    def testProcessInput(self):
        MockClassMethod(Proxy, '_GrabPacket')
        MockClassMethod(Proxy, '_HandleProxyPacket')
        self.proxy._ProcessInput(self.proxy._proxyfd)
        self.assertEqual([x[0] for x in self.proxy.called],
                         ['_GrabPacket', '_HandleProxyPacket'])
示例#7
0
class ProxyPacketHandlingTests(unittest.TestCase):
    def setUp(self):
        self.proxy = Proxy()
        self.proxy.hosts["host"] = TrivialObject()
        self.proxy.hosts["host"].secret = "supersecret"
        self.packet = TrivialObject()
        self.packet.code = AccessAccept
        self.packet.source = ("host", "port")

    def testHandleProxyPacketUnknownHost(self):
        self.packet.source = ("stranger", "port")
        try:
            self.proxy._HandleProxyPacket(self.packet)
        except ServerPacketError as e:
            self.failUnless("unknown host" in str(e))
        else:
            self.fail()

    def testHandleProxyPacketSetsSecret(self):
        self.proxy._HandleProxyPacket(self.packet)
        self.assertEqual(self.packet.secret, "supersecret")

    def testHandleProxyPacketHandlesWrongPacket(self):
        self.packet.code = AccessRequest
        try:
            self.proxy._HandleProxyPacket(self.packet)
        except ServerPacketError as e:
            self.failUnless("non-response" in str(e))
        else:
            self.fail()
示例#8
0
class ProxyPacketHandlingTests(unittest.TestCase):
    def setUp(self):
        self.proxy = Proxy()
        self.proxy.hosts['host'] = TrivialObject()
        self.proxy.hosts['host'].secret = 'supersecret'
        self.packet = TrivialObject()
        self.packet.code = AccessAccept
        self.packet.source = ('host', 'port')

    def testHandleProxyPacketUnknownHost(self):
        self.packet.source = ('stranger', 'port')
        try:
            self.proxy._HandleProxyPacket(self.packet)
        except ServerPacketError as e:
            self.failUnless('unknown host' in str(e))
        else:
            self.fail()

    def testHandleProxyPacketSetsSecret(self):
        self.proxy._HandleProxyPacket(self.packet)
        self.assertEqual(self.packet.secret, 'supersecret')

    def testHandleProxyPacketHandlesWrongPacket(self):
        self.packet.code = AccessRequest
        try:
            self.proxy._HandleProxyPacket(self.packet)
        except ServerPacketError as e:
            self.failUnless('non-response' in str(e))
        else:
            self.fail()
示例#9
0
 def setUp(self):
     self.proxy = Proxy()
     self.proxy._proxyfd = MockFd()
示例#10
0
 def setUp(self):
     self.orgsocket = socket.socket
     socket.socket = MockSocket
     self.proxy = Proxy()
     self.proxy._fdmap = {}
示例#11
0
 def setUp(self):
     self.proxy = Proxy()
     self.proxy._proxyfd = MockFd()
示例#12
0
 def setUp(self):
     self.orgsocket = socket.socket
     socket.socket = MockSocket
     self.proxy = Proxy()
     self.proxy._fdmap = {}