aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2020-04-08 22:11:52 +0200
committerMaximilian Hils <git@maximilianhils.com>2020-04-09 08:25:22 +0200
commitb5e3f736c0c6654c3ef0d1f280a4eacdb5ca91de (patch)
treec1472652ee95cf8c41b91d544e89f3b0d64c0323 /test
parent7dda557add07de21cc701cebc60410579ed4b811 (diff)
downloadmitmproxy-b5e3f736c0c6654c3ef0d1f280a4eacdb5ca91de.tar.gz
mitmproxy-b5e3f736c0c6654c3ef0d1f280a4eacdb5ca91de.tar.bz2
mitmproxy-b5e3f736c0c6654c3ef0d1f280a4eacdb5ca91de.zip
minor improvements, tests++
Diffstat (limited to 'test')
-rw-r--r--test/mitmproxy/addons/test_command_history.py13
-rw-r--r--test/mitmproxy/net/http/http1/test_read.py3
-rw-r--r--test/mitmproxy/test_command_lexer.py13
3 files changed, 25 insertions, 4 deletions
diff --git a/test/mitmproxy/addons/test_command_history.py b/test/mitmproxy/addons/test_command_history.py
index df20fba7..245bbc26 100644
--- a/test/mitmproxy/addons/test_command_history.py
+++ b/test/mitmproxy/addons/test_command_history.py
@@ -5,15 +5,22 @@ from mitmproxy.test import taddons
class TestCommandHistory:
- def test_load_from_file(self, tmpdir):
- commands = ['cmd1', 'cmd2', 'cmd3']
- with open(tmpdir.join('command_history'), 'w') as f:
+ def test_load_and_save(self, tmpdir):
+ history_file = tmpdir.join('command_history')
+ commands = ["cmd1", "cmd2", "cmd3"]
+ with open(history_file, 'w') as f:
f.write("\n".join(commands))
ch = command_history.CommandHistory()
+ ch.VACUUM_SIZE = 4
with taddons.context(ch) as tctx:
tctx.options.confdir = str(tmpdir)
assert ch.history == commands
+ ch.add_command("cmd4")
+ ch.done()
+
+ with open(history_file, "r") as f:
+ assert f.read() == "cmd3\ncmd4\n"
def test_add_command(self):
history = command_history.CommandHistory()
diff --git a/test/mitmproxy/net/http/http1/test_read.py b/test/mitmproxy/net/http/http1/test_read.py
index 127f75ba..92c94fe3 100644
--- a/test/mitmproxy/net/http/http1/test_read.py
+++ b/test/mitmproxy/net/http/http1/test_read.py
@@ -161,7 +161,8 @@ def test_connection_close():
def test_expected_http_body_size():
# Expect: 100-continue
assert expected_http_body_size(
- treq(headers=Headers(expect="100-continue", content_length="42"))
+ treq(headers=Headers(expect="100-continue", content_length="42")),
+ expect_continue_as_0=True
) == 0
# Expect: 100-continue
assert expected_http_body_size(
diff --git a/test/mitmproxy/test_command_lexer.py b/test/mitmproxy/test_command_lexer.py
index 3f009f88..cdda1085 100644
--- a/test/mitmproxy/test_command_lexer.py
+++ b/test/mitmproxy/test_command_lexer.py
@@ -1,5 +1,7 @@
import pyparsing
import pytest
+from hypothesis import given, example
+from hypothesis.strategies import text
from mitmproxy import command_lexer
@@ -36,3 +38,14 @@ def test_partial_quoted_string(test_input, valid):
)
def test_expr(test_input, expected):
assert list(command_lexer.expr.parseString(test_input, parseAll=True)) == expected
+
+
+@given(text())
+def test_quote_unquote_cycle(s):
+ assert command_lexer.unquote(command_lexer.quote(s)) == s
+
+
+@given(text())
+@example("'foo\\'")
+def test_unquote_never_fails(s):
+ command_lexer.unquote(s)