mirror of
https://github.com/vee1e/mitmproxy.git
synced 2026-09-02 18:57:22 +00:00
minor improvements, tests++
This commit is contained in:
parent
7dda557add
commit
b5e3f736c0
7 changed files with 35 additions and 13 deletions
|
|
@ -99,9 +99,7 @@ requirements installed, and you can run the basic test suite with tox_:
|
|||
|
||||
.. code-block:: bash
|
||||
|
||||
tox -e py37 # runs Python tests
|
||||
tox -e flake8 # checks code style style
|
||||
tox -e mypy # checks static types
|
||||
tox -e py # runs Python tests
|
||||
|
||||
Our CI system has additional tox environments that are run on every pull request and branch on GitHub.
|
||||
|
||||
|
|
@ -141,11 +139,12 @@ good reason not to.
|
|||
|
||||
This is automatically enforced on every PR. If we detect a linting error, the
|
||||
PR checks will fail and block merging. You can run our lint checks yourself
|
||||
with the following command:
|
||||
with the following commands:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
tox -e lint
|
||||
tox -e flake8
|
||||
tox -e mypy # checks static types
|
||||
|
||||
|
||||
.. |mitmproxy_site| image:: https://shields.mitmproxy.org/badge/https%3A%2F%2F-mitmproxy.org-blue.svg
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ class CommandHistory:
|
|||
def running(self):
|
||||
# FIXME: We have a weird bug where the contract for configure is not followed and it is never called with
|
||||
# confdir or command_history as updated.
|
||||
self.configure("command_history")
|
||||
self.configure("command_history") # pragma: no cover
|
||||
|
||||
def configure(self, updated):
|
||||
if "command_history" in updated or "confdir" in updated:
|
||||
|
|
@ -36,9 +36,9 @@ class CommandHistory:
|
|||
self.set_filter('')
|
||||
|
||||
def done(self):
|
||||
if ctx.options.command_history and len(self.history) > self.VACUUM_SIZE:
|
||||
if ctx.options.command_history and len(self.history) >= self.VACUUM_SIZE:
|
||||
# vacuum history so that it doesn't grow indefinitely.
|
||||
history_str = "\n".join(self.history[-self.VACUUM_SIZE / 2:]) + "\n"
|
||||
history_str = "\n".join(self.history[-self.VACUUM_SIZE // 2:]) + "\n"
|
||||
self.history_file.write_text(history_str)
|
||||
|
||||
@command.command("commands.history.add")
|
||||
|
|
|
|||
|
|
@ -331,7 +331,8 @@ def _read_headers(rfile):
|
|||
while True:
|
||||
line = rfile.readline()
|
||||
if not line or line == b"\r\n" or line == b"\n":
|
||||
break
|
||||
# we do have coverage of this, but coverage.py does not detect it.
|
||||
break # pragma: no cover
|
||||
if line[0] in b" \t":
|
||||
if not ret:
|
||||
raise exceptions.HttpSyntaxException("Invalid headers")
|
||||
|
|
|
|||
1
setup.py
1
setup.py
|
|
@ -93,6 +93,7 @@ setup(
|
|||
'dev': [
|
||||
"asynctest>=0.12.0",
|
||||
"Flask>=1.0,<1.2",
|
||||
"hypothesis>=5.8,<5.9",
|
||||
"parver>=0.1,<2.0",
|
||||
"pytest-asyncio>=0.10.0,<0.11",
|
||||
"pytest-cov>=2.7.1,<3",
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue