aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/mitmproxy/proxy/test_config.py39
-rw-r--r--test/mitmproxy/tools/console/test_help.py11
-rw-r--r--test/mitmproxy/tools/console/test_keymap.py37
-rw-r--r--test/mitmproxy/tools/console/test_master.py9
4 files changed, 67 insertions, 29 deletions
diff --git a/test/mitmproxy/proxy/test_config.py b/test/mitmproxy/proxy/test_config.py
index 777ab4dd..a7da980b 100644
--- a/test/mitmproxy/proxy/test_config.py
+++ b/test/mitmproxy/proxy/test_config.py
@@ -1 +1,38 @@
-# TODO: write tests
+import pytest
+
+from mitmproxy import options
+from mitmproxy import exceptions
+from mitmproxy.proxy.config import ProxyConfig
+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")]
+ with pytest.raises(exceptions.OptionsError, match="Invalid certificate format"):
+ ProxyConfig(opts)
diff --git a/test/mitmproxy/tools/console/test_help.py b/test/mitmproxy/tools/console/test_help.py
deleted file mode 100644
index 0ebc2d6a..00000000
--- a/test/mitmproxy/tools/console/test_help.py
+++ /dev/null
@@ -1,11 +0,0 @@
-import mitmproxy.tools.console.help as help
-
-from ....conftest import skip_appveyor
-
-
-@skip_appveyor
-class TestHelp:
-
- def test_helptext(self):
- h = help.HelpView(None)
- assert h.helptext()
diff --git a/test/mitmproxy/tools/console/test_keymap.py b/test/mitmproxy/tools/console/test_keymap.py
index 6a75800e..bbca4ac9 100644
--- a/test/mitmproxy/tools/console/test_keymap.py
+++ b/test/mitmproxy/tools/console/test_keymap.py
@@ -5,25 +5,28 @@ import pytest
def test_bind():
- with taddons.context() as tctx:
- km = keymap.Keymap(tctx.master)
- km.executor = mock.Mock()
+ with taddons.context() as tctx:
+ km = keymap.Keymap(tctx.master)
+ km.executor = mock.Mock()
- with pytest.raises(ValueError):
- km.add("foo", "bar", ["unsupported"])
+ with pytest.raises(ValueError):
+ km.add("foo", "bar", ["unsupported"])
- km.add("key", "str", ["options", "commands"])
- assert km.get("options", "key")
- assert km.get("commands", "key")
- assert not km.get("flowlist", "key")
+ km.add("key", "str", ["options", "commands"])
+ assert km.get("options", "key")
+ assert km.get("commands", "key")
+ assert not km.get("flowlist", "key")
+ assert len((km.list("commands"))) == 1
- km.handle("unknown", "unknown")
- assert not km.executor.called
+ km.handle("unknown", "unknown")
+ assert not km.executor.called
- km.handle("options", "key")
- assert km.executor.called
+ km.handle("options", "key")
+ assert km.executor.called
- km.add("glob", "str", ["global"])
- km.executor = mock.Mock()
- km.handle("options", "glob")
- assert km.executor.called
+ km.add("glob", "str", ["global"])
+ km.executor = mock.Mock()
+ km.handle("options", "glob")
+ assert km.executor.called
+
+ assert len((km.list("global"))) == 1
diff --git a/test/mitmproxy/tools/console/test_master.py b/test/mitmproxy/tools/console/test_master.py
index c87c9e83..7732483f 100644
--- a/test/mitmproxy/tools/console/test_master.py
+++ b/test/mitmproxy/tools/console/test_master.py
@@ -1,3 +1,5 @@
+import pytest
+
from mitmproxy.test import tflow
from mitmproxy.test import tutils
from mitmproxy.tools import console
@@ -6,6 +8,13 @@ from mitmproxy import options
from mitmproxy.tools.console import common
from ... import tservers
import urwid
+from unittest import mock
+
+
+@pytest.fixture(scope="module", autouse=True)
+def definitely_atty():
+ with mock.patch("sys.stdout.isatty", lambda: True):
+ yield
def test_format_keyvals():