diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/mitmproxy/addons/test_dumper.py | 10 | ||||
-rw-r--r-- | test/mitmproxy/addons/test_serverplayback.py | 6 | ||||
-rw-r--r-- | test/mitmproxy/addons/test_stickycookie.py | 2 | ||||
-rw-r--r-- | test/mitmproxy/console/test_master.py | 12 | ||||
-rw-r--r-- | test/mitmproxy/mastertest.py | 6 | ||||
-rw-r--r-- | test/mitmproxy/net/__init__.py (renamed from test/netlib/__init__.py) | 0 | ||||
-rw-r--r-- | test/mitmproxy/net/data/clientcert/.gitignore (renamed from test/netlib/data/clientcert/.gitignore) | 0 | ||||
-rw-r--r-- | test/mitmproxy/net/data/clientcert/client.cnf (renamed from test/netlib/data/clientcert/client.cnf) | 0 | ||||
-rw-r--r-- | test/mitmproxy/net/data/clientcert/client.pem (renamed from test/netlib/data/clientcert/client.pem) | 0 | ||||
-rw-r--r-- | test/mitmproxy/net/data/clientcert/make (renamed from test/netlib/data/clientcert/make) | 0 | ||||
-rw-r--r-- | test/mitmproxy/net/data/dercert (renamed from test/netlib/data/dercert) | bin | 1838 -> 1838 bytes | |||
-rw-r--r-- | test/mitmproxy/net/data/dhparam.pem (renamed from test/netlib/data/dhparam.pem) | 0 | ||||
-rw-r--r-- | test/mitmproxy/net/data/htpasswd (renamed from test/netlib/data/htpasswd) | 0 | ||||
-rw-r--r-- | test/mitmproxy/net/data/server.crt (renamed from test/netlib/data/server.crt) | 0 | ||||
-rw-r--r-- | test/mitmproxy/net/data/server.key (renamed from test/netlib/data/server.key) | 0 | ||||
-rw-r--r-- | test/mitmproxy/net/data/text_cert (renamed from test/netlib/data/text_cert) | 0 | ||||
-rw-r--r-- | test/mitmproxy/net/data/text_cert_2 (renamed from test/netlib/data/text_cert_2) | 0 | ||||
-rw-r--r-- | test/mitmproxy/net/data/text_cert_weird1 (renamed from test/netlib/data/text_cert_weird1) | 0 | ||||
-rw-r--r-- | test/mitmproxy/net/data/verificationcerts/9da13359.0 (renamed from test/netlib/data/verificationcerts/9da13359.0) | 0 | ||||
-rw-r--r-- | test/mitmproxy/net/data/verificationcerts/generate.py (renamed from test/netlib/data/verificationcerts/generate.py) | 0 | ||||
-rw-r--r-- | test/mitmproxy/net/data/verificationcerts/self-signed.crt (renamed from test/netlib/data/verificationcerts/self-signed.crt) | 0 | ||||
-rw-r--r-- | test/mitmproxy/net/data/verificationcerts/self-signed.key (renamed from test/netlib/data/verificationcerts/self-signed.key) | 0 | ||||
-rw-r--r-- | test/mitmproxy/net/data/verificationcerts/trusted-leaf.crt (renamed from test/netlib/data/verificationcerts/trusted-leaf.crt) | 0 | ||||
-rw-r--r-- | test/mitmproxy/net/data/verificationcerts/trusted-leaf.key (renamed from test/netlib/data/verificationcerts/trusted-leaf.key) | 0 | ||||
-rw-r--r-- | test/mitmproxy/net/data/verificationcerts/trusted-root.crt (renamed from test/netlib/data/verificationcerts/trusted-root.crt) | 0 | ||||
-rw-r--r-- | test/mitmproxy/net/data/verificationcerts/trusted-root.key (renamed from test/netlib/data/verificationcerts/trusted-root.key) | 0 | ||||
-rw-r--r-- | test/mitmproxy/net/data/verificationcerts/trusted-root.srl (renamed from test/netlib/data/verificationcerts/trusted-root.srl) | 0 | ||||
-rw-r--r-- | test/mitmproxy/net/http/__init__.py (renamed from test/netlib/http/__init__.py) | 0 | ||||
-rw-r--r-- | test/mitmproxy/net/http/http1/__init__.py (renamed from test/netlib/http/http1/__init__.py) | 0 | ||||
-rw-r--r-- | test/mitmproxy/net/http/http1/test_assemble.py (renamed from test/netlib/http/http1/test_assemble.py) | 12 | ||||
-rw-r--r-- | test/mitmproxy/net/http/http1/test_read.py (renamed from test/netlib/http/http1/test_read.py) | 61 | ||||
-rw-r--r-- | test/mitmproxy/net/http/http2/__init__.py (renamed from test/netlib/http/http2/__init__.py) | 0 | ||||
-rw-r--r-- | test/mitmproxy/net/http/http2/test_framereader.py (renamed from test/netlib/http/http2/test_framereader.py) | 0 | ||||
-rw-r--r-- | test/mitmproxy/net/http/test_authentication.py (renamed from test/netlib/http/test_authentication.py) | 4 | ||||
-rw-r--r-- | test/mitmproxy/net/http/test_cookies.py (renamed from test/netlib/http/test_cookies.py) | 4 | ||||
-rw-r--r-- | test/mitmproxy/net/http/test_encoding.py (renamed from test/netlib/test_encoding.py) | 3 | ||||
-rw-r--r-- | test/mitmproxy/net/http/test_headers.py (renamed from test/netlib/http/test_headers.py) | 4 | ||||
-rw-r--r-- | test/mitmproxy/net/http/test_message.py (renamed from test/netlib/http/test_message.py) | 58 | ||||
-rw-r--r-- | test/mitmproxy/net/http/test_multipart.py (renamed from test/netlib/http/test_multipart.py) | 4 | ||||
-rw-r--r-- | test/mitmproxy/net/http/test_request.py (renamed from test/netlib/http/test_request.py) | 4 | ||||
-rw-r--r-- | test/mitmproxy/net/http/test_response.py (renamed from test/netlib/http/test_response.py) | 8 | ||||
-rw-r--r-- | test/mitmproxy/net/http/test_status_codes.py (renamed from test/netlib/http/test_status_codes.py) | 2 | ||||
-rw-r--r-- | test/mitmproxy/net/http/test_url.py (renamed from test/netlib/http/test_url.py) | 4 | ||||
-rw-r--r-- | test/mitmproxy/net/http/test_user_agents.py (renamed from test/netlib/http/test_user_agents.py) | 2 | ||||
-rw-r--r-- | test/mitmproxy/net/test_check.py | 10 | ||||
-rw-r--r-- | test/mitmproxy/net/test_imports.py (renamed from test/netlib/test_imports.py) | 0 | ||||
-rw-r--r-- | test/mitmproxy/net/test_socks.py (renamed from test/netlib/test_socks.py) | 4 | ||||
-rw-r--r-- | test/mitmproxy/net/test_tcp.py (renamed from test/netlib/test_tcp.py) | 53 | ||||
-rw-r--r-- | test/mitmproxy/net/test_wsgi.py (renamed from test/netlib/test_wsgi.py) | 4 | ||||
-rw-r--r-- | test/mitmproxy/net/tools/getcertnames (renamed from test/netlib/tools/getcertnames) | 2 | ||||
-rw-r--r-- | test/mitmproxy/net/tservers.py (renamed from test/netlib/tservers.py) | 4 | ||||
-rw-r--r-- | test/mitmproxy/net/websockets/__init__.py (renamed from test/netlib/websockets/__init__.py) | 0 | ||||
-rw-r--r-- | test/mitmproxy/net/websockets/test_frame.py (renamed from test/netlib/websockets/test_frame.py) | 4 | ||||
-rw-r--r-- | test/mitmproxy/net/websockets/test_masker.py (renamed from test/netlib/websockets/test_masker.py) | 2 | ||||
-rw-r--r-- | test/mitmproxy/net/websockets/test_utils.py (renamed from test/netlib/websockets/test_utils.py) | 4 | ||||
-rw-r--r-- | test/mitmproxy/protocol/test_http1.py | 6 | ||||
-rw-r--r-- | test/mitmproxy/protocol/test_http2.py | 44 | ||||
-rw-r--r-- | test/mitmproxy/protocol/test_websockets.py | 25 | ||||
-rw-r--r-- | test/mitmproxy/test_certs.py (renamed from test/netlib/test_certutils.py) | 41 | ||||
-rw-r--r-- | test/mitmproxy/test_contentview.py | 10 | ||||
-rw-r--r-- | test/mitmproxy/test_controller.py | 2 | ||||
-rw-r--r-- | test/mitmproxy/test_custom_contentview.py | 2 | ||||
-rw-r--r-- | test/mitmproxy/test_examples.py | 11 | ||||
-rw-r--r-- | test/mitmproxy/test_flow.py | 30 | ||||
-rw-r--r-- | test/mitmproxy/test_flow_export.py | 10 | ||||
-rw-r--r-- | test/mitmproxy/test_optmanager.py | 2 | ||||
-rw-r--r-- | test/mitmproxy/test_proxy.py | 6 | ||||
-rw-r--r-- | test/mitmproxy/test_server.py | 51 | ||||
-rw-r--r-- | test/mitmproxy/test_types_bidi.py | 11 | ||||
-rw-r--r-- | test/mitmproxy/test_types_multidict.py (renamed from test/netlib/test_multidict.py) | 10 | ||||
-rw-r--r-- | test/mitmproxy/test_types_serializable.py (renamed from test/netlib/test_basetypes.py) | 4 | ||||
-rw-r--r-- | test/mitmproxy/test_utils_data.py | 7 | ||||
-rw-r--r-- | test/mitmproxy/test_utils_debug.py (renamed from test/netlib/test_debug.py) | 2 | ||||
-rw-r--r-- | test/mitmproxy/test_utils_human.py (renamed from test/netlib/test_human.py) | 3 | ||||
-rw-r--r-- | test/mitmproxy/test_utils_lrucache.py (renamed from test/mitmproxy/test_utils.py) | 12 | ||||
-rw-r--r-- | test/mitmproxy/test_utils_strutils.py (renamed from test/netlib/test_strutils.py) | 3 | ||||
-rw-r--r-- | test/mitmproxy/test_utils_version_check.py (renamed from test/netlib/test_version_check.py) | 2 | ||||
-rw-r--r-- | test/mitmproxy/tservers.py | 7 | ||||
-rw-r--r-- | test/mitmproxy/tutils.py | 12 | ||||
-rw-r--r-- | test/netlib/test_utils.py | 19 | ||||
-rw-r--r-- | test/pathod/test_language_http2.py | 4 | ||||
-rw-r--r-- | test/pathod/test_language_websocket.py | 12 | ||||
-rw-r--r-- | test/pathod/test_log.py | 4 | ||||
-rw-r--r-- | test/pathod/test_pathoc.py | 12 | ||||
-rw-r--r-- | test/pathod/test_pathod.py | 12 | ||||
-rw-r--r-- | test/pathod/test_protocols_http2.py | 32 | ||||
-rw-r--r-- | test/pathod/tutils.py | 9 |
87 files changed, 361 insertions, 349 deletions
diff --git a/test/mitmproxy/addons/test_dumper.py b/test/mitmproxy/addons/test_dumper.py index e49f91bc..5f1b2dbd 100644 --- a/test/mitmproxy/addons/test_dumper.py +++ b/test/mitmproxy/addons/test_dumper.py @@ -7,7 +7,7 @@ from mitmproxy import exceptions from mitmproxy.tools import dump from mitmproxy import http from mitmproxy import proxy -import netlib.tutils +import mitmproxy.test.tutils import mock @@ -38,11 +38,11 @@ class TestDumper(mastertest.MasterTest): sio = io.StringIO() d.configure(dump.Options(tfile = sio, flow_detail = 4), updated) flow = tutils.tflow() - flow.request = netlib.tutils.treq() + flow.request = mitmproxy.test.tutils.treq() flow.request.stickycookie = True flow.client_conn = mock.MagicMock() flow.client_conn.address.host = "foo" - flow.response = netlib.tutils.tresp(content=None) + flow.response = mitmproxy.test.tutils.tresp(content=None) flow.response.is_replay = True flow.response.status_code = 300 d.response(flow) @@ -50,7 +50,7 @@ class TestDumper(mastertest.MasterTest): sio = io.StringIO() d.configure(dump.Options(tfile = sio, flow_detail = 4), updated) - flow = tutils.tflow(resp=netlib.tutils.tresp(content=b"{")) + flow = tutils.tflow(resp=mitmproxy.test.tutils.tresp(content=b"{")) flow.response.headers["content-type"] = "application/json" flow.response.status_code = 400 d.response(flow) @@ -60,7 +60,7 @@ class TestDumper(mastertest.MasterTest): d.configure(dump.Options(tfile = sio), updated) flow = tutils.tflow() flow.request.content = None - flow.response = http.HTTPResponse.wrap(netlib.tutils.tresp()) + flow.response = http.HTTPResponse.wrap(mitmproxy.test.tutils.tresp()) flow.response.content = None d.response(flow) assert "content missing" in sio.getvalue() diff --git a/test/mitmproxy/addons/test_serverplayback.py b/test/mitmproxy/addons/test_serverplayback.py index 649b3c22..c8dd8704 100644 --- a/test/mitmproxy/addons/test_serverplayback.py +++ b/test/mitmproxy/addons/test_serverplayback.py @@ -1,6 +1,6 @@ from .. import tutils, mastertest -import netlib.tutils +import mitmproxy.test.tutils from mitmproxy.addons import serverplayback from mitmproxy import options from mitmproxy import proxy @@ -244,7 +244,7 @@ class TestServerPlayback: m.addons.add(s) f = tutils.tflow() - f.response = netlib.tutils.tresp(content=f.request.content) + f.response = mitmproxy.test.tutils.tresp(content=f.request.content) s.load([f, f]) tf = tutils.tflow() @@ -273,7 +273,7 @@ class TestServerPlayback: m.addons.add(s) f = tutils.tflow() - f.response = netlib.tutils.tresp(content=f.request.content) + f.response = mitmproxy.test.tutils.tresp(content=f.request.content) s.load([f]) f = tutils.tflow() diff --git a/test/mitmproxy/addons/test_stickycookie.py b/test/mitmproxy/addons/test_stickycookie.py index 29c9e198..28c35b28 100644 --- a/test/mitmproxy/addons/test_stickycookie.py +++ b/test/mitmproxy/addons/test_stickycookie.py @@ -3,7 +3,7 @@ from mitmproxy.addons import stickycookie from mitmproxy import master from mitmproxy import options from mitmproxy import proxy -from netlib import tutils as ntutils +from mitmproxy.test import tutils as ntutils def test_domain_match(): diff --git a/test/mitmproxy/console/test_master.py b/test/mitmproxy/console/test_master.py index da29a2b1..6d4bb7f9 100644 --- a/test/mitmproxy/console/test_master.py +++ b/test/mitmproxy/console/test_master.py @@ -1,6 +1,6 @@ import gc -import netlib.tutils +import mitmproxy.test.tutils from mitmproxy.tools import console from mitmproxy import proxy from mitmproxy.tools.console import common @@ -59,13 +59,13 @@ class TestConsoleState: def _add_response(self, state): f = self._add_request(state) - f.response = netlib.tutils.tresp() + f.response = mitmproxy.test.tutils.tresp() state.update_flow(f) def test_add_response(self): c = console.master.ConsoleState() f = self._add_request(c) - f.response = netlib.tutils.tresp() + f.response = mitmproxy.test.tutils.tresp() c.focus = None c.update_flow(f) @@ -127,12 +127,12 @@ class TestMaster(mastertest.MasterTest): def test_intercept(self): """regression test for https://github.com/mitmproxy/mitmproxy/issues/1605""" m = self.mkmaster(intercept="~b bar") - f = tutils.tflow(req=netlib.tutils.treq(content=b"foo")) + f = tutils.tflow(req=mitmproxy.test.tutils.treq(content=b"foo")) m.request(f) assert not m.state.flows[0].intercepted - f = tutils.tflow(req=netlib.tutils.treq(content=b"bar")) + f = tutils.tflow(req=mitmproxy.test.tutils.treq(content=b"bar")) m.request(f) assert m.state.flows[1].intercepted - f = tutils.tflow(resp=netlib.tutils.tresp(content=b"bar")) + f = tutils.tflow(resp=mitmproxy.test.tutils.tresp(content=b"bar")) m.request(f) assert m.state.flows[2].intercepted diff --git a/test/mitmproxy/mastertest.py b/test/mitmproxy/mastertest.py index 0b57c2d4..cdfb5ad5 100644 --- a/test/mitmproxy/mastertest.py +++ b/test/mitmproxy/mastertest.py @@ -1,7 +1,7 @@ import contextlib from . import tutils -import netlib.tutils +import mitmproxy.test.tutils from mitmproxy import master from mitmproxy import io @@ -17,13 +17,13 @@ class TestMaster: class MasterTest: def cycle(self, master, content): - f = tutils.tflow(req=netlib.tutils.treq(content=content)) + f = tutils.tflow(req=mitmproxy.test.tutils.treq(content=content)) master.clientconnect(f.client_conn) master.serverconnect(f.server_conn) master.request(f) if not f.error: f.response = http.HTTPResponse.wrap( - netlib.tutils.tresp(content=content) + mitmproxy.test.tutils.tresp(content=content) ) master.response(f) master.clientdisconnect(f) diff --git a/test/netlib/__init__.py b/test/mitmproxy/net/__init__.py index e69de29b..e69de29b 100644 --- a/test/netlib/__init__.py +++ b/test/mitmproxy/net/__init__.py diff --git a/test/netlib/data/clientcert/.gitignore b/test/mitmproxy/net/data/clientcert/.gitignore index 07bc53d2..07bc53d2 100644 --- a/test/netlib/data/clientcert/.gitignore +++ b/test/mitmproxy/net/data/clientcert/.gitignore diff --git a/test/netlib/data/clientcert/client.cnf b/test/mitmproxy/net/data/clientcert/client.cnf index 5046a944..5046a944 100644 --- a/test/netlib/data/clientcert/client.cnf +++ b/test/mitmproxy/net/data/clientcert/client.cnf diff --git a/test/netlib/data/clientcert/client.pem b/test/mitmproxy/net/data/clientcert/client.pem index 4927bca2..4927bca2 100644 --- a/test/netlib/data/clientcert/client.pem +++ b/test/mitmproxy/net/data/clientcert/client.pem diff --git a/test/netlib/data/clientcert/make b/test/mitmproxy/net/data/clientcert/make index d1caea81..d1caea81 100644 --- a/test/netlib/data/clientcert/make +++ b/test/mitmproxy/net/data/clientcert/make diff --git a/test/netlib/data/dercert b/test/mitmproxy/net/data/dercert Binary files differindex 370252af..370252af 100644 --- a/test/netlib/data/dercert +++ b/test/mitmproxy/net/data/dercert diff --git a/test/netlib/data/dhparam.pem b/test/mitmproxy/net/data/dhparam.pem index afb41672..afb41672 100644 --- a/test/netlib/data/dhparam.pem +++ b/test/mitmproxy/net/data/dhparam.pem diff --git a/test/netlib/data/htpasswd b/test/mitmproxy/net/data/htpasswd index 54c95b8c..54c95b8c 100644 --- a/test/netlib/data/htpasswd +++ b/test/mitmproxy/net/data/htpasswd diff --git a/test/netlib/data/server.crt b/test/mitmproxy/net/data/server.crt index 68f61bac..68f61bac 100644 --- a/test/netlib/data/server.crt +++ b/test/mitmproxy/net/data/server.crt diff --git a/test/netlib/data/server.key b/test/mitmproxy/net/data/server.key index b1b658ab..b1b658ab 100644 --- a/test/netlib/data/server.key +++ b/test/mitmproxy/net/data/server.key diff --git a/test/netlib/data/text_cert b/test/mitmproxy/net/data/text_cert index 36ca33b9..36ca33b9 100644 --- a/test/netlib/data/text_cert +++ b/test/mitmproxy/net/data/text_cert diff --git a/test/netlib/data/text_cert_2 b/test/mitmproxy/net/data/text_cert_2 index ffe8faae..ffe8faae 100644 --- a/test/netlib/data/text_cert_2 +++ b/test/mitmproxy/net/data/text_cert_2 diff --git a/test/netlib/data/text_cert_weird1 b/test/mitmproxy/net/data/text_cert_weird1 index 72b09dcb..72b09dcb 100644 --- a/test/netlib/data/text_cert_weird1 +++ b/test/mitmproxy/net/data/text_cert_weird1 diff --git a/test/netlib/data/verificationcerts/9da13359.0 b/test/mitmproxy/net/data/verificationcerts/9da13359.0 index b22e4d20..b22e4d20 100644 --- a/test/netlib/data/verificationcerts/9da13359.0 +++ b/test/mitmproxy/net/data/verificationcerts/9da13359.0 diff --git a/test/netlib/data/verificationcerts/generate.py b/test/mitmproxy/net/data/verificationcerts/generate.py index 6d4d8550..6d4d8550 100644 --- a/test/netlib/data/verificationcerts/generate.py +++ b/test/mitmproxy/net/data/verificationcerts/generate.py diff --git a/test/netlib/data/verificationcerts/self-signed.crt b/test/mitmproxy/net/data/verificationcerts/self-signed.crt index dce2a7e0..dce2a7e0 100644 --- a/test/netlib/data/verificationcerts/self-signed.crt +++ b/test/mitmproxy/net/data/verificationcerts/self-signed.crt diff --git a/test/netlib/data/verificationcerts/self-signed.key b/test/mitmproxy/net/data/verificationcerts/self-signed.key index 71a6ad6a..71a6ad6a 100644 --- a/test/netlib/data/verificationcerts/self-signed.key +++ b/test/mitmproxy/net/data/verificationcerts/self-signed.key diff --git a/test/netlib/data/verificationcerts/trusted-leaf.crt b/test/mitmproxy/net/data/verificationcerts/trusted-leaf.crt index 6a92de92..6a92de92 100644 --- a/test/netlib/data/verificationcerts/trusted-leaf.crt +++ b/test/mitmproxy/net/data/verificationcerts/trusted-leaf.crt diff --git a/test/netlib/data/verificationcerts/trusted-leaf.key b/test/mitmproxy/net/data/verificationcerts/trusted-leaf.key index 783ebf1c..783ebf1c 100644 --- a/test/netlib/data/verificationcerts/trusted-leaf.key +++ b/test/mitmproxy/net/data/verificationcerts/trusted-leaf.key diff --git a/test/netlib/data/verificationcerts/trusted-root.crt b/test/mitmproxy/net/data/verificationcerts/trusted-root.crt index b22e4d20..b22e4d20 100644 --- a/test/netlib/data/verificationcerts/trusted-root.crt +++ b/test/mitmproxy/net/data/verificationcerts/trusted-root.crt diff --git a/test/netlib/data/verificationcerts/trusted-root.key b/test/mitmproxy/net/data/verificationcerts/trusted-root.key index 05483f77..05483f77 100644 --- a/test/netlib/data/verificationcerts/trusted-root.key +++ b/test/mitmproxy/net/data/verificationcerts/trusted-root.key diff --git a/test/netlib/data/verificationcerts/trusted-root.srl b/test/mitmproxy/net/data/verificationcerts/trusted-root.srl index 4ad962ba..4ad962ba 100644 --- a/test/netlib/data/verificationcerts/trusted-root.srl +++ b/test/mitmproxy/net/data/verificationcerts/trusted-root.srl diff --git a/test/netlib/http/__init__.py b/test/mitmproxy/net/http/__init__.py index e69de29b..e69de29b 100644 --- a/test/netlib/http/__init__.py +++ b/test/mitmproxy/net/http/__init__.py diff --git a/test/netlib/http/http1/__init__.py b/test/mitmproxy/net/http/http1/__init__.py index e69de29b..e69de29b 100644 --- a/test/netlib/http/http1/__init__.py +++ b/test/mitmproxy/net/http/http1/__init__.py diff --git a/test/netlib/http/http1/test_assemble.py b/test/mitmproxy/net/http/http1/test_assemble.py index 5d7e007e..e80376e8 100644 --- a/test/netlib/http/http1/test_assemble.py +++ b/test/mitmproxy/net/http/http1/test_assemble.py @@ -1,11 +1,11 @@ -from netlib.exceptions import HttpException -from netlib.http import Headers -from netlib.http.http1.assemble import ( +from mitmproxy import exceptions +from mitmproxy.net.http import Headers +from mitmproxy.net.http.http1.assemble import ( assemble_request, assemble_request_head, assemble_response, assemble_response_head, _assemble_request_line, _assemble_request_headers, _assemble_response_headers, assemble_body) -from netlib.tutils import treq, raises, tresp +from mitmproxy.test.tutils import treq, raises, tresp def test_assemble_request(): @@ -18,7 +18,7 @@ def test_assemble_request(): b"content" ) - with raises(HttpException): + with raises(exceptions.HttpException): assemble_request(treq(content=None)) @@ -39,7 +39,7 @@ def test_assemble_response(): b"message" ) - with raises(HttpException): + with raises(exceptions.HttpException): assemble_response(tresp(content=None)) diff --git a/test/netlib/http/http1/test_read.py b/test/mitmproxy/net/http/http1/test_read.py index f25cd3e2..20997259 100644 --- a/test/netlib/http/http1/test_read.py +++ b/test/mitmproxy/net/http/http1/test_read.py @@ -2,16 +2,15 @@ from io import BytesIO from mock import Mock import pytest -from netlib.exceptions import HttpException, HttpSyntaxException, HttpReadDisconnect, TcpDisconnect -from netlib.http import Headers -from netlib.http.http1.read import ( +from mitmproxy import exceptions +from mitmproxy.net.http import Headers +from mitmproxy.net.http.http1.read import ( read_request, read_response, read_request_head, read_response_head, read_body, connection_close, expected_http_body_size, _get_first_line, _read_request_line, _parse_authority_form, _read_response_line, _check_http_version, _read_headers, _read_chunked, get_header_tokens ) -from netlib.tutils import treq, tresp, raises -from netlib import exceptions +from mitmproxy.test.tutils import treq, tresp, raises def test_get_header_tokens(): @@ -117,12 +116,12 @@ class TestReadBody: def test_known_size_limit(self): rfile = BytesIO(b"foobar") - with raises(HttpException): + with raises(exceptions.HttpException): b"".join(read_body(rfile, 3, 2)) def test_known_size_too_short(self): rfile = BytesIO(b"foo") - with raises(HttpException): + with raises(exceptions.HttpException): b"".join(read_body(rfile, 6)) def test_unknown_size(self): @@ -132,7 +131,7 @@ class TestReadBody: def test_unknown_size_limit(self): rfile = BytesIO(b"foobar") - with raises(HttpException): + with raises(exceptions.HttpException): b"".join(read_body(rfile, -1, 3)) def test_max_chunk_size(self): @@ -186,7 +185,7 @@ def test_expected_http_body_size(): # explicit length for val in (b"foo", b"-7"): - with raises(HttpSyntaxException): + with raises(exceptions.HttpSyntaxException): expected_http_body_size( treq(headers=Headers(content_length=val)) ) @@ -210,13 +209,13 @@ def test_get_first_line(): rfile = BytesIO(b"\r\nfoo\r\nbar") assert _get_first_line(rfile) == b"foo" - with raises(HttpReadDisconnect): + with raises(exceptions.HttpReadDisconnect): rfile = BytesIO(b"") _get_first_line(rfile) - with raises(HttpReadDisconnect): + with raises(exceptions.HttpReadDisconnect): rfile = Mock() - rfile.readline.side_effect = TcpDisconnect + rfile.readline.side_effect = exceptions.TcpDisconnect _get_first_line(rfile) @@ -233,23 +232,23 @@ def test_read_request_line(): assert (t(b"GET http://foo:42/bar HTTP/1.1") == ("absolute", b"GET", b"http", b"foo", 42, b"/bar", b"HTTP/1.1")) - with raises(HttpSyntaxException): + with raises(exceptions.HttpSyntaxException): t(b"GET / WTF/1.1") - with raises(HttpSyntaxException): + with raises(exceptions.HttpSyntaxException): t(b"this is not http") - with raises(HttpReadDisconnect): + with raises(exceptions.HttpReadDisconnect): t(b"") def test_parse_authority_form(): assert _parse_authority_form(b"foo:42") == (b"foo", 42) - with raises(HttpSyntaxException): + with raises(exceptions.HttpSyntaxException): _parse_authority_form(b"foo") - with raises(HttpSyntaxException): + with raises(exceptions.HttpSyntaxException): _parse_authority_form(b"foo:bar") - with raises(HttpSyntaxException): + with raises(exceptions.HttpSyntaxException): _parse_authority_form(b"foo:99999999") - with raises(HttpSyntaxException): + with raises(exceptions.HttpSyntaxException): _parse_authority_form(b"f\x00oo:80") @@ -263,14 +262,14 @@ def test_read_response_line(): # https://github.com/mitmproxy/mitmproxy/issues/784 assert t(b"HTTP/1.1 200 Non-Autoris\xc3\xa9") == (b"HTTP/1.1", 200, b"Non-Autoris\xc3\xa9") - with raises(HttpSyntaxException): + with raises(exceptions.HttpSyntaxException): assert t(b"HTTP/1.1") - with raises(HttpSyntaxException): + with raises(exceptions.HttpSyntaxException): t(b"HTTP/1.1 OK OK") - with raises(HttpSyntaxException): + with raises(exceptions.HttpSyntaxException): t(b"WTF/1.1 200 OK") - with raises(HttpReadDisconnect): + with raises(exceptions.HttpReadDisconnect): t(b"") @@ -279,11 +278,11 @@ def test_check_http_version(): _check_http_version(b"HTTP/1.0") _check_http_version(b"HTTP/1.1") _check_http_version(b"HTTP/2.0") - with raises(HttpSyntaxException): + with raises(exceptions.HttpSyntaxException): _check_http_version(b"WTF/1.0") - with raises(HttpSyntaxException): + with raises(exceptions.HttpSyntaxException): _check_http_version(b"HTTP/1.10") - with raises(HttpSyntaxException): + with raises(exceptions.HttpSyntaxException): _check_http_version(b"HTTP/1.b") @@ -322,17 +321,17 @@ class TestReadHeaders: def test_read_continued_err(self): data = b"\tfoo: bar\r\n" - with raises(HttpSyntaxException): + with raises(exceptions.HttpSyntaxException): self._read(data) def test_read_err(self): data = b"foo" - with raises(HttpSyntaxException): + with raises(exceptions.HttpSyntaxException): self._read(data) def test_read_empty_name(self): data = b":foo" - with raises(HttpSyntaxException): + with raises(exceptions.HttpSyntaxException): self._read(data) def test_read_empty_value(self): @@ -346,7 +345,7 @@ def test_read_chunked(): req.headers["Transfer-Encoding"] = "chunked" data = b"1\r\na\r\n0\r\n" - with raises(HttpSyntaxException): + with raises(exceptions.HttpSyntaxException): b"".join(_read_chunked(BytesIO(data))) data = b"1\r\na\r\n0\r\n\r\n" @@ -364,7 +363,7 @@ def test_read_chunked(): b"".join(_read_chunked(BytesIO(data))) data = b"foo\r\nfoo" - with raises(HttpSyntaxException): + with raises(exceptions.HttpSyntaxException): b"".join(_read_chunked(BytesIO(data))) data = b"5\r\naaaaa\r\n0\r\n\r\n" diff --git a/test/netlib/http/http2/__init__.py b/test/mitmproxy/net/http/http2/__init__.py index e69de29b..e69de29b 100644 --- a/test/netlib/http/http2/__init__.py +++ b/test/mitmproxy/net/http/http2/__init__.py diff --git a/test/netlib/http/http2/test_framereader.py b/test/mitmproxy/net/http/http2/test_framereader.py index 41b73189..41b73189 100644 --- a/test/netlib/http/http2/test_framereader.py +++ b/test/mitmproxy/net/http/http2/test_framereader.py diff --git a/test/netlib/http/test_authentication.py b/test/mitmproxy/net/http/test_authentication.py index 95d72447..11b6e2e0 100644 --- a/test/netlib/http/test_authentication.py +++ b/test/mitmproxy/net/http/test_authentication.py @@ -1,7 +1,7 @@ import binascii -from netlib import tutils -from netlib.http import authentication, Headers +from mitmproxy.test import tutils +from mitmproxy.net.http import authentication, Headers def test_parse_http_basic_auth(): diff --git a/test/netlib/http/test_cookies.py b/test/mitmproxy/net/http/test_cookies.py index 80ffb0a6..8c9c0c32 100644 --- a/test/netlib/http/test_cookies.py +++ b/test/mitmproxy/net/http/test_cookies.py @@ -1,7 +1,7 @@ import time -from netlib.http import cookies -from netlib.tutils import raises +from mitmproxy.net.http import cookies +from mitmproxy.test.tutils import raises import mock diff --git a/test/netlib/test_encoding.py b/test/mitmproxy/net/http/test_encoding.py index e1175ef0..d8fa5e76 100644 --- a/test/netlib/test_encoding.py +++ b/test/mitmproxy/net/http/test_encoding.py @@ -1,7 +1,8 @@ import mock import pytest -from netlib import encoding, tutils +from mitmproxy.net.http import encoding +from mitmproxy.test import tutils @pytest.mark.parametrize("encoder", [ diff --git a/test/netlib/http/test_headers.py b/test/mitmproxy/net/http/test_headers.py index 63f16897..8e0f770d 100644 --- a/test/netlib/http/test_headers.py +++ b/test/mitmproxy/net/http/test_headers.py @@ -1,7 +1,7 @@ import collections -from netlib.http.headers import Headers, parse_content_type, assemble_content_type -from netlib.tutils import raises +from mitmproxy.net.http.headers import Headers, parse_content_type, assemble_content_type +from mitmproxy.test.tutils import raises class TestHeaders: diff --git a/test/netlib/http/test_message.py b/test/mitmproxy/net/http/test_message.py index 8374f8f6..69d029d9 100644 --- a/test/netlib/http/test_message.py +++ b/test/mitmproxy/net/http/test_message.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- -from netlib.tutils import tresp -from netlib import http, tutils +from mitmproxy.test import tutils +from mitmproxy.net import http def _test_passthrough_attr(message, attr): @@ -37,12 +37,12 @@ def _test_decoded_attr(message, attr): class TestMessageData: def test_eq_ne(self): - data = tresp(timestamp_start=42, timestamp_end=42).data - same = tresp(timestamp_start=42, timestamp_end=42).data + data = tutils.tresp(timestamp_start=42, timestamp_end=42).data + same = tutils.tresp(timestamp_start=42, timestamp_end=42).data assert data == same assert not data != same - other = tresp(content=b"foo").data + other = tutils.tresp(content=b"foo").data assert not data == other assert data != other @@ -52,28 +52,28 @@ class TestMessageData: class TestMessage: def test_init(self): - resp = tresp() + resp = tutils.tresp() assert resp.data def test_eq_ne(self): - resp = tresp(timestamp_start=42, timestamp_end=42) - same = tresp(timestamp_start=42, timestamp_end=42) + resp = tutils.tresp(timestamp_start=42, timestamp_end=42) + same = tutils.tresp(timestamp_start=42, timestamp_end=42) assert resp == same assert not resp != same - other = tresp(timestamp_start=0, timestamp_end=0) + other = tutils.tresp(timestamp_start=0, timestamp_end=0) assert not resp == other assert resp != other assert resp != 0 def test_serializable(self): - resp = tresp() + resp = tutils.tresp() resp2 = http.Response.from_state(resp.get_state()) assert resp == resp2 def test_content_length_update(self): - resp = tresp() + resp = tutils.tresp() resp.content = b"foo" assert resp.data.content == b"foo" assert resp.headers["content-length"] == "3" @@ -85,19 +85,19 @@ class TestMessage: assert resp.headers["content-length"] == "0" def test_headers(self): - _test_passthrough_attr(tresp(), "headers") + _test_passthrough_attr(tutils.tresp(), "headers") def test_timestamp_start(self): - _test_passthrough_attr(tresp(), "timestamp_start") + _test_passthrough_attr(tutils.tresp(), "timestamp_start") def test_timestamp_end(self): - _test_passthrough_attr(tresp(), "timestamp_end") + _test_passthrough_attr(tutils.tresp(), "timestamp_end") def test_http_version(self): - _test_decoded_attr(tresp(), "http_version") + _test_decoded_attr(tutils.tresp(), "http_version") def test_replace(self): - r = tresp() + r = tutils.tresp() r.content = b"foofootoo" r.replace(b"foo", "gg") assert r.content == b"ggggtoo" @@ -109,7 +109,7 @@ class TestMessage: class TestMessageContentEncoding: def test_simple(self): - r = tresp() + r = tutils.tresp() assert r.raw_content == b"message" assert "content-encoding" not in r.headers r.encode("gzip") @@ -120,7 +120,7 @@ class TestMessageContentEncoding: assert r.raw_content != b"message" def test_modify(self): - r = tresp() + r = tutils.tresp() assert "content-encoding" not in r.headers r.encode("gzip") @@ -133,7 +133,7 @@ class TestMessageContentEncoding: r.content = u"foo" def test_unknown_ce(self): - r = tresp() + r = tutils.tresp() r.headers["content-encoding"] = "zopfli" r.raw_content = b"foo" with tutils.raises(ValueError): @@ -142,7 +142,7 @@ class TestMessageContentEncoding: assert r.get_content(strict=False) == b"foo" def test_cannot_decode(self): - r = tresp() + r = tutils.tresp() r.encode("gzip") r.raw_content = b"foo" with tutils.raises(ValueError): @@ -160,7 +160,7 @@ class TestMessageContentEncoding: assert "content-encoding" not in r.headers def test_none(self): - r = tresp(content=None) + r = tutils.tresp(content=None) assert r.content is None r.content = b"foo" assert r.content is not None @@ -168,7 +168,7 @@ class TestMessageContentEncoding: assert r.content is None def test_cannot_encode(self): - r = tresp() + r = tutils.tresp() r.encode("gzip") r.content = None assert r.headers["content-encoding"] @@ -187,7 +187,7 @@ class TestMessageContentEncoding: class TestMessageText: def test_simple(self): - r = tresp(content=b'\xfc') + r = tutils.tresp(content=b'\xfc') assert r.raw_content == b"\xfc" assert r.content == b"\xfc" assert r.text == u"ü" @@ -204,12 +204,12 @@ class TestMessageText: assert r.text == u"ü" def test_guess_json(self): - r = tresp(content=b'"\xc3\xbc"') + r = tutils.tresp(content=b'"\xc3\xbc"') r.headers["content-type"] = "application/json" assert r.text == u'"ü"' def test_none(self): - r = tresp(content=None) + r = tutils.tresp(content=None) assert r.text is None r.text = u"foo" assert r.text is not None @@ -217,7 +217,7 @@ class TestMessageText: assert r.text is None def test_modify(self): - r = tresp() + r = tutils.tresp() r.text = u"ü" assert r.raw_content == b"\xfc" @@ -228,7 +228,7 @@ class TestMessageText: assert r.headers["content-length"] == "2" def test_unknown_ce(self): - r = tresp() + r = tutils.tresp() r.headers["content-type"] = "text/html; charset=wtf" r.raw_content = b"foo" with tutils.raises(ValueError): @@ -236,7 +236,7 @@ class TestMessageText: assert r.get_text(strict=False) == u"foo" def test_cannot_decode(self): - r = tresp() + r = tutils.tresp() r.headers["content-type"] = "text/html; charset=utf8" r.raw_content = b"\xFF" with tutils.raises(ValueError): @@ -245,7 +245,7 @@ class TestMessageText: assert r.get_text(strict=False) == '\udcff' def test_cannot_encode(self): - r = tresp() + r = tutils.tresp() r.content = None assert "content-type" not in r.headers assert r.raw_content is None diff --git a/test/netlib/http/test_multipart.py b/test/mitmproxy/net/http/test_multipart.py index 1d7e0062..68ae6bbd 100644 --- a/test/netlib/http/test_multipart.py +++ b/test/mitmproxy/net/http/test_multipart.py @@ -1,5 +1,5 @@ -from netlib.http import Headers -from netlib.http import multipart +from mitmproxy.net.http import Headers +from mitmproxy.net.http import multipart def test_decode(): diff --git a/test/netlib/http/test_request.py b/test/mitmproxy/net/http/test_request.py index 336dc86d..9c0ec333 100644 --- a/test/netlib/http/test_request.py +++ b/test/mitmproxy/net/http/test_request.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- -from netlib.http import Headers -from netlib.tutils import treq, raises +from mitmproxy.net.http import Headers +from mitmproxy.test.tutils import treq, raises from .test_message import _test_decoded_attr, _test_passthrough_attr diff --git a/test/netlib/http/test_response.py b/test/mitmproxy/net/http/test_response.py index 725f2b33..239fb6ef 100644 --- a/test/netlib/http/test_response.py +++ b/test/mitmproxy/net/http/test_response.py @@ -2,10 +2,10 @@ import email import time -from netlib.http import Headers -from netlib.http import Response -from netlib.http.cookies import CookieAttrs -from netlib.tutils import raises, tresp +from mitmproxy.net.http import Headers +from mitmproxy.net.http import Response +from mitmproxy.net.http.cookies import CookieAttrs +from mitmproxy.test.tutils import raises, tresp from .test_message import _test_passthrough_attr, _test_decoded_attr diff --git a/test/netlib/http/test_status_codes.py b/test/mitmproxy/net/http/test_status_codes.py index 9fea6b70..098f8eef 100644 --- a/test/netlib/http/test_status_codes.py +++ b/test/mitmproxy/net/http/test_status_codes.py @@ -1,4 +1,4 @@ -from netlib.http import status_codes +from mitmproxy.net.http import status_codes def test_simple(): diff --git a/test/netlib/http/test_url.py b/test/mitmproxy/net/http/test_url.py index 631ed8a9..94b2eacc 100644 --- a/test/netlib/http/test_url.py +++ b/test/mitmproxy/net/http/test_url.py @@ -1,5 +1,5 @@ -from netlib import tutils -from netlib.http import url +from mitmproxy.test import tutils +from mitmproxy.net.http import url def test_parse(): diff --git a/test/netlib/http/test_user_agents.py b/test/mitmproxy/net/http/test_user_agents.py index 0bf1bba7..9e391447 100644 --- a/test/netlib/http/test_user_agents.py +++ b/test/mitmproxy/net/http/test_user_agents.py @@ -1,4 +1,4 @@ -from netlib.http import user_agents +from mitmproxy.net.http import user_agents def test_get_shortcut(): diff --git a/test/mitmproxy/net/test_check.py b/test/mitmproxy/net/test_check.py new file mode 100644 index 00000000..18a50157 --- /dev/null +++ b/test/mitmproxy/net/test_check.py @@ -0,0 +1,10 @@ +# coding=utf-8 + +from mitmproxy.net import check + + +def test_is_valid_host(): + assert not check.is_valid_host(b"") + assert check.is_valid_host(b"one.two") + assert not check.is_valid_host(b"one" * 255) + assert check.is_valid_host(b"one.two.") diff --git a/test/netlib/test_imports.py b/test/mitmproxy/net/test_imports.py index b88ef26d..b88ef26d 100644 --- a/test/netlib/test_imports.py +++ b/test/mitmproxy/net/test_imports.py diff --git a/test/netlib/test_socks.py b/test/mitmproxy/net/test_socks.py index 17e08054..b6551faa 100644 --- a/test/netlib/test_socks.py +++ b/test/mitmproxy/net/test_socks.py @@ -1,6 +1,8 @@ import ipaddress from io import BytesIO -from netlib import socks, tcp, tutils +from mitmproxy.net import socks +from mitmproxy.net import tcp +from mitmproxy.test import tutils def test_client_greeting(): diff --git a/test/netlib/test_tcp.py b/test/mitmproxy/net/test_tcp.py index 797a5a04..8a7c692a 100644 --- a/test/netlib/test_tcp.py +++ b/test/mitmproxy/net/test_tcp.py @@ -9,9 +9,10 @@ import mock from OpenSSL import SSL -from netlib import tcp, certutils, tutils -from netlib.exceptions import InvalidCertificateException, TcpReadIncomplete, TlsException, \ - TcpTimeout, TcpDisconnect, TcpException, NetlibException +from mitmproxy import certs +from mitmproxy.net import tcp +from mitmproxy.test import tutils +from mitmproxy import exceptions from . import tservers @@ -108,7 +109,7 @@ class TestServerBind(tservers.ServerTestBase): with c.connect(): assert c.rfile.readline() == str(("127.0.0.1", random_port)).encode() return - except TcpException: # port probably already in use + except exceptions.TcpException: # port probably already in use pass @@ -155,7 +156,7 @@ class TestFinishFail(tservers.ServerTestBase): c = tcp.TCPClient(("127.0.0.1", self.port)) with c.connect(): c.wfile.write(b"foo\n") - c.wfile.flush = mock.Mock(side_effect=TcpDisconnect) + c.wfile.flush = mock.Mock(side_effect=exceptions.TcpDisconnect) c.finish() @@ -195,7 +196,7 @@ class TestSSLv3Only(tservers.ServerTestBase): def test_failure(self): c = tcp.TCPClient(("127.0.0.1", self.port)) with c.connect(): - tutils.raises(TlsException, c.convert_to_ssl, sni="foo.com") + tutils.raises(exceptions.TlsException, c.convert_to_ssl, sni="foo.com") class TestSSLUpstreamCertVerificationWBadServerCert(tservers.ServerTestBase): @@ -236,7 +237,7 @@ class TestSSLUpstreamCertVerificationWBadServerCert(tservers.ServerTestBase): def test_mode_strict_should_fail(self): c = tcp.TCPClient(("127.0.0.1", self.port)) with c.connect(): - with tutils.raises(InvalidCertificateException): + with tutils.raises(exceptions.InvalidCertificateException): c.convert_to_ssl( sni="example.mitmproxy.org", verify_options=SSL.VERIFY_PEER, @@ -261,7 +262,7 @@ class TestSSLUpstreamCertVerificationWBadHostname(tservers.ServerTestBase): def test_should_fail_without_sni(self): c = tcp.TCPClient(("127.0.0.1", self.port)) with c.connect(): - with tutils.raises(TlsException): + with tutils.raises(exceptions.TlsException): c.convert_to_ssl( verify_options=SSL.VERIFY_PEER, ca_pemfile=tutils.test_data.path("data/verificationcerts/trusted-root.crt") @@ -270,7 +271,7 @@ class TestSSLUpstreamCertVerificationWBadHostname(tservers.ServerTestBase): def test_should_fail(self): c = tcp.TCPClient(("127.0.0.1", self.port)) with c.connect(): - with tutils.raises(InvalidCertificateException): + with tutils.raises(exceptions.InvalidCertificateException): c.convert_to_ssl( sni="mitmproxy.org", verify_options=SSL.VERIFY_PEER, @@ -348,7 +349,7 @@ class TestSSLClientCert(tservers.ServerTestBase): c = tcp.TCPClient(("127.0.0.1", self.port)) with c.connect(): tutils.raises( - TlsException, + exceptions.TlsException, c.convert_to_ssl, cert=tutils.test_data.path("data/clientcert/make") ) @@ -454,7 +455,7 @@ class TestSSLDisconnect(tservers.ServerTestBase): # Excercise SSL.ZeroReturnError c.rfile.read(10) c.close() - tutils.raises(TcpDisconnect, c.wfile.write, b"foo") + tutils.raises(exceptions.TcpDisconnect, c.wfile.write, b"foo") tutils.raises(queue.Empty, self.q.get_nowait) @@ -469,7 +470,7 @@ class TestSSLHardDisconnect(tservers.ServerTestBase): # Exercise SSL.SysCallError c.rfile.read(10) c.close() - tutils.raises(TcpDisconnect, c.wfile.write, b"foo") + tutils.raises(exceptions.TcpDisconnect, c.wfile.write, b"foo") class TestDisconnect(tservers.ServerTestBase): @@ -492,7 +493,7 @@ class TestServerTimeOut(tservers.ServerTestBase): self.settimeout(0.01) try: self.rfile.read(10) - except TcpTimeout: + except exceptions.TcpTimeout: self.timeout = True def test_timeout(self): @@ -510,7 +511,7 @@ class TestTimeOut(tservers.ServerTestBase): with c.connect(): c.settimeout(0.1) assert c.gettimeout() == 0.1 - tutils.raises(TcpTimeout, c.rfile.read, 10) + tutils.raises(exceptions.TcpTimeout, c.rfile.read, 10) class TestALPNClient(tservers.ServerTestBase): @@ -562,13 +563,13 @@ class TestSSLTimeOut(tservers.ServerTestBase): with c.connect(): c.convert_to_ssl() c.settimeout(0.1) - tutils.raises(TcpTimeout, c.rfile.read, 10) + tutils.raises(exceptions.TcpTimeout, c.rfile.read, 10) class TestDHParams(tservers.ServerTestBase): handler = HangHandler ssl = dict( - dhparams=certutils.CertStore.load_dhparam( + dhparams=certs.CertStore.load_dhparam( tutils.test_data.path("data/dhparam.pem"), ), cipher_list="DHE-RSA-AES256-SHA" @@ -584,7 +585,7 @@ class TestDHParams(tservers.ServerTestBase): def test_create_dhparams(self): with tutils.tmpdir() as d: filename = os.path.join(d, "dhparam.pem") - certutils.CertStore.load_dhparam(filename) + certs.CertStore.load_dhparam(filename) assert os.path.exists(filename) @@ -592,7 +593,7 @@ class TestTCPClient: def test_conerr(self): c = tcp.TCPClient(("127.0.0.1", 0)) - tutils.raises(TcpException, c.connect) + tutils.raises(exceptions.TcpException, c.connect) class TestFileLike: @@ -661,7 +662,7 @@ class TestFileLike: o = mock.MagicMock() o.flush = mock.MagicMock(side_effect=socket.error) s.o = o - tutils.raises(TcpDisconnect, s.flush) + tutils.raises(exceptions.TcpDisconnect, s.flush) def test_reader_read_error(self): s = BytesIO(b"foobar\nfoobar") @@ -669,7 +670,7 @@ class TestFileLike: o = mock.MagicMock() o.read = mock.MagicMock(side_effect=socket.error) s.o = o - tutils.raises(TcpDisconnect, s.read, 10) + tutils.raises(exceptions.TcpDisconnect, s.read, 10) def test_reset_timestamps(self): s = BytesIO(b"foobar\nfoobar") @@ -700,24 +701,24 @@ class TestFileLike: s = mock.MagicMock() s.read = mock.MagicMock(side_effect=SSL.Error()) s = tcp.Reader(s) - tutils.raises(TlsException, s.read, 1) + tutils.raises(exceptions.TlsException, s.read, 1) def test_read_syscall_ssl_error(self): s = mock.MagicMock() s.read = mock.MagicMock(side_effect=SSL.SysCallError()) s = tcp.Reader(s) - tutils.raises(TlsException, s.read, 1) + tutils.raises(exceptions.TlsException, s.read, 1) def test_reader_readline_disconnect(self): o = mock.MagicMock() o.read = mock.MagicMock(side_effect=socket.error) s = tcp.Reader(o) - tutils.raises(TcpDisconnect, s.readline, 10) + tutils.raises(exceptions.TcpDisconnect, s.readline, 10) def test_reader_incomplete_error(self): s = BytesIO(b"foobar") s = tcp.Reader(s) - tutils.raises(TcpReadIncomplete, s.safe_read, 10) + tutils.raises(exceptions.TcpReadIncomplete, s.safe_read, 10) class TestPeek(tservers.ServerTestBase): @@ -738,11 +739,11 @@ class TestPeek(tservers.ServerTestBase): assert c.rfile.readline() == testval c.close() - with tutils.raises(NetlibException): + with tutils.raises(exceptions.NetlibException): if c.rfile.peek(1) == b"": # Workaround for Python 2 on Unix: # Peeking a closed connection does not raise an exception here. - raise NetlibException() + raise exceptions.NetlibException() class TestPeekSSL(TestPeek): diff --git a/test/netlib/test_wsgi.py b/test/mitmproxy/net/test_wsgi.py index 5c61f81c..b4d6b53f 100644 --- a/test/netlib/test_wsgi.py +++ b/test/mitmproxy/net/test_wsgi.py @@ -1,7 +1,7 @@ from io import BytesIO import sys -from netlib import wsgi -from netlib.http import Headers +from mitmproxy.net import wsgi +from mitmproxy.net.http import Headers def tflow(): diff --git a/test/netlib/tools/getcertnames b/test/mitmproxy/net/tools/getcertnames index 0882fccd..d64e5ff5 100644 --- a/test/netlib/tools/getcertnames +++ b/test/mitmproxy/net/tools/getcertnames @@ -1,7 +1,7 @@ #!/usr/bin/env python import sys sys.path.insert(0, "../../") -from netlib import tcp +from mitmproxy.net import tcp def get_remote_cert(host, port, sni): diff --git a/test/netlib/tservers.py b/test/mitmproxy/net/tservers.py index b344e25c..ba10ef5e 100644 --- a/test/netlib/tservers.py +++ b/test/mitmproxy/net/tservers.py @@ -3,8 +3,8 @@ import queue import io import OpenSSL -from netlib import tcp -from netlib import tutils +from mitmproxy.net import tcp +from mitmproxy.test import tutils class _ServerThread(threading.Thread): diff --git a/test/netlib/websockets/__init__.py b/test/mitmproxy/net/websockets/__init__.py index e69de29b..e69de29b 100644 --- a/test/netlib/websockets/__init__.py +++ b/test/mitmproxy/net/websockets/__init__.py diff --git a/test/netlib/websockets/test_frame.py b/test/mitmproxy/net/websockets/test_frame.py index a039dcb1..198be3d5 100644 --- a/test/netlib/websockets/test_frame.py +++ b/test/mitmproxy/net/websockets/test_frame.py @@ -2,8 +2,8 @@ import os import codecs import pytest -from netlib import websockets -from netlib import tutils +from mitmproxy.net import websockets +from mitmproxy.test import tutils class TestFrameHeader: diff --git a/test/netlib/websockets/test_masker.py b/test/mitmproxy/net/websockets/test_masker.py index 23a9b876..88360c3b 100644 --- a/test/netlib/websockets/test_masker.py +++ b/test/mitmproxy/net/websockets/test_masker.py @@ -1,7 +1,7 @@ import codecs import pytest -from netlib import websockets +from mitmproxy.net import websockets class TestMasker: diff --git a/test/netlib/websockets/test_utils.py b/test/mitmproxy/net/websockets/test_utils.py index f6f1e40a..6704d39d 100644 --- a/test/netlib/websockets/test_utils.py +++ b/test/mitmproxy/net/websockets/test_utils.py @@ -1,7 +1,7 @@ import pytest -from netlib import http -from netlib import websockets +from mitmproxy.net import http +from mitmproxy.net import websockets class TestUtils: diff --git a/test/mitmproxy/protocol/test_http1.py b/test/mitmproxy/protocol/test_http1.py index 8701c8e6..43c903f3 100644 --- a/test/mitmproxy/protocol/test_http1.py +++ b/test/mitmproxy/protocol/test_http1.py @@ -1,6 +1,6 @@ -from netlib.http import http1 -from netlib.tcp import TCPClient -from netlib.tutils import treq +from mitmproxy.net.http import http1 +from mitmproxy.net.tcp import TCPClient +from mitmproxy.test.tutils import treq from .. import tutils, tservers diff --git a/test/mitmproxy/protocol/test_http2.py b/test/mitmproxy/protocol/test_http2.py index a2efdc47..4629d109 100644 --- a/test/mitmproxy/protocol/test_http2.py +++ b/test/mitmproxy/protocol/test_http2.py @@ -11,10 +11,10 @@ import h2 from mitmproxy import options from mitmproxy.proxy.config import ProxyConfig -import netlib -from ...netlib import tservers as netlib_tservers -from netlib.exceptions import HttpException -from netlib.http import http1, http2 +import mitmproxy.net +from ...mitmproxy.net import tservers as net_tservers +from mitmproxy import exceptions +from mitmproxy.net.http import http1, http2 from .. import tservers @@ -28,7 +28,7 @@ logging.getLogger("PIL.PngImagePlugin").setLevel(logging.WARNING) requires_alpn = pytest.mark.skipif( - not netlib.tcp.HAS_ALPN, + not mitmproxy.net.tcp.HAS_ALPN, reason='requires OpenSSL with ALPN support') @@ -37,10 +37,10 @@ requires_alpn = pytest.mark.skipif( # print(msg) -class _Http2ServerBase(netlib_tservers.ServerTestBase): +class _Http2ServerBase(net_tservers.ServerTestBase): ssl = dict(alpn_select=b'h2') - class handler(netlib.tcp.BaseHandler): + class handler(mitmproxy.net.tcp.BaseHandler): def handle(self): h2_conn = h2.connection.H2Connection(client_side=False, header_encoding=False) @@ -61,10 +61,10 @@ class _Http2ServerBase(netlib_tservers.ServerTestBase): try: raw = b''.join(http2.read_raw_frame(self.rfile)) events = h2_conn.receive_data(raw) - except HttpException: + except exceptions.HttpException: print(traceback.format_exc()) assert False - except netlib.exceptions.TcpDisconnect: + except exceptions.TcpDisconnect: break except: print(traceback.format_exc()) @@ -77,7 +77,7 @@ class _Http2ServerBase(netlib_tservers.ServerTestBase): if not self.server.handle_server_event(event, h2_conn, self.rfile, self.wfile): done = True break - except netlib.exceptions.TcpDisconnect: + except exceptions.TcpDisconnect: done = True except: done = True @@ -122,11 +122,11 @@ class _Http2TestBase: self.server.server.handle_server_event = self.handle_server_event def _setup_connection(self): - client = netlib.tcp.TCPClient(("127.0.0.1", self.proxy.port)) + client = mitmproxy.net.tcp.TCPClient(("127.0.0.1", self.proxy.port)) client.connect() # send CONNECT request - client.wfile.write(http1.assemble_request(netlib.http.Request( + client.wfile.write(http1.assemble_request(mitmproxy.net.http.Request( 'authority', b'CONNECT', b'', @@ -252,7 +252,7 @@ class TestSimple(_Http2Test): try: raw = b''.join(http2.read_raw_frame(client.rfile)) events = h2_conn.receive_data(raw) - except HttpException: + except exceptions.HttpException: print(traceback.format_exc()) assert False @@ -329,7 +329,7 @@ class TestRequestWithPriority(_Http2Test): try: raw = b''.join(http2.read_raw_frame(client.rfile)) events = h2_conn.receive_data(raw) - except HttpException: + except exceptions.HttpException: print(traceback.format_exc()) assert False @@ -368,7 +368,7 @@ class TestRequestWithPriority(_Http2Test): try: raw = b''.join(http2.read_raw_frame(client.rfile)) events = h2_conn.receive_data(raw) - except HttpException: + except exceptions.HttpException: print(traceback.format_exc()) assert False @@ -440,7 +440,7 @@ class TestPriority(_Http2Test): try: raw = b''.join(http2.read_raw_frame(client.rfile)) events = h2_conn.receive_data(raw) - except HttpException: + except exceptions.HttpException: print(traceback.format_exc()) assert False @@ -517,7 +517,7 @@ class TestPriorityWithExistingStream(_Http2Test): try: raw = b''.join(http2.read_raw_frame(client.rfile)) events = h2_conn.receive_data(raw) - except HttpException: + except exceptions.HttpException: print(traceback.format_exc()) assert False @@ -568,7 +568,7 @@ class TestStreamResetFromServer(_Http2Test): try: raw = b''.join(http2.read_raw_frame(client.rfile)) events = h2_conn.receive_data(raw) - except HttpException: + except exceptions.HttpException: print(traceback.format_exc()) assert False @@ -618,7 +618,7 @@ class TestBodySizeLimit(_Http2Test): try: raw = b''.join(http2.read_raw_frame(client.rfile)) events = h2_conn.receive_data(raw) - except HttpException: + except exceptions.HttpException: print(traceback.format_exc()) assert False @@ -703,7 +703,7 @@ class TestPushPromise(_Http2Test): try: raw = b''.join(http2.read_raw_frame(client.rfile)) events = h2_conn.receive_data(raw) - except HttpException: + except exceptions.HttpException: print(traceback.format_exc()) assert False except: @@ -756,7 +756,7 @@ class TestPushPromise(_Http2Test): try: raw = b''.join(http2.read_raw_frame(client.rfile)) events = h2_conn.receive_data(raw) - except HttpException: + except exceptions.HttpException: print(traceback.format_exc()) assert False @@ -816,7 +816,7 @@ class TestConnectionLost(_Http2Test): try: raw = b''.join(http2.read_raw_frame(client.rfile)) h2_conn.receive_data(raw) - except HttpException: + except exceptions.HttpException: print(traceback.format_exc()) assert False except: diff --git a/test/mitmproxy/protocol/test_websockets.py b/test/mitmproxy/protocol/test_websockets.py index ef520d87..71cbb5f4 100644 --- a/test/mitmproxy/protocol/test_websockets.py +++ b/test/mitmproxy/protocol/test_websockets.py @@ -4,19 +4,20 @@ import tempfile import traceback from mitmproxy import options +from mitmproxy import exceptions from mitmproxy.proxy.config import ProxyConfig -import netlib -from netlib import http -from ...netlib import tservers as netlib_tservers +import mitmproxy.net +from mitmproxy.net import http +from ...mitmproxy.net import tservers as net_tservers from .. import tservers -from netlib import websockets +from mitmproxy.net import websockets -class _WebSocketsServerBase(netlib_tservers.ServerTestBase): +class _WebSocketsServerBase(net_tservers.ServerTestBase): - class handler(netlib.tcp.BaseHandler): + class handler(mitmproxy.net.tcp.BaseHandler): def handle(self): try: @@ -77,7 +78,7 @@ class _WebSocketsTestBase: self.server.server.handle_websockets = self.handle_websockets def _setup_connection(self): - client = netlib.tcp.TCPClient(("127.0.0.1", self.proxy.port)) + client = mitmproxy.net.tcp.TCPClient(("127.0.0.1", self.proxy.port)) client.connect() request = http.Request( @@ -249,7 +250,7 @@ class TestClose(_WebSocketsTest): wfile.write(bytes(frame)) wfile.flush() - with pytest.raises(netlib.exceptions.TcpDisconnect): + with pytest.raises(exceptions.TcpDisconnect): websockets.Frame.from_file(rfile) def test_close(self): @@ -258,7 +259,7 @@ class TestClose(_WebSocketsTest): client.wfile.write(bytes(websockets.Frame(fin=1, opcode=websockets.OPCODE.CLOSE))) client.wfile.flush() - with pytest.raises(netlib.exceptions.TcpDisconnect): + with pytest.raises(exceptions.TcpDisconnect): websockets.Frame.from_file(client.rfile) def test_close_payload_1(self): @@ -267,7 +268,7 @@ class TestClose(_WebSocketsTest): client.wfile.write(bytes(websockets.Frame(fin=1, opcode=websockets.OPCODE.CLOSE, payload=b'\00\42'))) client.wfile.flush() - with pytest.raises(netlib.exceptions.TcpDisconnect): + with pytest.raises(exceptions.TcpDisconnect): websockets.Frame.from_file(client.rfile) def test_close_payload_2(self): @@ -276,7 +277,7 @@ class TestClose(_WebSocketsTest): client.wfile.write(bytes(websockets.Frame(fin=1, opcode=websockets.OPCODE.CLOSE, payload=b'\00\42foobar'))) client.wfile.flush() - with pytest.raises(netlib.exceptions.TcpDisconnect): + with pytest.raises(exceptions.TcpDisconnect): websockets.Frame.from_file(client.rfile) @@ -290,7 +291,7 @@ class TestInvalidFrame(_WebSocketsTest): def test_invalid_frame(self): client = self._setup_connection() - # with pytest.raises(netlib.exceptions.TcpDisconnect): + # with pytest.raises(exceptions.TcpDisconnect): frame = websockets.Frame.from_file(client.rfile) assert frame.header.opcode == 15 assert frame.payload == b'foobar' diff --git a/test/netlib/test_certutils.py b/test/mitmproxy/test_certs.py index cf9a671b..2e706fa6 100644 --- a/test/netlib/test_certutils.py +++ b/test/mitmproxy/test_certs.py @@ -1,9 +1,10 @@ import os -from netlib import certutils, tutils +from mitmproxy import certs +from mitmproxy.test import tutils # class TestDNTree: # def test_simple(self): -# d = certutils.DNTree() +# d = certs.DNTree() # d.add("foo.com", "foo") # d.add("bar.com", "bar") # assert d.get("foo.com") == "foo" @@ -19,12 +20,12 @@ from netlib import certutils, tutils # assert d.get("foo.foo.match.org") == "match" # # def test_wildcard(self): -# d = certutils.DNTree() +# d = certs.DNTree() # d.add("foo.com", "foo") # assert not d.get("*.foo.com") # d.add("*.foo.com", "wild") # -# d = certutils.DNTree() +# d = certs.DNTree() # d.add("*", "foo") # assert d.get("foo.com") == "foo" # assert d.get("*.foo.com") == "foo" @@ -35,22 +36,22 @@ class TestCertStore: def test_create_explicit(self): with tutils.tmpdir() as d: - ca = certutils.CertStore.from_store(d, "test") + ca = certs.CertStore.from_store(d, "test") assert ca.get_cert(b"foo", []) - ca2 = certutils.CertStore.from_store(d, "test") + ca2 = certs.CertStore.from_store(d, "test") assert ca2.get_cert(b"foo", []) assert ca.default_ca.get_serial_number() == ca2.default_ca.get_serial_number() def test_create_no_common_name(self): with tutils.tmpdir() as d: - ca = certutils.CertStore.from_store(d, "test") + ca = certs.CertStore.from_store(d, "test") assert ca.get_cert(None, [])[0].cn is None def test_create_tmp(self): with tutils.tmpdir() as d: - ca = certutils.CertStore.from_store(d, "test") + ca = certs.CertStore.from_store(d, "test") assert ca.get_cert(b"foo.com", []) assert ca.get_cert(b"foo.com", []) assert ca.get_cert(b"*.foo.com", []) @@ -60,7 +61,7 @@ class TestCertStore: def test_sans(self): with tutils.tmpdir() as d: - ca = certutils.CertStore.from_store(d, "test") + ca = certs.CertStore.from_store(d, "test") c1 = ca.get_cert(b"foo.com", [b"*.bar.com"]) ca.get_cert(b"foo.bar.com", []) # assert c1 == c2 @@ -69,14 +70,14 @@ class TestCertStore: def test_sans_change(self): with tutils.tmpdir() as d: - ca = certutils.CertStore.from_store(d, "test") + ca = certs.CertStore.from_store(d, "test") ca.get_cert(b"foo.com", [b"*.bar.com"]) cert, key, chain_file = ca.get_cert(b"foo.bar.com", [b"*.baz.com"]) assert b"*.baz.com" in cert.altnames def test_expire(self): with tutils.tmpdir() as d: - ca = certutils.CertStore.from_store(d, "test") + ca = certs.CertStore.from_store(d, "test") ca.STORE_CAP = 3 ca.get_cert(b"one.com", []) ca.get_cert(b"two.com", []) @@ -101,8 +102,8 @@ class TestCertStore: def test_overrides(self): with tutils.tmpdir() as d: - ca1 = certutils.CertStore.from_store(os.path.join(d, "ca1"), "test") - ca2 = certutils.CertStore.from_store(os.path.join(d, "ca2"), "test") + ca1 = certs.CertStore.from_store(os.path.join(d, "ca1"), "test") + ca2 = certs.CertStore.from_store(os.path.join(d, "ca2"), "test") assert not ca1.default_ca.get_serial_number( ) == ca2.default_ca.get_serial_number() @@ -121,8 +122,8 @@ class TestDummyCert: def test_with_ca(self): with tutils.tmpdir() as d: - ca = certutils.CertStore.from_store(d, "test") - r = certutils.dummy_cert( + ca = certs.CertStore.from_store(d, "test") + r = certs.dummy_cert( ca.default_privatekey, ca.default_ca, b"foo.com", @@ -130,7 +131,7 @@ class TestDummyCert: ) assert r.cn == b"foo.com" - r = certutils.dummy_cert( + r = certs.dummy_cert( ca.default_privatekey, ca.default_ca, None, @@ -144,13 +145,13 @@ class TestSSLCert: def test_simple(self): with open(tutils.test_data.path("data/text_cert"), "rb") as f: d = f.read() - c1 = certutils.SSLCert.from_pem(d) + c1 = certs.SSLCert.from_pem(d) assert c1.cn == b"google.com" assert len(c1.altnames) == 436 with open(tutils.test_data.path("data/text_cert_2"), "rb") as f: d = f.read() - c2 = certutils.SSLCert.from_pem(d) + c2 = certs.SSLCert.from_pem(d) assert c2.cn == b"www.inode.co.nz" assert len(c2.altnames) == 2 assert c2.digest("sha1") @@ -169,12 +170,12 @@ class TestSSLCert: def test_err_broken_sans(self): with open(tutils.test_data.path("data/text_cert_weird1"), "rb") as f: d = f.read() - c = certutils.SSLCert.from_pem(d) + c = certs.SSLCert.from_pem(d) # This breaks unless we ignore a decoding error. assert c.altnames is not None def test_der(self): with open(tutils.test_data.path("data/dercert"), "rb") as f: d = f.read() - s = certutils.SSLCert.from_der(d) + s = certs.SSLCert.from_der(d) assert s.cn diff --git a/test/mitmproxy/test_contentview.py b/test/mitmproxy/test_contentview.py index d63ee50e..b0e77ce1 100644 --- a/test/mitmproxy/test_contentview.py +++ b/test/mitmproxy/test_contentview.py @@ -1,12 +1,12 @@ import mock from mitmproxy.exceptions import ContentViewException -from netlib.http import Headers -from netlib.http import url -from netlib import multidict +from mitmproxy.net.http import Headers +from mitmproxy.net.http import url +from mitmproxy.types import multidict import mitmproxy.contentviews as cv from . import tutils -import netlib.tutils +import mitmproxy.test.tutils try: import pyamf @@ -232,7 +232,7 @@ def test_get_content_view(): def test_get_message_content_view(): - r = netlib.tutils.treq() + r = mitmproxy.test.tutils.treq() desc, lines, err = cv.get_message_content_view(cv.get("Raw"), r) assert desc == "Raw" diff --git a/test/mitmproxy/test_controller.py b/test/mitmproxy/test_controller.py index 071638a9..3bcb7013 100644 --- a/test/mitmproxy/test_controller.py +++ b/test/mitmproxy/test_controller.py @@ -9,7 +9,7 @@ import queue from mitmproxy.exceptions import Kill, ControlException from mitmproxy import proxy from mitmproxy import master -from netlib.tutils import raises +from mitmproxy.test.tutils import raises class TMsg: diff --git a/test/mitmproxy/test_custom_contentview.py b/test/mitmproxy/test_custom_contentview.py index 889fb8b3..28f7fb33 100644 --- a/test/mitmproxy/test_custom_contentview.py +++ b/test/mitmproxy/test_custom_contentview.py @@ -1,5 +1,5 @@ import mitmproxy.contentviews as cv -from netlib.http import Headers +from mitmproxy.net.http import Headers def test_custom_views(): diff --git a/test/mitmproxy/test_examples.py b/test/mitmproxy/test_examples.py index 7551c1c8..6972da0c 100644 --- a/test/mitmproxy/test_examples.py +++ b/test/mitmproxy/test_examples.py @@ -6,17 +6,16 @@ from mitmproxy import options from mitmproxy import contentviews from mitmproxy import proxy from mitmproxy.addons import script +from mitmproxy.utils import data from mitmproxy import master -import netlib.utils - -from netlib import tutils as netutils -from netlib.http import Headers -from netlib.http import cookies +from mitmproxy.test import tutils as netutils +from mitmproxy.net.http import Headers +from mitmproxy.net.http import cookies from . import tutils, mastertest -example_dir = netlib.utils.Data(__name__).push("../../examples") +example_dir = data.Data(__name__).push("../../examples") class ScriptError(Exception): diff --git a/test/mitmproxy/test_flow.py b/test/mitmproxy/test_flow.py index 9ebcca34..5b9f3835 100644 --- a/test/mitmproxy/test_flow.py +++ b/test/mitmproxy/test_flow.py @@ -1,8 +1,8 @@ import mock import io -import netlib.utils -from netlib.http import Headers +import mitmproxy.test.tutils +from mitmproxy.net.http import Headers import mitmproxy.io from mitmproxy import flowfilter, options from mitmproxy.addons import state @@ -59,7 +59,7 @@ class TestHTTPFlow: def test_backup(self): f = tutils.tflow() - f.response = http.HTTPResponse.wrap(netlib.tutils.tresp()) + f.response = http.HTTPResponse.wrap(mitmproxy.test.tutils.tresp()) f.request.content = b"foo" assert not f.modified() f.backup() @@ -212,7 +212,7 @@ class TestState: assert c.add_flow(newf) assert c.active_flow_count() == 2 - f.response = http.HTTPResponse.wrap(netlib.tutils.tresp()) + f.response = http.HTTPResponse.wrap(mitmproxy.test.tutils.tresp()) assert c.update_flow(f) assert c.flow_count() == 2 assert c.active_flow_count() == 1 @@ -220,7 +220,7 @@ class TestState: assert not c.update_flow(None) assert c.active_flow_count() == 1 - newf.response = http.HTTPResponse.wrap(netlib.tutils.tresp()) + newf.response = http.HTTPResponse.wrap(mitmproxy.test.tutils.tresp()) assert c.update_flow(newf) assert c.active_flow_count() == 0 @@ -252,7 +252,7 @@ class TestState: c.set_view_filter("~s") assert c.filter_txt == "~s" assert len(c.view) == 0 - f.response = http.HTTPResponse.wrap(netlib.tutils.tresp()) + f.response = http.HTTPResponse.wrap(mitmproxy.test.tutils.tresp()) c.update_flow(f) assert len(c.view) == 1 c.set_view_filter(None) @@ -284,7 +284,7 @@ class TestState: def _add_response(self, state): f = tutils.tflow() state.add_flow(f) - f.response = http.HTTPResponse.wrap(netlib.tutils.tresp()) + f.response = http.HTTPResponse.wrap(mitmproxy.test.tutils.tresp()) state.update_flow(f) def _add_error(self, state): @@ -444,11 +444,11 @@ class TestFlowMaster: fm.addons.add(s) f = tutils.tflow(req=None) fm.clientconnect(f.client_conn) - f.request = http.HTTPRequest.wrap(netlib.tutils.treq()) + f.request = http.HTTPRequest.wrap(mitmproxy.test.tutils.treq()) fm.request(f) assert s.flow_count() == 1 - f.response = http.HTTPResponse.wrap(netlib.tutils.tresp()) + f.response = http.HTTPResponse.wrap(mitmproxy.test.tutils.tresp()) fm.response(f) assert s.flow_count() == 1 @@ -473,7 +473,7 @@ class TestRequest: assert r.get_state() == r2.get_state() def test_get_url(self): - r = http.HTTPRequest.wrap(netlib.tutils.treq()) + r = http.HTTPRequest.wrap(mitmproxy.test.tutils.treq()) assert r.url == "http://address:22/path" @@ -494,7 +494,7 @@ class TestRequest: assert r.pretty_url == "https://foo.com:22/path" def test_replace(self): - r = http.HTTPRequest.wrap(netlib.tutils.treq()) + r = http.HTTPRequest.wrap(mitmproxy.test.tutils.treq()) r.path = "path/foo" r.headers["Foo"] = "fOo" r.content = b"afoob" @@ -504,7 +504,7 @@ class TestRequest: assert r.headers["boo"] == "boo" def test_constrain_encoding(self): - r = http.HTTPRequest.wrap(netlib.tutils.treq()) + r = http.HTTPRequest.wrap(mitmproxy.test.tutils.treq()) r.headers["accept-encoding"] = "gzip, oink" r.constrain_encoding() assert "oink" not in r.headers["accept-encoding"] @@ -514,7 +514,7 @@ class TestRequest: assert "oink" not in r.headers["accept-encoding"] def test_get_content_type(self): - resp = http.HTTPResponse.wrap(netlib.tutils.tresp()) + resp = http.HTTPResponse.wrap(mitmproxy.test.tutils.tresp()) resp.headers = Headers(content_type="text/plain") assert resp.headers["content-type"] == "text/plain" @@ -528,7 +528,7 @@ class TestResponse: assert resp2.get_state() == resp.get_state() def test_replace(self): - r = http.HTTPResponse.wrap(netlib.tutils.tresp()) + r = http.HTTPResponse.wrap(mitmproxy.test.tutils.tresp()) r.headers["Foo"] = "fOo" r.content = b"afoob" assert r.replace("foo(?i)", "boo") == 3 @@ -536,7 +536,7 @@ class TestResponse: assert r.headers["boo"] == "boo" def test_get_content_type(self): - resp = http.HTTPResponse.wrap(netlib.tutils.tresp()) + resp = http.HTTPResponse.wrap(mitmproxy.test.tutils.tresp()) resp.headers = Headers(content_type="text/plain") assert resp.headers["content-type"] == "text/plain" diff --git a/test/mitmproxy/test_flow_export.py b/test/mitmproxy/test_flow_export.py index aafd5a1c..df0ccb77 100644 --- a/test/mitmproxy/test_flow_export.py +++ b/test/mitmproxy/test_flow_export.py @@ -1,7 +1,7 @@ import re -import netlib.tutils -from netlib.http import Headers +import mitmproxy.test.tutils +from mitmproxy.net.http import Headers from mitmproxy import export # heh from . import tutils @@ -20,15 +20,15 @@ def python_equals(testdata, text): def req_get(): - return netlib.tutils.treq(method=b'GET', content=b'', path=b"/path?a=foo&a=bar&b=baz") + return mitmproxy.test.tutils.treq(method=b'GET', content=b'', path=b"/path?a=foo&a=bar&b=baz") def req_post(): - return netlib.tutils.treq(method=b'POST', headers=()) + return mitmproxy.test.tutils.treq(method=b'POST', headers=()) def req_patch(): - return netlib.tutils.treq(method=b'PATCH', path=b"/path?query=param") + return mitmproxy.test.tutils.treq(method=b'PATCH', path=b"/path?query=param") class TestExportCurlCommand: diff --git a/test/mitmproxy/test_optmanager.py b/test/mitmproxy/test_optmanager.py index 1d677bd3..3c845707 100644 --- a/test/mitmproxy/test_optmanager.py +++ b/test/mitmproxy/test_optmanager.py @@ -2,7 +2,7 @@ import copy from mitmproxy import optmanager from mitmproxy import exceptions -from netlib import tutils +from mitmproxy.test import tutils class TO(optmanager.OptManager): diff --git a/test/mitmproxy/test_proxy.py b/test/mitmproxy/test_proxy.py index 7d401184..a9d9bb87 100644 --- a/test/mitmproxy/test_proxy.py +++ b/test/mitmproxy/test_proxy.py @@ -8,9 +8,9 @@ from mitmproxy.proxy import ProxyConfig from mitmproxy import connections from mitmproxy.proxy.server import DummyServer, ProxyServer, ConnectionHandler from mitmproxy.proxy import config -from netlib.exceptions import TcpDisconnect +from mitmproxy import exceptions from pathod import test -from netlib.http import http1 +from mitmproxy.net.http import http1 from . import tutils @@ -40,7 +40,7 @@ class TestServerConnection: sc.connect() sc.connection = mock.Mock() sc.connection.recv = mock.Mock(return_value=False) - sc.connection.flush = mock.Mock(side_effect=TcpDisconnect) + sc.connection.flush = mock.Mock(side_effect=exceptions.TcpDisconnect) sc.finish() self.d.shutdown() diff --git a/test/mitmproxy/test_server.py b/test/mitmproxy/test_server.py index 93a82954..7dd738f4 100644 --- a/test/mitmproxy/test_server.py +++ b/test/mitmproxy/test_server.py @@ -2,20 +2,23 @@ import os import socket import time -import netlib.tutils +import mitmproxy.test.tutils from mitmproxy import controller from mitmproxy import options from mitmproxy.addons import script from mitmproxy import http from mitmproxy.proxy.config import HostMatcher, parse_server_spec -import netlib.http -from netlib import tcp, socks -from netlib.certutils import SSLCert -from netlib.exceptions import HttpReadDisconnect, HttpException -from netlib.http import authentication, http1 -from netlib.tcp import Address -from netlib.tutils import raises -from pathod import pathoc, pathod +import mitmproxy.net.http +from mitmproxy.net import tcp +from mitmproxy.net import socks +from mitmproxy import certs +from mitmproxy import exceptions +from mitmproxy.net.http import authentication +from mitmproxy.net.http import http1 +from mitmproxy.net.tcp import Address +from mitmproxy.test.tutils import raises +from pathod import pathoc +from pathod import pathod from . import tutils, tservers @@ -144,9 +147,9 @@ class TcpMixin: # Test that we get the original SSL cert if self.ssl: - i_cert = SSLCert(i.sslinfo.certchain[0]) - i2_cert = SSLCert(i2.sslinfo.certchain[0]) - n_cert = SSLCert(n.sslinfo.certchain[0]) + i_cert = certs.SSLCert(i.sslinfo.certchain[0]) + i2_cert = certs.SSLCert(i2.sslinfo.certchain[0]) + n_cert = certs.SSLCert(n.sslinfo.certchain[0]) assert i_cert == i2_cert assert i_cert != n_cert @@ -156,7 +159,7 @@ class TcpMixin: # mitmproxy responds with bad gateway assert self.pathod(spec).status_code == 502 self._ignore_on() - with raises(HttpException): + with raises(exceptions.HttpException): self.pathod(spec) # pathoc tries to parse answer as HTTP self._ignore_off() @@ -190,9 +193,9 @@ class TcpMixin: # Test that we get the original SSL cert if self.ssl: - i_cert = SSLCert(i.sslinfo.certchain[0]) - i2_cert = SSLCert(i2.sslinfo.certchain[0]) - n_cert = SSLCert(n.sslinfo.certchain[0]) + i_cert = certs.SSLCert(i.sslinfo.certchain[0]) + i2_cert = certs.SSLCert(i2.sslinfo.certchain[0]) + n_cert = certs.SSLCert(n.sslinfo.certchain[0]) assert i_cert == i2_cert == n_cert @@ -294,7 +297,7 @@ class TestHTTPAuth(tservers.HTTPProxyTest): h'%s'='%s' """ % ( self.server.port, - netlib.http.authentication.BasicProxyAuth.AUTH_HEADER, + mitmproxy.net.http.authentication.BasicProxyAuth.AUTH_HEADER, authentication.assemble_http_basic_auth("basic", "test", "test") )) assert ret.status_code == 202 @@ -311,7 +314,7 @@ class TestHTTPReverseAuth(tservers.ReverseProxyTest): '/p/202' h'%s'='%s' """ % ( - netlib.http.authentication.BasicWebsiteAuth.AUTH_HEADER, + mitmproxy.net.http.authentication.BasicWebsiteAuth.AUTH_HEADER, authentication.assemble_http_basic_auth("basic", "test", "test") )) assert ret.status_code == 202 @@ -435,7 +438,7 @@ class TestHTTPSUpstreamServerVerificationWBadCert(tservers.HTTPProxyTest): def test_verification_w_bad_cert(self): # We only test for a single invalid cert here. # Actual testing of different root-causes (invalid hostname, expired, ...) - # is done in netlib. + # is done in mitmproxy.net. self.config.options.ssl_insecure = False r = self._request() assert r.status_code == 502 @@ -791,7 +794,7 @@ class TestStreamRequest(tservers.HTTPProxyTest): class MasterFakeResponse(tservers.TestMaster): @controller.handler def request(self, f): - f.response = http.HTTPResponse.wrap(netlib.tutils.tresp()) + f.response = http.HTTPResponse.wrap(mitmproxy.test.tutils.tresp()) class TestFakeResponse(tservers.HTTPProxyTest): @@ -830,7 +833,7 @@ class TestKillRequest(tservers.HTTPProxyTest): masterclass = MasterKillRequest def test_kill(self): - with raises(HttpReadDisconnect): + with raises(exceptions.HttpReadDisconnect): self.pathod("200") # Nothing should have hit the server assert not self.server.last_log() @@ -847,7 +850,7 @@ class TestKillResponse(tservers.HTTPProxyTest): masterclass = MasterKillResponse def test_kill(self): - with raises(HttpReadDisconnect): + with raises(exceptions.HttpReadDisconnect): self.pathod("200") # The server should have seen a request assert self.server.last_log() @@ -870,7 +873,7 @@ class MasterIncomplete(tservers.TestMaster): @controller.handler def request(self, f): - resp = http.HTTPResponse.wrap(netlib.tutils.tresp()) + resp = http.HTTPResponse.wrap(mitmproxy.test.tutils.tresp()) resp.content = None f.response = resp @@ -1050,7 +1053,7 @@ class AddUpstreamCertsToClientChainMixin: def test_add_upstream_certs_to_client_chain(self): with open(self.servercert, "rb") as f: d = f.read() - upstreamCert = SSLCert.from_pem(d) + upstreamCert = certs.SSLCert.from_pem(d) p = self.pathoc() with p.connect(): upstream_cert_found_in_client_chain = False diff --git a/test/mitmproxy/test_types_bidi.py b/test/mitmproxy/test_types_bidi.py new file mode 100644 index 00000000..0494ac9d --- /dev/null +++ b/test/mitmproxy/test_types_bidi.py @@ -0,0 +1,11 @@ +from mitmproxy.types import bidi +from mitmproxy.test import tutils + + +def test_bidi(): + b = bidi.BiDi(a=1, b=2) + assert b.a == 1 + assert b.get_name(1) == "a" + assert b.get_name(5) is None + tutils.raises(AttributeError, getattr, b, "c") + tutils.raises(ValueError, bidi.BiDi, one=1, two=1) diff --git a/test/netlib/test_multidict.py b/test/mitmproxy/test_types_multidict.py index a9523fd9..d566905c 100644 --- a/test/netlib/test_multidict.py +++ b/test/mitmproxy/test_types_multidict.py @@ -1,5 +1,5 @@ -from netlib import tutils -from netlib.multidict import MultiDict, ImmutableMultiDict, MultiDictView +from mitmproxy.test import tutils +from mitmproxy.types import multidict class _TMulti: @@ -8,11 +8,11 @@ class _TMulti: return key.lower() -class TMultiDict(_TMulti, MultiDict): +class TMultiDict(_TMulti, multidict.MultiDict): pass -class TImmutableMultiDict(_TMulti, ImmutableMultiDict): +class TImmutableMultiDict(_TMulti, multidict.ImmutableMultiDict): pass @@ -238,7 +238,7 @@ class TParent: class TestMultiDictView: def test_modify(self): p = TParent() - tv = MultiDictView(p.getter, p.setter) + tv = multidict.MultiDictView(p.getter, p.setter) assert len(tv) == 0 tv["a"] = "b" assert p.vals == (("a", "b"),) diff --git a/test/netlib/test_basetypes.py b/test/mitmproxy/test_types_serializable.py index aa415784..dd4a3778 100644 --- a/test/netlib/test_basetypes.py +++ b/test/mitmproxy/test_types_serializable.py @@ -1,7 +1,7 @@ -from netlib import basetypes +from mitmproxy.types import serializable -class SerializableDummy(basetypes.Serializable): +class SerializableDummy(serializable.Serializable): def __init__(self, i): self.i = i diff --git a/test/mitmproxy/test_utils_data.py b/test/mitmproxy/test_utils_data.py new file mode 100644 index 00000000..c6e4420e --- /dev/null +++ b/test/mitmproxy/test_utils_data.py @@ -0,0 +1,7 @@ +from mitmproxy.utils import data +from . import tutils + + +def test_pkg_data(): + assert data.pkg_data.path("tools/console") + tutils.raises("does not exist", data.pkg_data.path, "nonexistent") diff --git a/test/netlib/test_debug.py b/test/mitmproxy/test_utils_debug.py index bdb85c9e..9acf8192 100644 --- a/test/netlib/test_debug.py +++ b/test/mitmproxy/test_utils_debug.py @@ -1,6 +1,6 @@ import io -from netlib import debug +from mitmproxy.utils import debug def test_dump_info(): diff --git a/test/netlib/test_human.py b/test/mitmproxy/test_utils_human.py index bb97dc54..443c8f66 100644 --- a/test/netlib/test_human.py +++ b/test/mitmproxy/test_utils_human.py @@ -1,5 +1,6 @@ import time -from netlib import human, tutils +from mitmproxy.utils import human +from mitmproxy.test import tutils def test_format_timestamp(): diff --git a/test/mitmproxy/test_utils.py b/test/mitmproxy/test_utils_lrucache.py index ed59f484..07b96b4d 100644 --- a/test/mitmproxy/test_utils.py +++ b/test/mitmproxy/test_utils_lrucache.py @@ -1,16 +1,8 @@ -from mitmproxy import utils -from . import tutils - -utils.CERT_SLEEP_TIME = 0 - - -def test_pkg_data(): - assert utils.pkg_data.path("tools/console") - tutils.raises("does not exist", utils.pkg_data.path, "nonexistent") +from mitmproxy.utils import lrucache def test_LRUCache(): - cache = utils.LRUCache(2) + cache = lrucache.LRUCache(2) class Foo: ran = False diff --git a/test/netlib/test_strutils.py b/test/mitmproxy/test_utils_strutils.py index 36f709da..d4c2883c 100644 --- a/test/netlib/test_strutils.py +++ b/test/mitmproxy/test_utils_strutils.py @@ -1,4 +1,5 @@ -from netlib import strutils, tutils +from mitmproxy.utils import strutils +from mitmproxy.test import tutils def test_always_bytes(): diff --git a/test/netlib/test_version_check.py b/test/mitmproxy/test_utils_version_check.py index 01820dad..5c8d8c8c 100644 --- a/test/netlib/test_version_check.py +++ b/test/mitmproxy/test_utils_version_check.py @@ -1,6 +1,6 @@ import io import mock -from netlib import version_check +from mitmproxy.utils import version_check @mock.patch("sys.exit") diff --git a/test/mitmproxy/tservers.py b/test/mitmproxy/tservers.py index 1243bca0..e07102e1 100644 --- a/test/mitmproxy/tservers.py +++ b/test/mitmproxy/tservers.py @@ -10,8 +10,9 @@ from mitmproxy import master from mitmproxy.addons import state import pathod.test import pathod.pathoc -from mitmproxy import controller, options -import netlib.exceptions +from mitmproxy import controller +from mitmproxy import options +from mitmproxy import exceptions class TestMaster(master.Master): @@ -98,7 +99,7 @@ class ProxyTestBase: def teardown(self): try: self.server.wait_for_silence() - except netlib.exceptions.Timeout: + except exceptions.Timeout: # FIXME: Track down the Windows sync issues if sys.platform != "win32": raise diff --git a/test/mitmproxy/tutils.py b/test/mitmproxy/tutils.py index eb0c90e9..c83223f6 100644 --- a/test/mitmproxy/tutils.py +++ b/test/mitmproxy/tutils.py @@ -9,13 +9,13 @@ from unittest.case import SkipTest import io -import netlib.utils -import netlib.tutils +import mitmproxy.test.tutils from mitmproxy import controller from mitmproxy import connections from mitmproxy import flow from mitmproxy import http from mitmproxy import tcp +from mitmproxy.utils import data def _skip_windows(*args): @@ -102,9 +102,9 @@ def tflow(client_conn=True, server_conn=True, req=True, resp=None, err=None): if server_conn is True: server_conn = tserver_conn() if req is True: - req = netlib.tutils.treq() + req = mitmproxy.test.tutils.treq() if resp is True: - resp = netlib.tutils.tresp() + resp = mitmproxy.test.tutils.tresp() if err is True: err = terr() @@ -197,7 +197,7 @@ class MockParser(argparse.ArgumentParser): raise Exception(message) -raises = netlib.tutils.raises +raises = mitmproxy.test.tutils.raises @contextmanager @@ -208,4 +208,4 @@ def capture_stderr(command, *args, **kwargs): sys.stderr = out -test_data = netlib.utils.Data(__name__) +test_data = data.Data(__name__) diff --git a/test/netlib/test_utils.py b/test/netlib/test_utils.py deleted file mode 100644 index 9dcbffd8..00000000 --- a/test/netlib/test_utils.py +++ /dev/null @@ -1,19 +0,0 @@ -# coding=utf-8 - -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 - assert b.get_name(1) == "a" - assert b.get_name(5) is None - tutils.raises(AttributeError, getattr, b, "c") - tutils.raises(ValueError, utils.BiDi, one=1, two=1) diff --git a/test/pathod/test_language_http2.py b/test/pathod/test_language_http2.py index 11e100ac..7d3a8e60 100644 --- a/test/pathod/test_language_http2.py +++ b/test/pathod/test_language_http2.py @@ -1,7 +1,7 @@ import io -from netlib import tcp -from netlib.http import user_agents +from mitmproxy.net import tcp +from mitmproxy.net.http import user_agents from pathod import language from pathod.language import http2 diff --git a/test/pathod/test_language_websocket.py b/test/pathod/test_language_websocket.py index 9d533d98..49fbd4e6 100644 --- a/test/pathod/test_language_websocket.py +++ b/test/pathod/test_language_websocket.py @@ -1,6 +1,6 @@ from pathod import language from pathod.language import websockets -import netlib.websockets +import mitmproxy.net.websockets from . import tutils @@ -62,7 +62,7 @@ class TestWebsocketFrame: def test_flags(self): wf = parse_request("wf:fin:mask:rsv1:rsv2:rsv3") - frm = netlib.websockets.Frame.from_bytes(tutils.render(wf)) + frm = mitmproxy.net.websockets.Frame.from_bytes(tutils.render(wf)) assert frm.header.fin assert frm.header.mask assert frm.header.rsv1 @@ -70,7 +70,7 @@ class TestWebsocketFrame: assert frm.header.rsv3 wf = parse_request("wf:-fin:-mask:-rsv1:-rsv2:-rsv3") - frm = netlib.websockets.Frame.from_bytes(tutils.render(wf)) + frm = mitmproxy.net.websockets.Frame.from_bytes(tutils.render(wf)) assert not frm.header.fin assert not frm.header.mask assert not frm.header.rsv1 @@ -80,15 +80,15 @@ class TestWebsocketFrame: def fr(self, spec, **kwargs): settings = language.base.Settings(**kwargs) wf = parse_request(spec) - return netlib.websockets.Frame.from_bytes(tutils.render(wf, settings)) + return mitmproxy.net.websockets.Frame.from_bytes(tutils.render(wf, settings)) def test_construction(self): assert self.fr("wf:c1").header.opcode == 1 assert self.fr("wf:c0").header.opcode == 0 assert self.fr("wf:cbinary").header.opcode ==\ - netlib.websockets.OPCODE.BINARY + mitmproxy.net.websockets.OPCODE.BINARY assert self.fr("wf:ctext").header.opcode ==\ - netlib.websockets.OPCODE.TEXT + mitmproxy.net.websockets.OPCODE.TEXT def test_rawbody(self): frm = self.fr("wf:mask:r'foo'") diff --git a/test/pathod/test_log.py b/test/pathod/test_log.py index deb0f613..8890e7d9 100644 --- a/test/pathod/test_log.py +++ b/test/pathod/test_log.py @@ -1,7 +1,7 @@ import io from pathod import log -from netlib.exceptions import TcpDisconnect +from mitmproxy import exceptions class DummyIO(io.StringIO): @@ -20,6 +20,6 @@ def test_disconnect(): try: with l.ctx() as lg: lg("Test") - except TcpDisconnect: + except exceptions.TcpDisconnect: pass assert "Test" in outf.getvalue() diff --git a/test/pathod/test_pathoc.py b/test/pathod/test_pathoc.py index f9670d73..90177ff6 100644 --- a/test/pathod/test_pathoc.py +++ b/test/pathod/test_pathoc.py @@ -1,11 +1,11 @@ import io from mock import Mock -from netlib import http -from netlib import tcp -from netlib.exceptions import NetlibException -from netlib.http import http1 -from netlib.tutils import raises +from mitmproxy.net import http +from mitmproxy.net import tcp +from mitmproxy.net.http import http1 +from mitmproxy.test.tutils import raises +from mitmproxy import exceptions from pathod import pathoc, language from pathod.protocols.http2 import HTTP2StateProtocol @@ -36,7 +36,7 @@ class PathocTestDaemon(tutils.DaemonTests): r = r.freeze(language.Settings()) try: c.request(r) - except NetlibException: + except exceptions.NetlibException: pass self.d.wait_for_silence() return s.getvalue() diff --git a/test/pathod/test_pathod.py b/test/pathod/test_pathod.py index 89d7c562..8ee7a2fd 100644 --- a/test/pathod/test_pathod.py +++ b/test/pathod/test_pathod.py @@ -1,8 +1,8 @@ import io from pathod import pathod -from netlib import tcp -from netlib.exceptions import HttpException, TlsException +from mitmproxy.net import tcp +from mitmproxy import exceptions from . import tutils @@ -157,7 +157,7 @@ class CommonTests(tutils.DaemonTests): def test_invalid_content_length(self): tutils.raises( - HttpException, + exceptions.HttpException, self.pathoc, ["get:/:h'content-length'='foo'"] ) @@ -166,7 +166,7 @@ class CommonTests(tutils.DaemonTests): assert "Unparseable Content Length" in l["msg"] def test_invalid_headers(self): - tutils.raises(HttpException, self.pathoc, ["get:/:h'\t'='foo'"]) + tutils.raises(exceptions.HttpException, self.pathoc, ["get:/:h'\t'='foo'"]) l = self.d.last_log() assert l["type"] == "error" assert "Invalid headers" in l["msg"] @@ -225,7 +225,7 @@ class TestDaemon(CommonTests): def test_connect_err(self): tutils.raises( - HttpException, + exceptions.HttpException, self.pathoc, [r"get:'http://foo.com/p/202':da"], connect_to=("localhost", self.d.port) @@ -241,7 +241,7 @@ class TestDaemonSSL(CommonTests): c.wbufsize = 0 with c.connect(): c.wfile.write(b"\0\0\0\0") - tutils.raises(TlsException, c.convert_to_ssl) + tutils.raises(exceptions.TlsException, c.convert_to_ssl) l = self.d.last_log() assert l["type"] == "error" assert "SSL" in l["msg"] diff --git a/test/pathod/test_protocols_http2.py b/test/pathod/test_protocols_http2.py index 7300cc1d..d77702a3 100644 --- a/test/pathod/test_protocols_http2.py +++ b/test/pathod/test_protocols_http2.py @@ -2,12 +2,12 @@ import mock import codecs import hyperframe -from netlib import tcp, http -from netlib.tutils import raises -from netlib.exceptions import TcpDisconnect -from netlib.http import http2 +from mitmproxy.net import tcp, http +from mitmproxy.test.tutils import raises +from mitmproxy.net.http import http2 +from mitmproxy import exceptions -from ..netlib import tservers as netlib_tservers +from ..mitmproxy.net import tservers as net_tservers from pathod.protocols.http2 import HTTP2StateProtocol, TCPHandler @@ -66,7 +66,7 @@ class TestProtocol: assert mock_server_method.called -class TestCheckALPNMatch(netlib_tservers.ServerTestBase): +class TestCheckALPNMatch(net_tservers.ServerTestBase): handler = EchoHandler ssl = dict( alpn_select=b'h2', @@ -82,7 +82,7 @@ class TestCheckALPNMatch(netlib_tservers.ServerTestBase): assert protocol.check_alpn() -class TestCheckALPNMismatch(netlib_tservers.ServerTestBase): +class TestCheckALPNMismatch(net_tservers.ServerTestBase): handler = EchoHandler ssl = dict( alpn_select=None, @@ -99,7 +99,7 @@ class TestCheckALPNMismatch(netlib_tservers.ServerTestBase): protocol.check_alpn() -class TestPerformServerConnectionPreface(netlib_tservers.ServerTestBase): +class TestPerformServerConnectionPreface(net_tservers.ServerTestBase): class handler(tcp.BaseHandler): def handle(self): @@ -132,11 +132,11 @@ class TestPerformServerConnectionPreface(netlib_tservers.ServerTestBase): protocol.perform_server_connection_preface() assert protocol.connection_preface_performed - with raises(TcpDisconnect): + with raises(exceptions.TcpDisconnect): protocol.perform_server_connection_preface(force=True) -class TestPerformClientConnectionPreface(netlib_tservers.ServerTestBase): +class TestPerformClientConnectionPreface(net_tservers.ServerTestBase): class handler(tcp.BaseHandler): def handle(self): @@ -197,7 +197,7 @@ class TestserverstreamIds: assert self.protocol.current_stream_id == 6 -class TestApplySettings(netlib_tservers.ServerTestBase): +class TestApplySettings(net_tservers.ServerTestBase): class handler(tcp.BaseHandler): def handle(self): # check settings acknowledgement @@ -290,7 +290,7 @@ class TestCreateBody: assert bytes[2] == codecs.decode('0000020001000000013432', 'hex_codec') -class TestReadRequest(netlib_tservers.ServerTestBase): +class TestReadRequest(net_tservers.ServerTestBase): class handler(tcp.BaseHandler): def handle(self): @@ -320,7 +320,7 @@ class TestReadRequest(netlib_tservers.ServerTestBase): assert req.content == b'foobar' -class TestReadRequestRelative(netlib_tservers.ServerTestBase): +class TestReadRequestRelative(net_tservers.ServerTestBase): class handler(tcp.BaseHandler): def handle(self): self.wfile.write( @@ -343,7 +343,7 @@ class TestReadRequestRelative(netlib_tservers.ServerTestBase): assert req.path == "*" -class TestReadRequestAbsolute(netlib_tservers.ServerTestBase): +class TestReadRequestAbsolute(net_tservers.ServerTestBase): class handler(tcp.BaseHandler): def handle(self): self.wfile.write( @@ -367,7 +367,7 @@ class TestReadRequestAbsolute(netlib_tservers.ServerTestBase): assert req.port == 22 -class TestReadResponse(netlib_tservers.ServerTestBase): +class TestReadResponse(net_tservers.ServerTestBase): class handler(tcp.BaseHandler): def handle(self): self.wfile.write( @@ -396,7 +396,7 @@ class TestReadResponse(netlib_tservers.ServerTestBase): assert resp.timestamp_end -class TestReadEmptyResponse(netlib_tservers.ServerTestBase): +class TestReadEmptyResponse(net_tservers.ServerTestBase): class handler(tcp.BaseHandler): def handle(self): self.wfile.write( diff --git a/test/pathod/tutils.py b/test/pathod/tutils.py index c2243578..ccc3df43 100644 --- a/test/pathod/tutils.py +++ b/test/pathod/tutils.py @@ -5,9 +5,10 @@ import requests import io import urllib -from netlib import tcp -from netlib import utils -from netlib import tutils +from mitmproxy.utils import data + +from mitmproxy.net import tcp +from mitmproxy.test import tutils from pathod import language from pathod import pathoc @@ -142,7 +143,7 @@ tmpdir = tutils.tmpdir raises = tutils.raises -test_data = utils.Data(__name__) +test_data = data.Data(__name__) def render(r, settings=language.Settings()): |