diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/mitmproxy/addons/test_check_alpn.py | 23 | ||||
| -rw-r--r-- | test/mitmproxy/addons/test_check_ca.py | 19 | ||||
| -rw-r--r-- | test/mitmproxy/test_tools_dump.py | 21 | ||||
| -rw-r--r-- | test/mitmproxy/test_web_master.py | 5 | 
4 files changed, 65 insertions, 3 deletions
| diff --git a/test/mitmproxy/addons/test_check_alpn.py b/test/mitmproxy/addons/test_check_alpn.py new file mode 100644 index 00000000..2dc0c835 --- /dev/null +++ b/test/mitmproxy/addons/test_check_alpn.py @@ -0,0 +1,23 @@ +from mitmproxy.addons import check_alpn +from mitmproxy.test import taddons +from ...conftest import requires_alpn + + +class TestCheckALPN: + +    @requires_alpn +    def test_check_alpn(self): +        msg = 'ALPN support missing' + +        with taddons.context() as tctx: +            a = check_alpn.CheckALPN() +            tctx.configure(a) +            assert not any(msg in m for l, m in tctx.master.event_log) + +    def test_check_no_alpn(self, disable_alpn): +        msg = 'ALPN support missing' + +        with taddons.context() as tctx: +            a = check_alpn.CheckALPN() +            tctx.configure(a) +            assert any(msg in m for l, m in tctx.master.event_log) diff --git a/test/mitmproxy/addons/test_check_ca.py b/test/mitmproxy/addons/test_check_ca.py new file mode 100644 index 00000000..fc64621c --- /dev/null +++ b/test/mitmproxy/addons/test_check_ca.py @@ -0,0 +1,19 @@ +import pytest +from unittest import mock + +from mitmproxy.addons import check_ca +from mitmproxy.test import taddons + + +class TestCheckCA: + +    @pytest.mark.parametrize('expired', [False, True]) +    def test_check_ca(self, expired): +        msg = 'The mitmproxy certificate authority has expired!' + +        with taddons.context() as tctx: +            tctx.master.server = mock.MagicMock() +            tctx.master.server.config.certstore.default_ca.has_expired = mock.MagicMock(return_value=expired) +            a = check_ca.CheckCA() +            tctx.configure(a) +            assert any(msg in m for l, m in tctx.master.event_log) is expired diff --git a/test/mitmproxy/test_tools_dump.py b/test/mitmproxy/test_tools_dump.py index 2e64d2d2..505f514b 100644 --- a/test/mitmproxy/test_tools_dump.py +++ b/test/mitmproxy/test_tools_dump.py @@ -1,10 +1,13 @@  import os +import pytest +from unittest import mock -from mitmproxy.tools import dump  from mitmproxy import proxy -from mitmproxy.test import tutils  from mitmproxy import log  from mitmproxy import controller +from mitmproxy.tools import dump + +from mitmproxy.test import tutils  from . import mastertest @@ -37,3 +40,17 @@ class TestDumpMaster(mastertest.MasterTest):          ent.reply = controller.DummyReply()          m.log(ent)          assert m.has_errored + +    @pytest.mark.parametrize("termlog", [False, True]) +    def test_addons_termlog(self, termlog): +        with mock.patch('sys.stdout'): +            o = dump.Options() +            m = dump.DumpMaster(o, proxy.DummyServer(), with_termlog=termlog) +            assert (m.addons.get('termlog') is not None) == termlog + +    @pytest.mark.parametrize("dumper", [False, True]) +    def test_addons_dumper(self, dumper): +        with mock.patch('sys.stdout'): +            o = dump.Options() +            m = dump.DumpMaster(o, proxy.DummyServer(), with_dumper=dumper) +            assert (m.addons.get('dumper') is not None) == dumper diff --git a/test/mitmproxy/test_web_master.py b/test/mitmproxy/test_web_master.py index 08dce8f3..3591284d 100644 --- a/test/mitmproxy/test_web_master.py +++ b/test/mitmproxy/test_web_master.py @@ -1,13 +1,16 @@  from mitmproxy.tools.web import master  from mitmproxy import proxy  from mitmproxy import options +from mitmproxy.proxy.config import ProxyConfig +  from . import mastertest  class TestWebMaster(mastertest.MasterTest):      def mkmaster(self, **opts):          o = options.Options(**opts) -        return master.WebMaster(o, proxy.DummyServer(o)) +        c = ProxyConfig(o) +        return master.WebMaster(o, proxy.DummyServer(c))      def test_basic(self):          m = self.mkmaster() | 
