aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2016-07-21 01:16:35 -0700
committerMaximilian Hils <git@maximilianhils.com>2016-07-21 01:16:35 -0700
commit6ffeaaebed0ac248b5ba1f60c6add44eb6e98004 (patch)
tree60900f6ea943125258dfb723b971ffe47726a19d /test
parent8a3a21bba1e6706295cc22e1b3a876a7a86cb705 (diff)
parentc090e02848e0b0b34021ca72f0fc0d39be4de0d0 (diff)
downloadmitmproxy-6ffeaaebed0ac248b5ba1f60c6add44eb6e98004.tar.gz
mitmproxy-6ffeaaebed0ac248b5ba1f60c6add44eb6e98004.tar.bz2
mitmproxy-6ffeaaebed0ac248b5ba1f60c6add44eb6e98004.zip
Merge branch 'master' of https://github.com/mitmproxy/mitmproxy
Diffstat (limited to 'test')
-rw-r--r--test/mitmproxy/test_flow_export.py42
-rw-r--r--test/netlib/http/http1/test_read.py9
-rw-r--r--test/netlib/test_utils.py7
3 files changed, 22 insertions, 36 deletions
diff --git a/test/mitmproxy/test_flow_export.py b/test/mitmproxy/test_flow_export.py
index e6d65e40..86ff937d 100644
--- a/test/mitmproxy/test_flow_export.py
+++ b/test/mitmproxy/test_flow_export.py
@@ -1,4 +1,3 @@
-from textwrap import dedent
import re
import netlib.tutils
@@ -70,41 +69,6 @@ class TestExportPythonCode():
python_equals("data/test_flow_export/python_patch.py", export.python_code(flow))
-class TestRawRequest():
- def test_get(self):
- flow = tutils.tflow(req=req_get())
- result = dedent("""
- GET /path?a=foo&a=bar&b=baz HTTP/1.1\r
- header: qvalue\r
- content-length: 7\r
- host: address:22\r
- \r
- """).strip(" ").lstrip()
- assert export.raw_request(flow) == result
-
- def test_post(self):
- flow = tutils.tflow(req=req_post())
- result = dedent("""
- POST /path HTTP/1.1\r
- host: address:22\r
- \r
- content
- """).strip()
- assert export.raw_request(flow) == result
-
- def test_patch(self):
- flow = tutils.tflow(req=req_patch())
- result = dedent("""
- PATCH /path?query=param HTTP/1.1\r
- header: qvalue\r
- content-length: 7\r
- host: address:22\r
- \r
- content
- """).strip()
- assert export.raw_request(flow) == result
-
-
class TestExportLocustCode():
def test_get(self):
flow = tutils.tflow(req=req_get())
@@ -153,3 +117,9 @@ class TestIsJson():
headers = Headers(content_type="application/json")
j = export.is_json(headers, b'{"name": "example", "email": "example@example.com"}')
assert isinstance(j, dict)
+
+
+class TestURL():
+ def test_url(self):
+ flow = tutils.tflow()
+ assert export.url(flow) == "http://address:22/path"
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..9dcbffd8 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