diff options
author | Thomas Kriechbaumer <Kriechi@users.noreply.github.com> | 2017-02-24 21:39:13 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-24 21:39:13 +0100 |
commit | e89c7857196c879e77a9eb675f650b37d15dccea (patch) | |
tree | 73ff04054b280a3f725317a01a399c350ad66c70 | |
parent | 6d9560df1d68b6891b77034ab975a1e2ddb12e5d (diff) | |
download | mitmproxy-e89c7857196c879e77a9eb675f650b37d15dccea.tar.gz mitmproxy-e89c7857196c879e77a9eb675f650b37d15dccea.tar.bz2 mitmproxy-e89c7857196c879e77a9eb675f650b37d15dccea.zip |
move tests around (#2058)
-rw-r--r-- | test/mitmproxy/test_connections.py | 68 | ||||
-rw-r--r-- | test/mitmproxy/test_flow.py | 22 | ||||
-rw-r--r-- | test/mitmproxy/test_proxy.py | 45 |
3 files changed, 68 insertions, 67 deletions
diff --git a/test/mitmproxy/test_connections.py b/test/mitmproxy/test_connections.py index 777ab4dd..fa23a53c 100644 --- a/test/mitmproxy/test_connections.py +++ b/test/mitmproxy/test_connections.py @@ -1 +1,67 @@ -# TODO: write tests +from unittest import mock + +from mitmproxy import connections +from mitmproxy import exceptions +from mitmproxy.net.http import http1 +from mitmproxy.test import tflow +from pathod import test + + +class TestClientConnection: + def test_state(self): + c = tflow.tclient_conn() + assert connections.ClientConnection.from_state(c.get_state()).get_state() == \ + c.get_state() + + c2 = tflow.tclient_conn() + c2.address = (c2.address[0], 4242) + assert not c == c2 + + c2.timestamp_start = 42 + c.set_state(c2.get_state()) + assert c.timestamp_start == 42 + + c3 = c.copy() + assert c3.get_state() == c.get_state() + + assert str(c) + + +class TestServerConnection: + + def test_simple(self): + self.d = test.Daemon() + sc = connections.ServerConnection((self.d.IFACE, self.d.port)) + sc.connect() + f = tflow.tflow() + f.server_conn = sc + f.request.path = "/p/200:da" + + # use this protocol just to assemble - not for actual sending + sc.wfile.write(http1.assemble_request(f.request)) + sc.wfile.flush() + + assert http1.read_response(sc.rfile, f.request, 1000) + assert self.d.last_log() + + sc.finish() + self.d.shutdown() + + def test_terminate_error(self): + self.d = test.Daemon() + sc = connections.ServerConnection((self.d.IFACE, self.d.port)) + sc.connect() + sc.connection = mock.Mock() + sc.connection.recv = mock.Mock(return_value=False) + sc.connection.flush = mock.Mock(side_effect=exceptions.TcpDisconnect) + sc.finish() + self.d.shutdown() + + def test_repr(self): + sc = tflow.tserver_conn() + assert "address:22" in repr(sc) + assert "ssl" not in repr(sc) + sc.ssl_established = True + assert "ssl" in repr(sc) + sc.sni = "foo" + assert "foo" in repr(sc) diff --git a/test/mitmproxy/test_flow.py b/test/mitmproxy/test_flow.py index f289afa8..c9b8ab96 100644 --- a/test/mitmproxy/test_flow.py +++ b/test/mitmproxy/test_flow.py @@ -9,7 +9,6 @@ from mitmproxy.contrib import tnetstring from mitmproxy.exceptions import FlowReadException, Kill from mitmproxy import flow from mitmproxy import http -from mitmproxy import connections from mitmproxy.proxy import ProxyConfig from mitmproxy.proxy.server import DummyServer from mitmproxy import master @@ -409,23 +408,4 @@ class TestError: def test_repr(self): e = flow.Error("yay") assert repr(e) - - -class TestClientConnection: - def test_state(self): - c = tflow.tclient_conn() - assert connections.ClientConnection.from_state(c.get_state()).get_state() == \ - c.get_state() - - c2 = tflow.tclient_conn() - c2.address = (c2.address[0], 4242) - assert not c == c2 - - c2.timestamp_start = 42 - c.set_state(c2.get_state()) - assert c.timestamp_start == 42 - - c3 = c.copy() - assert c3.get_state() == c.get_state() - - assert str(c) + assert str(e) diff --git a/test/mitmproxy/test_proxy.py b/test/mitmproxy/test_proxy.py index d2615840..37cec57a 100644 --- a/test/mitmproxy/test_proxy.py +++ b/test/mitmproxy/test_proxy.py @@ -4,62 +4,17 @@ from unittest import mock from OpenSSL import SSL import pytest -from mitmproxy.test import tflow from mitmproxy.tools import cmdline from mitmproxy import options from mitmproxy.proxy import ProxyConfig -from mitmproxy import connections from mitmproxy.proxy.server import DummyServer, ProxyServer, ConnectionHandler from mitmproxy.proxy import config -from mitmproxy import exceptions -from pathod import test -from mitmproxy.net.http import http1 from mitmproxy.test import tutils from ..conftest import skip_windows -class TestServerConnection: - - def test_simple(self): - self.d = test.Daemon() - sc = connections.ServerConnection((self.d.IFACE, self.d.port)) - sc.connect() - f = tflow.tflow() - f.server_conn = sc - f.request.path = "/p/200:da" - - # use this protocol just to assemble - not for actual sending - sc.wfile.write(http1.assemble_request(f.request)) - sc.wfile.flush() - - assert http1.read_response(sc.rfile, f.request, 1000) - assert self.d.last_log() - - sc.finish() - self.d.shutdown() - - def test_terminate_error(self): - self.d = test.Daemon() - sc = connections.ServerConnection((self.d.IFACE, self.d.port)) - sc.connect() - sc.connection = mock.Mock() - sc.connection.recv = mock.Mock(return_value=False) - sc.connection.flush = mock.Mock(side_effect=exceptions.TcpDisconnect) - sc.finish() - self.d.shutdown() - - def test_repr(self): - sc = tflow.tserver_conn() - assert "address:22" in repr(sc) - assert "ssl" not in repr(sc) - sc.ssl_established = True - assert "ssl" in repr(sc) - sc.sni = "foo" - assert "foo" in repr(sc) - - class MockParser(argparse.ArgumentParser): """ |