Пример #1
0
    def test_socks_agent_tcp_host_port(self):
        reactor = Mock()
        config = Mock()
        config.SocksPort = []
        proto = Mock()
        gold = object()
        proto.request = Mock(return_value=defer.succeed(gold))

        def getConnection(key, endpoint):
            self.assertTrue(isinstance(endpoint, TorSocksEndpoint))
            self.assertTrue(endpoint._tls)
            self.assertEqual(endpoint._host, u'meejah.ca')
            self.assertEqual(endpoint._port, 443)
            return defer.succeed(proto)

        pool = Mock()
        pool.getConnection = getConnection

        # do the test
        agent = yield agent_for_socks_port(reactor,
                                           config,
                                           '127.0.0.50:1234',
                                           pool=pool)

        # apart from the getConnection asserts...
        res = yield agent.request(b'GET', b'https://meejah.ca')
        self.assertIs(res, gold)
Пример #2
0
    def test_socks_agent_error_saving(self):
        reactor = Mock()
        config = Mock()
        config.SocksPort = []

        def boom(*args, **kw):
            raise RuntimeError("sad times at ridgemont high")
        config.save = boom
        try:
            yield agent_for_socks_port(reactor, config, '1234')
            self.fail("Should get an error")
        except RuntimeError as e:
            self.assertTrue("sad times at ridgemont high" in str(e))
Пример #3
0
    def test_socks_agent_error_saving(self):
        reactor = Mock()
        config = Mock()
        config.SocksPort = []

        def boom(*args, **kw):
            raise RuntimeError("sad times at ridgemont high")

        config.save = boom
        try:
            yield agent_for_socks_port(reactor, config, '1234')
            self.fail("Should get an error")
        except RuntimeError as e:
            self.assertTrue("sad times at ridgemont high" in str(e))
Пример #4
0
    def test_socks_agent_tcp_host_port(self):
        reactor = Mock()
        config = Mock()
        config.SocksPort = []
        proto = Mock()
        gold = object()
        proto.request = Mock(return_value=defer.succeed(gold))

        def getConnection(key, endpoint):
            self.assertTrue(isinstance(endpoint, TorSocksEndpoint))
            self.assertTrue(endpoint._tls)
            self.assertEqual(endpoint._host, u'meejah.ca')
            self.assertEqual(endpoint._port, 443)
            return defer.succeed(proto)
        pool = Mock()
        pool.getConnection = getConnection

        # do the test
        agent = yield agent_for_socks_port(reactor, config, '127.0.0.50:1234', pool=pool)

        # apart from the getConnection asserts...
        res = yield agent.request(b'GET', b'https://meejah.ca')
        self.assertIs(res, gold)
Пример #5
0
 def test_socks_agent_unix(self):
     reactor = Mock()
     config = Mock()
     config.SocksPort = []
     agent_for_socks_port(reactor, config, 'unix:/foo')
Пример #6
0
 def test_socks_agent_tcp_port(self):
     reactor = Mock()
     config = Mock()
     config.SocksPort = ['1234']
     agent_for_socks_port(reactor, config, '1234')
Пример #7
0
 def test_socks_agent_unix(self):
     reactor = Mock()
     config = Mock()
     config.SocksPort = []
     agent_for_socks_port(reactor, config, 'unix:/foo')
Пример #8
0
 def test_socks_agent_tcp_port(self):
     reactor = Mock()
     config = Mock()
     config.SocksPort = ['1234']
     agent_for_socks_port(reactor, config, '1234')