aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@corte.si>2018-05-10 17:30:49 +1200
committerGitHub <noreply@github.com>2018-05-10 17:30:49 +1200
commitab89079c65272a9a2ef4f98d38d0ed39468bc876 (patch)
tree340375b07b4ce7de5e4b4c2d0c98fa4d18edee21 /test
parent0c101a4bccfb8460a11691cc17467d47d1974b2f (diff)
parent8c63a8818d6e66c5b1e32e30d785d8d4a3bc233c (diff)
downloadmitmproxy-ab89079c65272a9a2ef4f98d38d0ed39468bc876.tar.gz
mitmproxy-ab89079c65272a9a2ef4f98d38d0ed39468bc876.tar.bz2
mitmproxy-ab89079c65272a9a2ef4f98d38d0ed39468bc876.zip
Merge pull request #3109 from cortesi/kmap
console keybindings: define a yaml format, load CONFDIR/keys.yaml on startup
Diffstat (limited to 'test')
-rw-r--r--test/mitmproxy/net/test_tcp.py2
-rw-r--r--test/mitmproxy/proxy/protocol/test_http2.py2
-rw-r--r--test/mitmproxy/proxy/protocol/test_websocket.py2
-rw-r--r--test/mitmproxy/proxy/test_config.py4
-rw-r--r--test/mitmproxy/proxy/test_server.py6
-rw-r--r--test/mitmproxy/tools/console/test_keymap.py95
-rw-r--r--test/mitmproxy/tservers.py6
-rw-r--r--test/mitmproxy/utils/test_arg_check.py6
8 files changed, 109 insertions, 14 deletions
diff --git a/test/mitmproxy/net/test_tcp.py b/test/mitmproxy/net/test_tcp.py
index db8dff05..b6bb7cc1 100644
--- a/test/mitmproxy/net/test_tcp.py
+++ b/test/mitmproxy/net/test_tcp.py
@@ -338,7 +338,7 @@ class TestSSLUpstreamCertVerificationWValidCertChain(tservers.ServerTestBase):
c.wfile.flush()
assert c.rfile.readline() == testval
- def test_mode_strict_w_cadir_should_pass(self, tdata):
+ def test_mode_strict_w_confdir_should_pass(self, tdata):
c = tcp.TCPClient(("127.0.0.1", self.port))
with c.connect():
c.convert_to_tls(
diff --git a/test/mitmproxy/proxy/protocol/test_http2.py b/test/mitmproxy/proxy/protocol/test_http2.py
index 13f28728..b5f21413 100644
--- a/test/mitmproxy/proxy/protocol/test_http2.py
+++ b/test/mitmproxy/proxy/protocol/test_http2.py
@@ -103,7 +103,7 @@ class _Http2TestBase:
upstream_cert=True,
ssl_insecure=True
)
- opts.cadir = os.path.join(tempfile.gettempdir(), "mitmproxy")
+ opts.confdir = os.path.join(tempfile.gettempdir(), "mitmproxy")
return opts
@property
diff --git a/test/mitmproxy/proxy/protocol/test_websocket.py b/test/mitmproxy/proxy/protocol/test_websocket.py
index 3ce1436a..1f4e2bca 100644
--- a/test/mitmproxy/proxy/protocol/test_websocket.py
+++ b/test/mitmproxy/proxy/protocol/test_websocket.py
@@ -67,7 +67,7 @@ class _WebSocketTestBase:
ssl_insecure=True,
websocket=True,
)
- opts.cadir = os.path.join(tempfile.gettempdir(), "mitmproxy")
+ opts.confdir = os.path.join(tempfile.gettempdir(), "mitmproxy")
return opts
@property
diff --git a/test/mitmproxy/proxy/test_config.py b/test/mitmproxy/proxy/test_config.py
index a2fd8f37..1da031c6 100644
--- a/test/mitmproxy/proxy/test_config.py
+++ b/test/mitmproxy/proxy/test_config.py
@@ -6,9 +6,9 @@ from mitmproxy.proxy.config import ProxyConfig
class TestProxyConfig:
- def test_invalid_cadir(self):
+ def test_invalid_confdir(self):
opts = options.Options()
- opts.cadir = "foo"
+ opts.confdir = "foo"
with pytest.raises(exceptions.OptionsError, match="parent directory does not exist"):
ProxyConfig(opts)
diff --git a/test/mitmproxy/proxy/test_server.py b/test/mitmproxy/proxy/test_server.py
index 914f9184..52970c9b 100644
--- a/test/mitmproxy/proxy/test_server.py
+++ b/test/mitmproxy/proxy/test_server.py
@@ -309,10 +309,10 @@ class TestHTTPSUpstreamServerVerificationWTrustedCert(tservers.HTTPProxyTest):
with p.connect():
return p.request("get:/p/242")
- def test_verification_w_cadir(self, tdata):
+ def test_verification_w_confdir(self, tdata):
self.options.update(
ssl_insecure=False,
- ssl_verify_upstream_trusted_cadir=tdata.path(
+ ssl_verify_upstream_trusted_confdir=tdata.path(
"mitmproxy/data/servercert/"
),
ssl_verify_upstream_trusted_ca=None,
@@ -322,7 +322,7 @@ class TestHTTPSUpstreamServerVerificationWTrustedCert(tservers.HTTPProxyTest):
def test_verification_w_pemfile(self, tdata):
self.options.update(
ssl_insecure=False,
- ssl_verify_upstream_trusted_cadir=None,
+ ssl_verify_upstream_trusted_confdir=None,
ssl_verify_upstream_trusted_ca=tdata.path(
"mitmproxy/data/servercert/trusted-root.pem"
),
diff --git a/test/mitmproxy/tools/console/test_keymap.py b/test/mitmproxy/tools/console/test_keymap.py
index 7b475ff8..3e6f7c2e 100644
--- a/test/mitmproxy/tools/console/test_keymap.py
+++ b/test/mitmproxy/tools/console/test_keymap.py
@@ -70,3 +70,98 @@ def test_remove():
km.remove("key", ["commands"])
assert len(km.bindings) == 0
+
+
+def test_load_path(tmpdir):
+ dst = str(tmpdir.join("conf"))
+
+ kmc = keymap.KeymapConfig()
+ with taddons.context(kmc) as tctx:
+ km = keymap.Keymap(tctx.master)
+ tctx.master.keymap = km
+
+ with open(dst, 'wb') as f:
+ f.write(b"\xff\xff\xff")
+ with pytest.raises(keymap.KeyBindingError, match="expected UTF8"):
+ kmc.load_path(km, dst)
+
+ with open(dst, 'w') as f:
+ f.write("'''")
+ with pytest.raises(keymap.KeyBindingError):
+ kmc.load_path(km, dst)
+
+ with open(dst, 'w') as f:
+ f.write(
+ """
+ - key: key1
+ ctx: [unknown]
+ cmd: >
+ foo bar
+ foo bar
+ """
+ )
+ with pytest.raises(keymap.KeyBindingError):
+ kmc.load_path(km, dst)
+
+ with open(dst, 'w') as f:
+ f.write(
+ """
+ - key: key1
+ ctx: [chooser]
+ help: one
+ cmd: >
+ foo bar
+ foo bar
+ """
+ )
+ kmc.load_path(km, dst)
+ assert(km.get("chooser", "key1"))
+
+
+def test_parse():
+ kmc = keymap.KeymapConfig()
+ with taddons.context(kmc):
+ assert kmc.parse("") == []
+ assert kmc.parse("\n\n\n \n") == []
+ with pytest.raises(keymap.KeyBindingError, match="expected a list of keys"):
+ kmc.parse("key: val")
+ with pytest.raises(keymap.KeyBindingError, match="expected a list of keys"):
+ kmc.parse("val")
+ with pytest.raises(keymap.KeyBindingError, match="Unknown key attributes"):
+ kmc.parse(
+ """
+ - key: key1
+ nonexistent: bar
+ """
+ )
+ with pytest.raises(keymap.KeyBindingError, match="Missing required key attributes"):
+ kmc.parse(
+ """
+ - help: key1
+ """
+ )
+ with pytest.raises(keymap.KeyBindingError, match="Invalid type for cmd"):
+ kmc.parse(
+ """
+ - key: key1
+ cmd: [ cmd ]
+ """
+ )
+ with pytest.raises(keymap.KeyBindingError, match="Invalid type for ctx"):
+ kmc.parse(
+ """
+ - key: key1
+ ctx: foo
+ cmd: cmd
+ """
+ )
+ assert kmc.parse(
+ """
+ - key: key1
+ ctx: [one, two]
+ help: one
+ cmd: >
+ foo bar
+ foo bar
+ """
+ ) == [{"key": "key1", "ctx": ["one", "two"], "help": "one", "cmd": "foo bar foo bar\n"}] \ No newline at end of file
diff --git a/test/mitmproxy/tservers.py b/test/mitmproxy/tservers.py
index 6f528ec2..ab400396 100644
--- a/test/mitmproxy/tservers.py
+++ b/test/mitmproxy/tservers.py
@@ -151,7 +151,7 @@ class ProxyTestBase:
def teardown_class(cls):
# perf: we want to run tests in parallel
# should this ever cause an error, travis should catch it.
- # shutil.rmtree(cls.cadir)
+ # shutil.rmtree(cls.confdir)
cls.proxy.shutdown()
cls.server.shutdown()
cls.server2.shutdown()
@@ -175,10 +175,10 @@ class ProxyTestBase:
@classmethod
def get_options(cls):
- cls.cadir = os.path.join(tempfile.gettempdir(), "mitmproxy")
+ cls.confdir = os.path.join(tempfile.gettempdir(), "mitmproxy")
return options.Options(
listen_port=0,
- cadir=cls.cadir,
+ confdir=cls.confdir,
add_upstream_certs_to_client_chain=cls.add_upstream_certs_to_client_chain,
ssl_insecure=True,
)
diff --git a/test/mitmproxy/utils/test_arg_check.py b/test/mitmproxy/utils/test_arg_check.py
index 72913955..8ab14077 100644
--- a/test/mitmproxy/utils/test_arg_check.py
+++ b/test/mitmproxy/utils/test_arg_check.py
@@ -10,9 +10,9 @@ from mitmproxy.utils import arg_check
@pytest.mark.parametrize('arg, output', [
(["-T"], "-T is deprecated, please use --mode transparent instead"),
(["-U"], "-U is deprecated, please use --mode upstream:SPEC instead"),
- (["--cadir"], "--cadir is deprecated.\n"
- "Please use `--set cadir=value` instead.\n"
- "To show all options and their default values use --options"),
+ (["--confdir"], "--confdir is deprecated.\n"
+ "Please use `--set confdir=value` instead.\n"
+ "To show all options and their default values use --options"),
(["--palette"], "--palette is deprecated.\n"
"Please use `--set console_palette=value` instead.\n"
"To show all options and their default values use --options"),