From 0e27dfd9c132e1f8768ae33a33ae8a1c55541948 Mon Sep 17 00:00:00 2001 From: yonder Date: Fri, 4 Mar 2016 11:12:03 -0500 Subject: [PATCH] Improve test case --- mitmproxy/cmdline.py | 2 +- test/mitmproxy/test_cmdline.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/mitmproxy/cmdline.py b/mitmproxy/cmdline.py index eb15a1d24..b1b860f83 100644 --- a/mitmproxy/cmdline.py +++ b/mitmproxy/cmdline.py @@ -119,7 +119,7 @@ def parse_server_spec(url): def parse_upstream_auth(auth): - pattern = re.compile(":") + pattern = re.compile(".+:") if pattern.search(auth) is None: raise configargparse.ArgumentTypeError( "Invalid upstream auth specification: %s" % auth diff --git a/test/mitmproxy/test_cmdline.py b/test/mitmproxy/test_cmdline.py index 1546bb419..e75b7baf0 100644 --- a/test/mitmproxy/test_cmdline.py +++ b/test/mitmproxy/test_cmdline.py @@ -56,8 +56,12 @@ def test_parse_server_spec(): 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, ":") + tutils.raises("Invalid upstream auth specification", cmdline.parse_upstream_auth, ":test") assert cmdline.parse_upstream_auth( "test:test") == "Basic" + " " + base64.b64encode("test:test") + assert cmdline.parse_upstream_auth( + "test:") == "Basic" + " " + base64.b64encode("test:") def test_parse_setheaders():