From fe01b1435a2acc9896b24a814e535558884a6143 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sun, 13 Nov 2016 11:50:28 +1300 Subject: upstream_proxy_auth -> upstream_auth Also clarify what this does in commandline help. --- test/mitmproxy/addons/test_upstream_auth.py | 65 +++++++++++++++++++++++ test/mitmproxy/addons/test_upstream_proxy_auth.py | 65 ----------------------- 2 files changed, 65 insertions(+), 65 deletions(-) create mode 100644 test/mitmproxy/addons/test_upstream_auth.py delete mode 100644 test/mitmproxy/addons/test_upstream_proxy_auth.py (limited to 'test') diff --git a/test/mitmproxy/addons/test_upstream_auth.py b/test/mitmproxy/addons/test_upstream_auth.py new file mode 100644 index 00000000..985b13a7 --- /dev/null +++ b/test/mitmproxy/addons/test_upstream_auth.py @@ -0,0 +1,65 @@ +import base64 + +from mitmproxy import exceptions +from mitmproxy.test import taddons +from mitmproxy.test import tflow +from mitmproxy.test import tutils +from mitmproxy.addons import upstream_auth + + +def test_configure(): + up = upstream_auth.UpstreamAuth() + with taddons.context() as tctx: + tctx.configure(up, upstream_auth="test:test") + assert up.auth == b"Basic" + b" " + base64.b64encode(b"test:test") + + tctx.configure(up, upstream_auth="test:") + assert up.auth == b"Basic" + b" " + base64.b64encode(b"test:") + + tctx.configure(up, upstream_auth=None) + assert not up.auth + + tutils.raises( + exceptions.OptionsError, + tctx.configure, + up, + upstream_auth="" + ) + tutils.raises( + exceptions.OptionsError, + tctx.configure, + up, + upstream_auth=":" + ) + tutils.raises( + exceptions.OptionsError, + tctx.configure, + up, + upstream_auth=":test" + ) + + +def test_simple(): + up = upstream_auth.UpstreamAuth() + with taddons.context() as tctx: + tctx.configure(up, upstream_auth="foo:bar") + + f = tflow.tflow() + f.mode = "upstream" + up.requestheaders(f) + assert "proxy-authorization" in f.request.headers + + f = tflow.tflow() + up.requestheaders(f) + assert "proxy-authorization" not in f.request.headers + + tctx.configure(up, mode="reverse") + f = tflow.tflow() + f.mode = "transparent" + up.requestheaders(f) + assert "proxy-authorization" in f.request.headers + + f = tflow.tflow() + f.mode = "upstream" + up.http_connect(f) + assert "proxy-authorization" in f.request.headers diff --git a/test/mitmproxy/addons/test_upstream_proxy_auth.py b/test/mitmproxy/addons/test_upstream_proxy_auth.py deleted file mode 100644 index d5d6a3e3..00000000 --- a/test/mitmproxy/addons/test_upstream_proxy_auth.py +++ /dev/null @@ -1,65 +0,0 @@ -import base64 - -from mitmproxy import exceptions -from mitmproxy.test import taddons -from mitmproxy.test import tflow -from mitmproxy.test import tutils -from mitmproxy.addons import upstream_proxy_auth - - -def test_configure(): - up = upstream_proxy_auth.UpstreamProxyAuth() - with taddons.context() as tctx: - tctx.configure(up, upstream_auth="test:test") - assert up.auth == b"Basic" + b" " + base64.b64encode(b"test:test") - - tctx.configure(up, upstream_auth="test:") - assert up.auth == b"Basic" + b" " + base64.b64encode(b"test:") - - tctx.configure(up, upstream_auth=None) - assert not up.auth - - tutils.raises( - exceptions.OptionsError, - tctx.configure, - up, - upstream_auth="" - ) - tutils.raises( - exceptions.OptionsError, - tctx.configure, - up, - upstream_auth=":" - ) - tutils.raises( - exceptions.OptionsError, - tctx.configure, - up, - upstream_auth=":test" - ) - - -def test_simple(): - up = upstream_proxy_auth.UpstreamProxyAuth() - with taddons.context() as tctx: - tctx.configure(up, upstream_auth="foo:bar") - - f = tflow.tflow() - f.mode = "upstream" - up.requestheaders(f) - assert "proxy-authorization" in f.request.headers - - f = tflow.tflow() - up.requestheaders(f) - assert "proxy-authorization" not in f.request.headers - - tctx.configure(up, mode="reverse") - f = tflow.tflow() - f.mode = "transparent" - up.requestheaders(f) - assert "proxy-authorization" in f.request.headers - - f = tflow.tflow() - f.mode = "upstream" - up.http_connect(f) - assert "proxy-authorization" in f.request.headers -- cgit v1.2.3