Add distinct tests for CapsClient and ProxyCapsClient
This commit is contained in:
@@ -1,17 +1,16 @@
|
||||
import unittest
|
||||
|
||||
import aiohttp
|
||||
import aioresponses
|
||||
from yarl import URL
|
||||
|
||||
from hippolyzer.lib.proxy.region import ProxiedRegion
|
||||
|
||||
from . import BaseProxyTest
|
||||
from hippolyzer.lib.base.network.caps_client import CapsClient
|
||||
|
||||
|
||||
class TestCapsClient(BaseProxyTest):
|
||||
class TestCapsClient(unittest.IsolatedAsyncioTestCase):
|
||||
def setUp(self) -> None:
|
||||
super().setUp()
|
||||
self.region = ProxiedRegion(("127.0.0.1", 1), "", self.session)
|
||||
self.caps_client = self.region.caps_client
|
||||
self.caps = {}
|
||||
self.caps_client = CapsClient(self.caps)
|
||||
|
||||
async def test_bare_url_works(self):
|
||||
with aioresponses.aioresponses() as m:
|
||||
@@ -33,7 +32,7 @@ class TestCapsClient(BaseProxyTest):
|
||||
self.assertEqual(await resp.read_llsd(), 2)
|
||||
|
||||
async def test_caps(self):
|
||||
self.region.update_caps({"Foobar": "https://example.com/"})
|
||||
self.caps.update({"Foobar": "https://example.com/"})
|
||||
with aioresponses.aioresponses() as m:
|
||||
m.post("https://example.com/baz", body=b"ok")
|
||||
data = {"hi": "hello"}
|
||||
@@ -2,8 +2,10 @@ from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
|
||||
import aioresponses
|
||||
from mitmproxy.test import tflow, tutils
|
||||
from mitmproxy.http import HTTPFlow
|
||||
from yarl import URL
|
||||
|
||||
from hippolyzer.lib.proxy.addon_utils import BaseAddon
|
||||
from hippolyzer.lib.proxy.addons import AddonManager
|
||||
@@ -70,3 +72,21 @@ class LLUDPIntegrationTests(BaseProxyTest):
|
||||
mitm_flow: HTTPFlow = HTTPFlow.from_state(flow_state)
|
||||
# The response sent back to mitmproxy should have been our modified version
|
||||
self.assertEqual(True, mitm_flow.metadata["touched_addon"])
|
||||
|
||||
|
||||
class TestCapsClient(BaseProxyTest):
|
||||
def setUp(self) -> None:
|
||||
super().setUp()
|
||||
self._setup_default_circuit()
|
||||
self.caps = {}
|
||||
self.caps_client = self.session.main_region.caps_client
|
||||
|
||||
async def test_requests_proxied_by_default(self):
|
||||
with aioresponses.aioresponses() as m:
|
||||
m.get("http://example.com/", body=b"foo")
|
||||
async with self.caps_client.get("http://example.com/") as resp:
|
||||
self.assertEqual(await resp.read(), b"foo")
|
||||
kwargs = m.requests[("GET", URL("http://example.com/"))][0].kwargs
|
||||
# Request should have been proxied, with a header marking it
|
||||
self.assertEqual(kwargs['headers']["X-Hippo-Injected"], "1")
|
||||
self.assertEqual(kwargs['proxy'], "http://127.0.0.1:9062")
|
||||
|
||||
Reference in New Issue
Block a user