From b9426fcec178395bf9c054f616ab6b23c5b2408a Mon Sep 17 00:00:00 2001 From: Shadab Zafar Date: Sun, 14 Aug 2016 13:56:14 +0530 Subject: [PATCH] Add a test for base64 encoding --- test/mitmproxy/test_examples.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/test/mitmproxy/test_examples.py b/test/mitmproxy/test_examples.py index 402120c05..99e1b34e7 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"]