diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/mitmproxy/addons/test_core.py | 21 | ||||
-rw-r--r-- | test/mitmproxy/net/http/test_request.py | 4 | ||||
-rw-r--r-- | test/mitmproxy/proxy/test_config.py | 18 | ||||
-rw-r--r-- | test/mitmproxy/test_proxy.py | 5 |
4 files changed, 22 insertions, 26 deletions
diff --git a/test/mitmproxy/addons/test_core.py b/test/mitmproxy/addons/test_core.py index b1b105d9..3c674b3f 100644 --- a/test/mitmproxy/addons/test_core.py +++ b/test/mitmproxy/addons/test_core.py @@ -3,6 +3,7 @@ from unittest import mock from mitmproxy.addons import core from mitmproxy.test import taddons from mitmproxy.test import tflow +from mitmproxy.test import tutils from mitmproxy import exceptions import pytest @@ -167,6 +168,12 @@ def test_validation_simple(): add_upstream_certs_to_client_chain = True, upstream_cert = False ) + with pytest.raises(exceptions.OptionsError, match="requires certificate verification to be disabled"): + tctx.configure( + sa, + add_upstream_certs_to_client_chain = True, + ssl_insecure = False + ) with pytest.raises(exceptions.OptionsError, match="Invalid mode"): tctx.configure( sa, @@ -188,4 +195,16 @@ def test_validation_modes(m): with taddons.context() as tctx: tctx.configure(sa, mode = "reverse:http://localhost") with pytest.raises(Exception, match="Invalid server specification"): - tctx.configure(sa, mode = "reverse:")
\ No newline at end of file + tctx.configure(sa, mode = "reverse:") + + +def test_client_certs(): + sa = core.Core() + with taddons.context() as tctx: + # Folders should work. + tctx.configure(sa, client_certs = tutils.test_data.path("mitmproxy/data/clientcert")) + # Files, too. + tctx.configure(sa, client_certs = tutils.test_data.path("mitmproxy/data/clientcert/client.pem")) + + with pytest.raises(exceptions.OptionsError, match="certificate path does not exist"): + tctx.configure(sa, client_certs = "invalid") diff --git a/test/mitmproxy/net/http/test_request.py b/test/mitmproxy/net/http/test_request.py index ce49002c..ef581a91 100644 --- a/test/mitmproxy/net/http/test_request.py +++ b/test/mitmproxy/net/http/test_request.py @@ -351,10 +351,10 @@ class TestRequestUtils: request.headers["Content-Type"] = "application/x-www-form-urlencoded" assert list(request.urlencoded_form.items()) == [("foobar", "baz")] request.raw_content = b"\xFF" - assert len(request.urlencoded_form) == 0 + assert len(request.urlencoded_form) == 1 def test_set_urlencoded_form(self): - request = treq() + request = treq(content=b"\xec\xed") request.urlencoded_form = [('foo', 'bar'), ('rab', 'oof')] assert request.headers["Content-Type"] == "application/x-www-form-urlencoded" assert request.content diff --git a/test/mitmproxy/proxy/test_config.py b/test/mitmproxy/proxy/test_config.py index a7da980b..60a0deb5 100644 --- a/test/mitmproxy/proxy/test_config.py +++ b/test/mitmproxy/proxy/test_config.py @@ -7,30 +7,12 @@ from mitmproxy.test import tutils class TestProxyConfig: - def test_upstream_cert_insecure(self): - opts = options.Options() - opts.add_upstream_certs_to_client_chain = True - with pytest.raises(exceptions.OptionsError, match="verify-upstream-cert"): - ProxyConfig(opts) - def test_invalid_cadir(self): opts = options.Options() opts.cadir = "foo" with pytest.raises(exceptions.OptionsError, match="parent directory does not exist"): ProxyConfig(opts) - def test_invalid_client_certs(self): - opts = options.Options() - opts.client_certs = "foo" - with pytest.raises(exceptions.OptionsError, match="certificate path does not exist"): - ProxyConfig(opts) - - def test_valid_client_certs(self): - opts = options.Options() - opts.client_certs = tutils.test_data.path("mitmproxy/data/clientcert/") - p = ProxyConfig(opts) - assert p.client_certs - def test_invalid_certificate(self): opts = options.Options() opts.certs = [tutils.test_data.path("mitmproxy/data/dumpfile-011")] diff --git a/test/mitmproxy/test_proxy.py b/test/mitmproxy/test_proxy.py index 299abab3..75d4cdf0 100644 --- a/test/mitmproxy/test_proxy.py +++ b/test/mitmproxy/test_proxy.py @@ -1,6 +1,5 @@ import argparse from unittest import mock -from OpenSSL import SSL import pytest from mitmproxy.tools import cmdline @@ -50,10 +49,6 @@ class TestProcessProxyOptions: with pytest.raises(Exception, match="does not exist"): self.p("--cert", "nonexistent") - def test_insecure(self): - p = self.assert_noerr("--ssl-insecure") - assert p.openssl_verification_mode_server == SSL.VERIFY_NONE - class TestProxyServer: |