diff --git a/mitmproxy/cmdline.py b/mitmproxy/cmdline.py index 77cdb8caa..d46051a23 100644 --- a/mitmproxy/cmdline.py +++ b/mitmproxy/cmdline.py @@ -9,6 +9,7 @@ import configargparse from mitmproxy import filt from mitmproxy.proxy import config from netlib import human +from netlib import strutils from netlib import tcp from netlib import version from netlib.http import url @@ -73,7 +74,7 @@ def parse_replace_hook(s): try: re.compile(regex) except re.error as e: - raise ParseException("Malformed replacement regex: %s" % str(e.message)) + raise ParseException("Malformed replacement regex: %s" % str(e)) return patt, regex, replacement @@ -109,7 +110,7 @@ def parse_setheader(s): def parse_server_spec(spec): try: p = url.parse(spec) - if p[0] not in ("http", "https"): + if p[0] not in (b"http", b"https"): raise ValueError() except ValueError: raise configargparse.ArgumentTypeError( @@ -127,7 +128,7 @@ def parse_upstream_auth(auth): raise configargparse.ArgumentTypeError( "Invalid upstream auth specification: %s" % auth ) - return "Basic" + " " + base64.b64encode(auth) + return b"Basic" + b" " + base64.b64encode(strutils.always_bytes(auth)) def get_common_options(options): @@ -147,13 +148,13 @@ def get_common_options(options): try: p = parse_replace_hook(i) except ParseException as e: - raise configargparse.ArgumentTypeError(e.message) + raise configargparse.ArgumentTypeError(e) reps.append(p) for i in options.replace_file: try: patt, rex, path = parse_replace_hook(i) except ParseException as e: - raise configargparse.ArgumentTypeError(e.message) + raise configargparse.ArgumentTypeError(e) try: v = open(path, "rb").read() except IOError as e: @@ -167,7 +168,7 @@ def get_common_options(options): try: p = parse_setheader(i) except ParseException as e: - raise configargparse.ArgumentTypeError(e.message) + raise configargparse.ArgumentTypeError(e) setheaders.append(p) if options.outfile and options.outfile[0] == options.rfile: diff --git a/test/mitmproxy/test_cmdline.py b/test/mitmproxy/test_cmdline.py index e75b7baf0..4fe2cf94f 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/tox.ini b/tox.ini index 846078fcb..4837d5b51 100644 --- a/tox.ini +++ b/tox.ini @@ -7,7 +7,7 @@ deps = codecov>=2.0.5 passenv = CI TRAVIS_BUILD_ID TRAVIS TRAVIS_BRANCH TRAVIS_JOB_NUMBER TRAVIS_PULL_REQUEST TRAVIS_JOB_ID TRAVIS_REPO_SLUG TRAVIS_COMMIT setenv = - PY3TESTS = test/netlib test/pathod/ test/mitmproxy/script test/mitmproxy/test_contentview.py test/mitmproxy/test_custom_contentview.py test/mitmproxy/test_app.py test/mitmproxy/test_controller.py test/mitmproxy/test_fuzzing.py test/mitmproxy/test_script.py test/mitmproxy/test_web_app.py test/mitmproxy/test_utils.py test/mitmproxy/test_stateobject.py + PY3TESTS = test/netlib test/pathod/ test/mitmproxy/script test/mitmproxy/test_contentview.py test/mitmproxy/test_custom_contentview.py test/mitmproxy/test_app.py test/mitmproxy/test_controller.py test/mitmproxy/test_fuzzing.py test/mitmproxy/test_script.py test/mitmproxy/test_web_app.py test/mitmproxy/test_utils.py test/mitmproxy/test_stateobject.py test/mitmproxy/test_cmdline.py [testenv:py27] commands =