def test_web_agent_error(self): reactor = Mock() cfg = Mock() proto = Mock() directlyProvides(proto, ITorControlProtocol) tor = Tor(reactor, proto, _tor_config=cfg) with self.assertRaises(ValueError) as ctx: agent = tor.web_agent(pool=self.pool, socks_endpoint=object()) yield agent.request('GET', b'meejah.ca') self.assertTrue("'socks_endpoint' should be" in str(ctx.exception))
def test_web_agent_deferred(self): socks_d = defer.succeed("9151") reactor = Mock() cfg = Mock() proto = Mock() directlyProvides(proto, ITorControlProtocol) tor = Tor(reactor, proto, _tor_config=cfg) agent = tor.web_agent(pool=self.pool, socks_endpoint=socks_d) resp = yield agent.request('GET', b'meejah.ca') self.assertEqual(self.expected_response, resp)
def test_web_agent_endpoint(self): socks = Mock() directlyProvides(socks, IStreamClientEndpoint) reactor = Mock() cfg = Mock() proto = Mock() directlyProvides(proto, ITorControlProtocol) tor = Tor(reactor, proto, _tor_config=cfg) agent = tor.web_agent(pool=self.pool, socks_endpoint=socks) resp = yield agent.request('GET', b'meejah.ca') self.assertEqual(self.expected_response, resp)
def test_web_agent_defaults(self): reactor = Mock() # XXX is there a faster way to do this? better reactor fake? fake_host = Mock() fake_host.port = 1234 fake_port = Mock() fake_port.getHost = Mock(return_value=fake_host) reactor.listenTCP = Mock(return_value=fake_port) cfg = Mock() cfg.create_socks_endpoint = Mock(return_value=defer.succeed("9050")) proto = Mock() proto.get_conf = Mock(return_value=defer.succeed({})) directlyProvides(proto, ITorControlProtocol) tor = Tor(reactor, proto, _tor_config=cfg) try: agent = tor.web_agent(pool=self.pool) except ImportError as e: if 'IAgentEndpointFactory' in str(e): print("Skipping; appears we don't have web support") return resp = yield agent.request('GET', b'meejah.ca') self.assertEqual(self.expected_response, resp)