feat: embedded mitmproxy capture addon and proxy server

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-01 00:04:58 +08:00
parent c6d349c505
commit 20c7e0275f
2 changed files with 134 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
from types import SimpleNamespace
from auto_reverse.proxy import flow_from_mitm
def _fake_mitm_flow():
request = SimpleNamespace(
method="POST", pretty_host="ex.com", path="/api/users?role=admin",
headers={"content-type": "application/json"}, content=b'{"name": "Ada"}',
query=SimpleNamespace(fields=[("role", "admin")]),
)
response = SimpleNamespace(
status_code=201, headers={"content-type": "application/json"},
content=b'{"id": 1}',
)
return SimpleNamespace(request=request, response=response, timestamp_start=1.5)
def test_flow_from_mitm_maps_fields():
captured = flow_from_mitm(_fake_mitm_flow())
assert captured.method == "POST"
assert captured.host == "ex.com"
assert captured.path == "/api/users"
assert captured.query == {"role": ["admin"]}
assert captured.status == 201
assert captured.request_json() == {"name": "Ada"}
assert captured.response_json() == {"id": 1}
def test_flow_from_mitm_handles_missing_response():
flow = _fake_mitm_flow()
flow.response = None
captured = flow_from_mitm(flow)
assert captured is None