20c7e0275f
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
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
|