Beispiel #1
0
class TestControlProtocolUsage(unittest.TestCase):

    def setUp(self):
        self.cp = ControlProtocol()
        self.cp.transport = DummyTransport()

    def test_trivial(self):
        pass

    def test_bad_data(self):
        l = [
            """{"hurp": "derp"}""",
        ]
        for line in l:
            self.cp.lineReceived(line)
            self.assertTrue(self.cp.transport.buf.startswith("FAILED"),
                "%s didn't cause an error" % line)
            self.cp.transport.buf = ""

    def test_privileged_port(self):
        self.cp.factory = DummyControlFactory()

        self.cp.lineReceived("""{
            "sport": 1,
            "dport": 11048,
            "daddr": "localhost",
            "password": "******"
        }""")
        self.assertTrue(self.cp.transport.buf.startswith("FAILED"))

    def test_forwarding(self):
        # Set up our test. We want to make sure that no actual ports are
        # opened, so let's patch out listenTCP().
        self.patch(reactor, "listenTCP",
            lambda port, factory, **kwargs: Deferred())
        self.cp.factory = DummyControlFactory()

        self.cp.lineReceived("""{
            "sport": 55555,
            "dport": 11048,
            "daddr": "localhost",
            "password": "******"
        }""")
        self.assertTrue(self.cp.transport.buf.startswith("55555"))

        # Clean up one single delayed call: The timeout.
        delayed = reactor.getDelayedCalls()
        self.assertEqual(len(delayed), 1)
        delayed[0].cancel()
Beispiel #2
0
class TestControlProtocolUsage(unittest.TestCase):
    def setUp(self):
        self.cp = ControlProtocol()
        self.cp.transport = DummyTransport()

    def test_trivial(self):
        pass

    def test_bad_data(self):
        l = [
            """{"hurp": "derp"}""",
        ]
        for line in l:
            self.cp.lineReceived(line)
            self.assertTrue(self.cp.transport.buf.startswith("FAILED"),
                            "%s didn't cause an error" % line)
            self.cp.transport.buf = ""

    def test_privileged_port(self):
        self.cp.factory = DummyControlFactory()

        self.cp.lineReceived("""{
            "sport": 1,
            "dport": 11048,
            "daddr": "localhost",
            "password": "******"
        }""")
        self.assertTrue(self.cp.transport.buf.startswith("FAILED"))

    def test_forwarding(self):
        # Set up our test. We want to make sure that no actual ports are
        # opened, so let's patch out listenTCP().
        self.patch(reactor, "listenTCP",
                   lambda port, factory, **kwargs: Deferred())
        self.cp.factory = DummyControlFactory()

        self.cp.lineReceived("""{
            "sport": 55555,
            "dport": 11048,
            "daddr": "localhost",
            "password": "******"
        }""")
        self.assertTrue(self.cp.transport.buf.startswith("55555"))

        # Clean up one single delayed call: The timeout.
        delayed = reactor.getDelayedCalls()
        self.assertEqual(len(delayed), 1)
        delayed[0].cancel()
Beispiel #3
0
 def setUp(self):
     self.cp = ControlProtocol()
     self.cp.transport = DummyTransport()
Beispiel #4
0
 def setUp(self):
     self.cp = ControlProtocol()
     self.cp.transport = DummyTransport()
Beispiel #5
0
 def setUp(self):
     self.cp = ControlProtocol()