aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMichael McKeirnan <github@mckeimic.com>2019-11-16 01:20:50 -0800
committerMichael McKeirnan <github@mckeimic.com>2019-11-16 01:20:50 -0800
commita6e8b930c9aac350cd1701e5e7fe4e7ca7e1ba3c (patch)
tree7fa25e0c8f454a3a489623f915fa4a962d195482 /test
parentdae01ad62329c74fa9373d2052c6bf7f879fa523 (diff)
downloadmitmproxy-a6e8b930c9aac350cd1701e5e7fe4e7ca7e1ba3c.tar.gz
mitmproxy-a6e8b930c9aac350cd1701e5e7fe4e7ca7e1ba3c.tar.bz2
mitmproxy-a6e8b930c9aac350cd1701e5e7fe4e7ca7e1ba3c.zip
Adding raw_request and raw_response to export
This is a proposed change for https://github.com/mitmproxy/mitmproxy/issues/3701 which alters the behavior of a raw http export to include both the request and the response. Additionally, this introduces two new export options "raw_request" and "raw_response" which allow for exporting the raw HTTP request or response individually.
Diffstat (limited to 'test')
-rw-r--r--test/mitmproxy/addons/test_export.py42
1 files changed, 41 insertions, 1 deletions
diff --git a/test/mitmproxy/addons/test_export.py b/test/mitmproxy/addons/test_export.py
index 1ea4f256..b0fbeb45 100644
--- a/test/mitmproxy/addons/test_export.py
+++ b/test/mitmproxy/addons/test_export.py
@@ -24,6 +24,13 @@ def get_response():
@pytest.fixture
+def get_flow():
+ return tflow.tflow(
+ req=tutils.treq(method=b'GET', content=b'', path=b"/path?a=foo&a=bar&b=baz"),
+ resp=tutils.tresp(status_code=404, content=b"Test Response Body"))
+
+
+@pytest.fixture
def post_request():
return tflow.tflow(
req=tutils.treq(method=b'POST', headers=(), content=bytes(range(256))))
@@ -85,18 +92,51 @@ class TestExportHttpieCommand:
export.httpie_command(tcp_flow)
+class TestRaw:
+ def test_req_and_resp_present(self, get_flow):
+ assert b"header: qvalue" in export.raw(get_flow)
+ assert b"header-response: svalue" in export.raw(get_flow)
+
+ def test_get_request_present(self, get_request):
+ assert b"header: qvalue" in export.raw(get_request)
+
+ def test_get_response_present(self, get_response):
+ delattr(get_response, 'request')
+ assert b"header-response: svalue" in export.raw(get_response)
+
+ def test_missing_both(self, get_request):
+ delattr(get_request, 'request')
+ delattr(get_request, 'response')
+ with pytest.raises(exceptions.CommandError):
+ export.raw(get_request)
+
+ def test_tcp(self, tcp_flow):
+ with pytest.raises(exceptions.CommandError):
+ export.raw_request(tcp_flow)
+
+
class TestRawRequest:
def test_get(self, get_request):
assert b"header: qvalue" in export.raw_request(get_request)
+ def test_no_request(self, get_response):
+ delattr(get_response, 'request')
+ with pytest.raises(exceptions.CommandError):
+ export.raw_request(get_response)
+
def test_tcp(self, tcp_flow):
with pytest.raises(exceptions.CommandError):
export.raw_request(tcp_flow)
+
class TestRawResponse:
def test_get(self, get_response):
assert b"header-response: svalue" in export.raw_response(get_response)
+ def test_no_response(self, get_request):
+ with pytest.raises(exceptions.CommandError):
+ export.raw_response(get_request)
+
def test_tcp(self, tcp_flow):
with pytest.raises(exceptions.CommandError):
export.raw_response(tcp_flow)
@@ -111,7 +151,7 @@ def test_export(tmpdir):
f = str(tmpdir.join("path"))
e = export.Export()
with taddons.context():
- assert e.formats() == ["curl", "httpie", "raw_request", "raw_response"]
+ assert e.formats() == ["curl", "httpie", "raw", "raw_request", "raw_response"]
with pytest.raises(exceptions.CommandError):
e.file("nonexistent", tflow.tflow(resp=True), f)