aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.codecov.yml (renamed from codecov.yml)0
-rw-r--r--README.rst22
-rw-r--r--pathod/pathoc.py4
-rw-r--r--pathod/protocols/http.py8
-rw-r--r--test/pathod/test_pathoc.py2
-rw-r--r--test/pathod/test_pathod.py16
-rw-r--r--test/pathod/tutils.py2
-rw-r--r--tox.ini2
8 files changed, 39 insertions, 17 deletions
diff --git a/codecov.yml b/.codecov.yml
index db247200..db247200 100644
--- a/codecov.yml
+++ b/.codecov.yml
diff --git a/README.rst b/README.rst
index 4a665360..983f50fb 100644
--- a/README.rst
+++ b/README.rst
@@ -94,6 +94,21 @@ requirements installed, and you can simply run the test suite:
Please ensure that all patches are accompanied by matching changes in the test
suite. The project tries to maintain 100% test coverage.
+You can also use `tox` to run a full suite of tests in Python 2.7 and 3.5,
+including a quick test to check documentation and code linting.
+
+The following tox environments are relevant for local testing:
+
+.. code-block:: text
+
+ tox -e py27 # runs all tests with Python 2.7
+ tox -e py35 # runs all tests with Python 3.5 (partial support only)
+ tox -e docs # runs a does-it-compile check on the documentation
+ tox -e lint # runs the linter for coding style checks
+
+We are in the middle of transitioning to Python 3, so please make sure all tests
+pass in Python 2.7 and 3.5. Running `tox` ensure all necessary tests are executed.
+
Documentation
-------------
@@ -120,6 +135,13 @@ contribute and collaborate. Please stick to the guidelines in
`PEP8`_ and the `Google Style Guide`_ unless there's a very
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. We are using this command to check for style compliance:
+
+.. code-block:: text
+
+ flake8 --jobs 8 --count mitmproxy netlib pathod examples test
+
.. |mitmproxy_site| image:: https://shields.mitmproxy.org/api/https%3A%2F%2F-mitmproxy.org-blue.svg
:target: https://mitmproxy.org/
diff --git a/pathod/pathoc.py b/pathod/pathoc.py
index 478ce2a2..ea21b747 100644
--- a/pathod/pathoc.py
+++ b/pathod/pathoc.py
@@ -241,8 +241,8 @@ class Pathoc(tcp.TCPClient):
def http_connect(self, connect_to):
self.wfile.write(
- 'CONNECT %s:%s HTTP/1.1\r\n' % tuple(connect_to) +
- '\r\n'
+ b'CONNECT %s:%d HTTP/1.1\r\n' % (connect_to[0].encode("idna"), connect_to[1]) +
+ b'\r\n'
)
self.wfile.flush()
try:
diff --git a/pathod/protocols/http.py b/pathod/protocols/http.py
index 7736df4b..2ede2591 100644
--- a/pathod/protocols/http.py
+++ b/pathod/protocols/http.py
@@ -17,15 +17,15 @@ class HTTPProtocol(object):
"""
self.pathod_handler.wfile.write(
- 'HTTP/1.1 200 Connection established\r\n' +
- ('Proxy-agent: %s\r\n' % version.PATHOD) +
- '\r\n'
+ b'HTTP/1.1 200 Connection established\r\n' +
+ (b'Proxy-agent: %s\r\n' % version.PATHOD.encode()) +
+ b'\r\n'
)
self.pathod_handler.wfile.flush()
if not self.pathod_handler.server.ssloptions.not_after_connect:
try:
cert, key, chain_file_ = self.pathod_handler.server.ssloptions.get_cert(
- connect[0]
+ connect[0].encode()
)
self.pathod_handler.convert_to_ssl(
cert,
diff --git a/test/pathod/test_pathoc.py b/test/pathod/test_pathoc.py
index 05cf518d..7f26c247 100644
--- a/test/pathod/test_pathoc.py
+++ b/test/pathod/test_pathoc.py
@@ -169,7 +169,7 @@ class TestDaemon(PathocTestDaemon):
def test_connect_fail(self):
to = ("foobar", 80)
c = pathoc.Pathoc(("127.0.0.1", self.d.port), fp=None)
- c.rfile, c.wfile = StringIO(), StringIO()
+ c.rfile, c.wfile = BytesIO(), BytesIO()
with raises("connect failed"):
c.http_connect(to)
c.rfile = BytesIO(
diff --git a/test/pathod/test_pathod.py b/test/pathod/test_pathod.py
index ed4ef49f..dc02fffb 100644
--- a/test/pathod/test_pathod.py
+++ b/test/pathod/test_pathod.py
@@ -52,7 +52,7 @@ class TestNotAfterConnect(tutils.DaemonTests):
class TestCustomCert(tutils.DaemonTests):
ssl = True
ssloptions = dict(
- certs=[("*", tutils.test_data.path("data/testkey.pem"))],
+ certs=[(b"*", tutils.test_data.path("data/testkey.pem"))],
)
def test_connect(self):
@@ -66,7 +66,7 @@ class TestCustomCert(tutils.DaemonTests):
class TestSSLCN(tutils.DaemonTests):
ssl = True
ssloptions = dict(
- cn="foo.com"
+ cn=b"foo.com"
)
def test_connect(self):
@@ -100,7 +100,7 @@ class TestNocraft(tutils.DaemonTests):
def test_nocraft(self):
r = self.get(r"200:b'\xf0'")
assert r.status_code == 800
- assert "Crafting disabled" in r.content
+ assert b"Crafting disabled" in r.content
class CommonTests(tutils.DaemonTests):
@@ -137,7 +137,7 @@ class CommonTests(tutils.DaemonTests):
def test_static(self):
rsp = self.get("200:b<file")
assert rsp.status_code == 200
- assert rsp.content.strip() == "testfile"
+ assert rsp.content.strip() == b"testfile"
def test_anchor(self):
rsp = self.getpath("/anchor/foo")
@@ -148,7 +148,7 @@ class CommonTests(tutils.DaemonTests):
with c.connect():
if self.ssl:
c.convert_to_ssl()
- c.wfile.write("foo\n\n\n")
+ c.wfile.write(b"foo\n\n\n")
c.wfile.flush()
l = self.d.last_log()
assert l["type"] == "error"
@@ -177,7 +177,7 @@ class CommonTests(tutils.DaemonTests):
def test_source_access_denied(self):
rsp = self.get("200:b</foo")
assert rsp.status_code == 800
- assert "File access denied" in rsp.content
+ assert b"File access denied" in rsp.content
def test_proxy(self):
r, _ = self.pathoc([r"get:'http://foo.com/p/202':da"])
@@ -195,7 +195,7 @@ class CommonTests(tutils.DaemonTests):
["ws:/p/", "wf:f'wf:b\"test\"':pa,1"],
ws_read_limit=1
)
- assert r[1].payload == "test"
+ assert r[1].payload == b"test"
def test_websocket_frame_reflect_error(self):
r, _ = self.pathoc(
@@ -239,7 +239,7 @@ class TestDaemonSSL(CommonTests):
c.rbufsize = 0
c.wbufsize = 0
with c.connect():
- c.wfile.write("\0\0\0\0")
+ c.wfile.write(b"\0\0\0\0")
tutils.raises(TlsException, c.convert_to_ssl)
l = self.d.last_log()
assert l["type"] == "error"
diff --git a/test/pathod/tutils.py b/test/pathod/tutils.py
index daaa8628..3a94b6eb 100644
--- a/test/pathod/tutils.py
+++ b/test/pathod/tutils.py
@@ -100,7 +100,7 @@ class DaemonTests(object):
)
with c.connect():
resp = c.request(
- "get:/p/%s" % urllib.parse.quote(spec).encode("string_escape")
+ "get:/p/%s" % urllib.parse.quote(spec)
)
return resp
diff --git a/tox.ini b/tox.ini
index c150e14e..1c48b91f 100644
--- a/tox.ini
+++ b/tox.ini
@@ -7,7 +7,7 @@ deps =
codecov>=2.0.5
passenv = CI TRAVIS_BUILD_ID TRAVIS TRAVIS_BRANCH TRAVIS_JOB_NUMBER TRAVIS_PULL_REQUEST TRAVIS_JOB_ID TRAVIS_REPO_SLUG TRAVIS_COMMIT
setenv =
- PY3TESTS = test/netlib test/mitmproxy/script test/pathod/test_utils.py test/pathod/test_log.py test/pathod/test_language_generators.py test/pathod/test_language_writer.py test/pathod/test_language_base.py test/pathod/test_language_http.py test/pathod/test_language_websocket.py test/pathod/test_language_http2.py test/pathod/test_pathoc.py
+ PY3TESTS = test/netlib test/pathod/ test/mitmproxy/script
[testenv:py27]
commands =