aboutsummaryrefslogtreecommitdiffstats
path: root/test/netlib
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2016-07-21 10:38:37 +1200
committerAldo Cortesi <aldo@nullcube.com>2016-07-21 10:38:37 +1200
commit02acfb1242d126e17a295ff8078ef9a73201c7ca (patch)
tree0f5df1008c792407de6b75ab4edb4bd9e04616ad /test/netlib
parentb27db1fc812b5b9935599caf5d0a2cdfe34d7322 (diff)
downloadmitmproxy-02acfb1242d126e17a295ff8078ef9a73201c7ca.tar.gz
mitmproxy-02acfb1242d126e17a295ff8078ef9a73201c7ca.tar.bz2
mitmproxy-02acfb1242d126e17a295ff8078ef9a73201c7ca.zip
Fix netlib.utils.is_valid_host
- Don't crash when passed an empty string. This translated into an actual core crash, discovered while fuzzing with afl. - Taking a slice of length one out of bytes returns an integer, so the check for trailing period in this function never worked on Python3. - Add unit tests.
Diffstat (limited to 'test/netlib')
-rw-r--r--test/netlib/http/http1/test_read.py9
-rw-r--r--test/netlib/test_utils.py7
2 files changed, 16 insertions, 0 deletions
diff --git a/test/netlib/http/http1/test_read.py b/test/netlib/http/http1/test_read.py
index c8a40ecb..44eff2ee 100644
--- a/test/netlib/http/http1/test_read.py
+++ b/test/netlib/http/http1/test_read.py
@@ -13,6 +13,7 @@ from netlib.http.http1.read import (
_read_headers, _read_chunked, get_header_tokens
)
from netlib.tutils import treq, tresp, raises
+from netlib import exceptions
def test_get_header_tokens():
@@ -42,6 +43,14 @@ def test_read_request(input):
assert rfile.read() == b"skip"
+@pytest.mark.parametrize("input", [
+ b"CONNECT :0 0",
+])
+def test_read_request_error(input):
+ rfile = BytesIO(input)
+ raises(exceptions.HttpException, read_request, rfile)
+
+
def test_read_request_head():
rfile = BytesIO(
b"GET / HTTP/1.1\r\n"
diff --git a/test/netlib/test_utils.py b/test/netlib/test_utils.py
index eaa66f13..f6acec03 100644
--- a/test/netlib/test_utils.py
+++ b/test/netlib/test_utils.py
@@ -3,6 +3,13 @@
from netlib import utils, tutils
+def test_is_valid_host():
+ assert not utils.is_valid_host(b"")
+ assert utils.is_valid_host(b"one.two")
+ assert not utils.is_valid_host(b"one"*255)
+ assert utils.is_valid_host(b"one.two.")
+
+
def test_bidi():
b = utils.BiDi(a=1, b=2)
assert b.a == 1