aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShadab Zafar <dufferzafar0@gmail.com>2016-08-14 13:56:14 +0530
committerShadab Zafar <dufferzafar0@gmail.com>2016-08-15 12:00:23 +0530
commitb9426fcec178395bf9c054f616ab6b23c5b2408a (patch)
treeac83fd3b11945eec1e0fc7c83360a953f22eea43
parentbf4425de80dfa5a9b2bef2947e57a79f9655d74f (diff)
downloadmitmproxy-b9426fcec178395bf9c054f616ab6b23c5b2408a.tar.gz
mitmproxy-b9426fcec178395bf9c054f616ab6b23c5b2408a.tar.bz2
mitmproxy-b9426fcec178395bf9c054f616ab6b23c5b2408a.zip
Add a test for base64 encoding
-rw-r--r--test/mitmproxy/test_examples.py23
1 files changed, 18 insertions, 5 deletions
diff --git a/test/mitmproxy/test_examples.py b/test/mitmproxy/test_examples.py
index 402120c0..99e1b34e 100644
--- a/test/mitmproxy/test_examples.py
+++ b/test/mitmproxy/test_examples.py
@@ -105,16 +105,16 @@ class TestScripts(mastertest.MasterTest):
class TestHARDump():
- def setup(self):
+ def flow(self, resp_content=b'message'):
times = dict(
timestamp_start=746203272,
timestamp_end=746203272,
)
# Create a dummy flow for testing
- self.req_get = tutils.tflow(
- req=netutils.treq(method=b'GET', content=b'', **times),
- resp=netutils.tresp(**times)
+ return tutils.tflow(
+ req=netutils.treq(method=b'GET', **times),
+ resp=netutils.tresp(content=resp_content, **times)
)
def test_no_file_arg(self):
@@ -126,7 +126,7 @@ class TestHARDump():
path = os.path.join(tdir, "somefile")
m, sc = tscript("har_dump.py", six.moves.shlex_quote(path))
- m.addons.invoke(m, "response", self.req_get)
+ m.addons.invoke(m, "response", self.flow())
m.addons.remove(sc)
with open(path, "r") as inp:
@@ -134,6 +134,19 @@ class TestHARDump():
assert len(har["log"]["entries"]) == 1
+ def test_base64(self):
+ with tutils.tmpdir() as tdir:
+ path = os.path.join(tdir, "somefile")
+
+ m, sc = tscript("har_dump.py", six.moves.shlex_quote(path))
+ m.addons.invoke(m, "response", self.flow(resp_content=b"foo" + b"\xFF" * 10))
+ m.addons.remove(sc)
+
+ with open(path, "r") as inp:
+ har = json.load(inp)
+
+ assert har["log"]["entries"][0]["response"]["content"]["encoding"] == "base64"
+
def test_format_cookies(self):
m, sc = tscript("har_dump.py", "-")
format_cookies = sc.ns.ns["format_cookies"]