aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@corte.si>2017-04-30 11:48:32 +1200
committerAldo Cortesi <aldo@corte.si>2017-04-30 11:48:32 +1200
commit7ffb2c7981b76ed2e8c467d3db3141b013cccd5b (patch)
treee496b647b9f1cc5d2fb9e101be8b1908299194a6 /test
parent4b568f99d6a56e4331af5aac00bcf7d4642a115d (diff)
downloadmitmproxy-7ffb2c7981b76ed2e8c467d3db3141b013cccd5b.tar.gz
mitmproxy-7ffb2c7981b76ed2e8c467d3db3141b013cccd5b.tar.bz2
mitmproxy-7ffb2c7981b76ed2e8c467d3db3141b013cccd5b.zip
cut: use csv module to encode multi-values for saving
Also add q.text, q.raw_content, s.text, s.raw_content selectors
Diffstat (limited to 'test')
-rw-r--r--test/mitmproxy/addons/test_cut.py33
1 files changed, 30 insertions, 3 deletions
diff --git a/test/mitmproxy/addons/test_cut.py b/test/mitmproxy/addons/test_cut.py
index 5eb864c0..3012803d 100644
--- a/test/mitmproxy/addons/test_cut.py
+++ b/test/mitmproxy/addons/test_cut.py
@@ -7,6 +7,33 @@ from mitmproxy.test import tflow
import pytest
+def test_extract():
+ tf = tflow.tflow(resp=True)
+ tests = [
+ ["q.method", "GET"],
+ ["q.scheme", "http"],
+ ["q.host", "address"],
+ ["q.port", "22"],
+ ["q.path", "/path"],
+ ["q.url", "http://address:22/path"],
+ ["q.text", "content"],
+ ["q.content", b"content"],
+ ["q.raw_content", b"content"],
+ ["q.header[header]", "qvalue"],
+
+ ["s.status_code", "200"],
+ ["s.reason", "OK"],
+ ["s.text", "message"],
+ ["s.content", b"message"],
+ ["s.raw_content", b"message"],
+ ["s.header[header-response]", "svalue"],
+ ]
+ for t in tests:
+ ret = cut.extract(t[0], tf)
+ if ret != t[1]:
+ raise AssertionError("Expected %s, got %s", t[1], ret)
+
+
def test_parse_cutspec():
tests = [
("", None, True),
@@ -71,9 +98,9 @@ def test_cut_file(tmpdir):
v.add([tflow.tflow(resp=True)])
tctx.command(c.save, "q.method|@all", f)
- assert qr(f) == b"GET\nGET"
- tctx.command(c.save, "q.method,q.path|@all", f)
- assert qr(f) == b"GET, /path\nGET, /path"
+ assert qr(f).splitlines() == [b"GET", b"GET"]
+ tctx.command(c.save, "q.method,q.content|@all", f)
+ assert qr(f).splitlines() == [b"GET,content", b"GET,content"]
def test_cut():