diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/mitmproxy/protocol/test_http2.py | 28 | ||||
-rw-r--r-- | test/mitmproxy/protocol/test_websockets.py | 11 | ||||
-rw-r--r-- | test/mitmproxy/test_proxy.py | 4 | ||||
-rw-r--r-- | test/mitmproxy/test_server.py | 2 | ||||
-rw-r--r-- | test/mitmproxy/tservers.py | 7 | ||||
-rw-r--r-- | test/netlib/http/http1/test_assemble.py | 6 | ||||
-rw-r--r-- | test/netlib/http/http1/test_read.py | 55 | ||||
-rw-r--r-- | test/netlib/test_tcp.py | 2 | ||||
-rw-r--r-- | test/pathod/test_log.py | 4 | ||||
-rw-r--r-- | test/pathod/test_pathoc.py | 4 | ||||
-rw-r--r-- | test/pathod/test_pathod.py | 10 | ||||
-rw-r--r-- | test/pathod/test_protocols_http2.py | 4 |
12 files changed, 69 insertions, 68 deletions
diff --git a/test/mitmproxy/protocol/test_http2.py b/test/mitmproxy/protocol/test_http2.py index a2efdc47..b624489f 100644 --- a/test/mitmproxy/protocol/test_http2.py +++ b/test/mitmproxy/protocol/test_http2.py @@ -13,7 +13,7 @@ from mitmproxy.proxy.config import ProxyConfig import netlib from ...netlib import tservers as netlib_tservers -from netlib.exceptions import HttpException +from mitmproxy import exceptions from netlib.http import http1, http2 from .. import tservers @@ -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 @@ -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..f22e95d5 100644 --- a/test/mitmproxy/protocol/test_websockets.py +++ b/test/mitmproxy/protocol/test_websockets.py @@ -4,6 +4,7 @@ import tempfile import traceback from mitmproxy import options +from mitmproxy import exceptions from mitmproxy.proxy.config import ProxyConfig import netlib @@ -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/mitmproxy/test_proxy.py b/test/mitmproxy/test_proxy.py index 7d401184..c0d978d2 100644 --- a/test/mitmproxy/test_proxy.py +++ b/test/mitmproxy/test_proxy.py @@ -8,7 +8,7 @@ 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 . 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 cadc67a8..79fd6f86 100644 --- a/test/mitmproxy/test_server.py +++ b/test/mitmproxy/test_server.py @@ -12,7 +12,7 @@ import netlib.http from netlib import tcp from netlib import socks from mitmproxy import certs -from netlib import exceptions +from mitmproxy import exceptions from netlib.http import authentication from netlib.http import http1 from netlib.tcp import Address 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/netlib/http/http1/test_assemble.py b/test/netlib/http/http1/test_assemble.py index 5d7e007e..d5a5e5fb 100644 --- a/test/netlib/http/http1/test_assemble.py +++ b/test/netlib/http/http1/test_assemble.py @@ -1,4 +1,4 @@ -from netlib.exceptions import HttpException +from mitmproxy import exceptions from netlib.http import Headers from netlib.http.http1.assemble import ( assemble_request, assemble_request_head, assemble_response, @@ -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/netlib/http/http1/test_read.py index f25cd3e2..9777e2e2 100644 --- a/test/netlib/http/http1/test_read.py +++ b/test/netlib/http/http1/test_read.py @@ -2,7 +2,7 @@ from io import BytesIO from mock import Mock import pytest -from netlib.exceptions import HttpException, HttpSyntaxException, HttpReadDisconnect, TcpDisconnect +from mitmproxy import exceptions from netlib.http import Headers from netlib.http.http1.read import ( read_request, read_response, read_request_head, @@ -11,7 +11,6 @@ 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(): @@ -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/test_tcp.py b/test/netlib/test_tcp.py index 2c1b92dc..d61e1d91 100644 --- a/test/netlib/test_tcp.py +++ b/test/netlib/test_tcp.py @@ -12,7 +12,7 @@ from OpenSSL import SSL from mitmproxy import certs from netlib import tcp from netlib import tutils -from netlib import exceptions +from mitmproxy import exceptions from . import tservers 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..d26eb15d 100644 --- a/test/pathod/test_pathoc.py +++ b/test/pathod/test_pathoc.py @@ -3,9 +3,9 @@ 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 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..402cd638 100644 --- a/test/pathod/test_pathod.py +++ b/test/pathod/test_pathod.py @@ -2,7 +2,7 @@ import io from pathod import pathod from netlib import tcp -from netlib.exceptions import HttpException, TlsException +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..bb69bd10 100644 --- a/test/pathod/test_protocols_http2.py +++ b/test/pathod/test_protocols_http2.py @@ -4,8 +4,8 @@ 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 import exceptions from ..netlib import tservers as netlib_tservers @@ -132,7 +132,7 @@ 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) |