diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/mitmproxy/mastertest.py | 5 | ||||
-rw-r--r-- | test/mitmproxy/test_cmdline.py | 12 | ||||
-rw-r--r-- | test/mitmproxy/test_contentview.py | 70 | ||||
-rw-r--r-- | test/mitmproxy/test_custom_contentview.py | 2 |
4 files changed, 45 insertions, 44 deletions
diff --git a/test/mitmproxy/mastertest.py b/test/mitmproxy/mastertest.py index 4d04f337..9e726a32 100644 --- a/test/mitmproxy/mastertest.py +++ b/test/mitmproxy/mastertest.py @@ -1,7 +1,8 @@ -import tutils -import netlib.tutils import mock +from . import tutils +import netlib.tutils + from mitmproxy import flow, proxy, models diff --git a/test/mitmproxy/test_cmdline.py b/test/mitmproxy/test_cmdline.py index e75b7baf..4fe2cf94 100644 --- a/test/mitmproxy/test_cmdline.py +++ b/test/mitmproxy/test_cmdline.py @@ -39,11 +39,11 @@ def test_parse_replace_hook(): def test_parse_server_spec(): tutils.raises("Invalid server specification", cmdline.parse_server_spec, "") assert cmdline.parse_server_spec( - "http://foo.com:88") == ("http", ("foo.com", 88)) + "http://foo.com:88") == (b"http", (b"foo.com", 88)) assert cmdline.parse_server_spec( - "http://foo.com") == ("http", ("foo.com", 80)) + "http://foo.com") == (b"http", (b"foo.com", 80)) assert cmdline.parse_server_spec( - "https://foo.com") == ("https", ("foo.com", 443)) + "https://foo.com") == (b"https", (b"foo.com", 443)) tutils.raises( "Invalid server specification", cmdline.parse_server_spec, @@ -59,9 +59,9 @@ def test_parse_upstream_auth(): tutils.raises("Invalid upstream auth specification", cmdline.parse_upstream_auth, ":") tutils.raises("Invalid upstream auth specification", cmdline.parse_upstream_auth, ":test") assert cmdline.parse_upstream_auth( - "test:test") == "Basic" + " " + base64.b64encode("test:test") + "test:test") == b"Basic" + b" " + base64.b64encode(b"test:test") assert cmdline.parse_upstream_auth( - "test:") == "Basic" + " " + base64.b64encode("test:") + "test:") == b"Basic" + b" " + base64.b64encode(b"test:") def test_parse_setheaders(): @@ -124,7 +124,7 @@ def test_common(): opts.replace_file = [("/foo/bar/%s" % p)] v = cmdline.get_common_options(opts)["replacements"] assert len(v) == 1 - assert v[0][2].strip() == "replacecontents" + assert v[0][2].strip() == b"replacecontents" def test_mitmproxy(): diff --git a/test/mitmproxy/test_contentview.py b/test/mitmproxy/test_contentview.py index 667a36fe..52fceeac 100644 --- a/test/mitmproxy/test_contentview.py +++ b/test/mitmproxy/test_contentview.py @@ -23,37 +23,37 @@ class TestContentView: def test_view_auto(self): v = cv.ViewAuto() f = v( - "foo", + b"foo", headers=Headers() ) assert f[0] == "Raw" f = v( - "<html></html>", + b"<html></html>", headers=Headers(content_type="text/html") ) assert f[0] == "HTML" f = v( - "foo", + b"foo", headers=Headers(content_type="text/flibble") ) assert f[0] == "Raw" f = v( - "<xml></xml>", + b"<xml></xml>", headers=Headers(content_type="text/flibble") ) assert f[0].startswith("XML") f = v( - "", + b"", headers=Headers() ) assert f[0] == "No content" f = v( - "", + b"", headers=Headers(), query=multidict.MultiDict([("foo", "bar")]), ) @@ -69,29 +69,29 @@ class TestContentView: def test_view_html(self): v = cv.ViewHTML() - s = "<html><br><br></br><p>one</p></html>" + s = b"<html><br><br></br><p>one</p></html>" assert v(s) - s = "gobbledygook" + s = b"gobbledygook" assert not v(s) def test_view_html_outline(self): v = cv.ViewHTMLOutline() - s = "<html><br><br></br><p>one</p></html>" + s = b"<html><br><br></br><p>one</p></html>" assert v(s) def test_view_json(self): cv.VIEW_CUTOFF = 100 v = cv.ViewJSON() - assert v("{}") - assert not v("{") - assert v("[1, 2, 3, 4, 5]") + assert v(b"{}") + assert not v(b"{") + assert v(b"[1, 2, 3, 4, 5]") def test_view_xml(self): v = cv.ViewXML() - assert v("<foo></foo>") - assert not v("<foo>") - s = """<?xml version="1.0" encoding="UTF-8"?> + assert v(b"<foo></foo>") + assert not v(b"<foo>") + s = b"""<?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet title="XSL_formatting"?> <rss xmlns:media="http://search.yahoo.com/mrss/" @@ -103,7 +103,7 @@ class TestContentView: def test_view_raw(self): v = cv.ViewRaw() - assert v("foo") + assert v(b"foo") def test_view_javascript(self): v = cv.ViewJavaScript() @@ -133,27 +133,27 @@ class TestContentView: def test_view_hex(self): v = cv.ViewHex() - assert v("foo") + assert v(b"foo") def test_view_image(self): v = cv.ViewImage() p = tutils.test_data.path("data/image.png") - assert v(file(p, "rb").read()) + assert v(open(p, "rb").read()) p = tutils.test_data.path("data/image.gif") - assert v(file(p, "rb").read()) + assert v(open(p, "rb").read()) p = tutils.test_data.path("data/image-err1.jpg") - assert v(file(p, "rb").read()) + assert v(open(p, "rb").read()) p = tutils.test_data.path("data/image.ico") - assert v(file(p, "rb").read()) + assert v(open(p, "rb").read()) - assert not v("flibble") + assert not v(b"flibble") def test_view_multipart(self): view = cv.ViewMultipart() - v = """ + v = b""" --AaB03x Content-Disposition: form-data; name="submit-name" @@ -182,21 +182,21 @@ Larry def test_get_content_view(self): r = cv.get_content_view( cv.get("Raw"), - "[1, 2, 3]", + b"[1, 2, 3]", headers=Headers(content_type="application/json") ) assert "Raw" in r[0] r = cv.get_content_view( cv.get("Auto"), - "[1, 2, 3]", + b"[1, 2, 3]", headers=Headers(content_type="application/json") ) assert r[0] == "JSON" r = cv.get_content_view( cv.get("Auto"), - "[1, 2", + b"[1, 2", headers=Headers(content_type="application/json") ) assert "Raw" in r[0] @@ -205,13 +205,13 @@ Larry ContentViewException, cv.get_content_view, cv.get("AMF"), - "[1, 2", + b"[1, 2", headers=Headers() ) r = cv.get_content_view( cv.get("Auto"), - encoding.encode('gzip', "[1, 2, 3]"), + encoding.encode('gzip', b"[1, 2, 3]"), headers=Headers( content_type="application/json", content_encoding="gzip" @@ -222,7 +222,7 @@ Larry r = cv.get_content_view( cv.get("XML"), - encoding.encode('gzip', "[1, 2, 3]"), + encoding.encode('gzip', b"[1, 2, 3]"), headers=Headers( content_type="application/json", content_encoding="gzip" @@ -252,22 +252,22 @@ if pyamf: v = cv.ViewAMF() p = tutils.test_data.path("data/amf01") - assert v(file(p, "rb").read()) + assert v(open(p, "rb").read()) p = tutils.test_data.path("data/amf02") - assert v(file(p, "rb").read()) + assert v(open(p, "rb").read()) def test_view_amf_response(): v = cv.ViewAMF() p = tutils.test_data.path("data/amf03") - assert v(file(p, "rb").read()) + assert v(open(p, "rb").read()) if cv.ViewProtobuf.is_available(): def test_view_protobuf_request(): v = cv.ViewProtobuf() p = tutils.test_data.path("data/protobuf01") - content_type, output = v(file(p, "rb").read()) + content_type, output = v(open(p, "rb").read()) assert content_type == "Protobuf" assert output.next()[0][1] == '1: "3bbc333c-e61c-433b-819a-0b9a8cc103b8"' @@ -277,7 +277,7 @@ def test_get_by_shortcut(): def test_pretty_json(): - assert cv.pretty_json('{"foo": 1}') - assert not cv.pretty_json("moo") + assert cv.pretty_json(b'{"foo": 1}') + assert not cv.pretty_json(b"moo") assert cv.pretty_json(b'{"foo" : "\xe4\xb8\x96\xe7\x95\x8c"}') # utf8 with chinese characters assert not cv.pretty_json(b'{"foo" : "\xFF"}') diff --git a/test/mitmproxy/test_custom_contentview.py b/test/mitmproxy/test_custom_contentview.py index 479b0b43..889fb8b3 100644 --- a/test/mitmproxy/test_custom_contentview.py +++ b/test/mitmproxy/test_custom_contentview.py @@ -40,7 +40,7 @@ def test_custom_views(): cv.remove(view_obj) r = cv.get_content_view( cv.get("Auto"), - "[1, 2, 3]", + b"[1, 2, 3]", headers=Headers( content_type="text/none" ) |