Esempio n. 1
0
    def test_dns_resolve_existing_socks(self, fake_socks):
        answer = object()
        proto = Mock()
        proto.get_conf = Mock(
            return_value=defer.succeed({"SocksPort": "9050"}))
        tor = Tor(Mock(), proto)
        fake_socks.resolve = Mock(return_value=defer.succeed(answer))
        ans0 = yield tor.dns_resolve("meejah.ca")

        # do it again to exercise the _default_socks_port() case when
        # we already got the default
        fake_socks.resolve = Mock(return_value=defer.succeed(answer))
        ans1 = yield tor.dns_resolve("meejah.ca")
        self.assertEqual(ans0, answer)
        self.assertEqual(ans1, answer)
Esempio n. 2
0
 def test_dns_resolve(self, fake_socks):
     answer = object()
     cfg = Mock()
     proto = Mock()
     proto.get_conf = Mock(
         return_value=defer.succeed({"SocksPort": "9050"}))
     tor = Tor(Mock(), proto, _tor_config=cfg)
     fake_socks.resolve = Mock(return_value=defer.succeed(answer))
     ans = yield tor.dns_resolve("meejah.ca")
     self.assertEqual(ans, answer)
Esempio n. 3
0
    def test_dns_resolve_no_configured_socks(self, fake_socks):
        answer = object()
        proto = Mock()
        proto.get_conf = Mock(
            return_value=defer.succeed({"SocksPort": "9050"}))
        cfg = Mock()
        tor = Tor(Mock(), proto, _tor_config=cfg)

        def boom(*args, **kw):
            raise RuntimeError("no socks")

        cfg.socks_endpoint = Mock(side_effect=boom)
        fake_socks.resolve = Mock(return_value=defer.succeed(answer))
        ans = yield tor.dns_resolve("meejah.ca")

        self.assertEqual(ans, answer)