aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/test_proxy.py15
-rw-r--r--test/test_server.py19
-rw-r--r--test/tutils.py10
3 files changed, 39 insertions, 5 deletions
diff --git a/test/test_proxy.py b/test/test_proxy.py
index 2f455992..d13c7ba9 100644
--- a/test/test_proxy.py
+++ b/test/test_proxy.py
@@ -3,7 +3,7 @@ from libmproxy import cmdline
from libmproxy.proxy.config import process_proxy_options
from libmproxy.proxy.connection import ServerConnection
from libmproxy.proxy.primitives import ProxyError
-from libmproxy.proxy.server import DummyServer, ProxyServer
+from libmproxy.proxy.server import DummyServer, ProxyServer, ConnectionHandler
import tutils
from libpathod import test
from netlib import http, tcp
@@ -128,6 +128,12 @@ class TestProxyServer:
opts = parser.parse_args(args=[])
tutils.raises("error starting proxy server", ProxyServer, opts, 1)
+ def test_err_2(self):
+ parser = argparse.ArgumentParser()
+ cmdline.common_options(parser)
+ opts = parser.parse_args(args=[])
+ tutils.raises("error starting proxy server", ProxyServer, opts, 8080, "invalidhost")
+
class TestDummyServer:
def test_simple(self):
@@ -135,3 +141,10 @@ class TestDummyServer:
d.start_slave()
d.shutdown()
+
+class TestConnectionHandler:
+ def test_fatal_error(self):
+ config = dict(get_upstream_server=mock.Mock(side_effect=RuntimeError))
+ c = ConnectionHandler(config, mock.MagicMock(), ("127.0.0.1", 8080), None, mock.MagicMock(), None)
+ with tutils.capture_stderr(c.handle) as output:
+ assert "mitmproxy has crashed" in output
diff --git a/test/test_server.py b/test/test_server.py
index a6d591ed..d33bcc89 100644
--- a/test/test_server.py
+++ b/test/test_server.py
@@ -199,11 +199,22 @@ class TestHTTP(tservers.HTTPProxTest, CommonMixin, AppMixin):
connection.connect(("127.0.0.1", self.proxy.port))
spec = '301:h"Transfer-Encoding"="chunked":r:b"0\\r\\n\\r\\n"'
connection.send("GET http://localhost:%d/p/%s HTTP/1.1\r\n"%(self.server.port, spec))
- connection.send("\r\n");
+ connection.send("\r\n")
resp = connection.recv(50000)
connection.close()
assert "content-length" in resp.lower()
+ def test_stream(self):
+ self.master.set_stream_large_bodies(1024 * 2)
+
+ self.pathod("200:b@1k")
+ assert not self.master.state.view[-1].response.stream
+ assert len(self.master.state.view[-1].response.content) == 1024 * 1
+
+ self.pathod("200:b@3k")
+ assert self.master.state.view[-1].response.stream
+ assert self.master.state.view[-1].response.content == CONTENT_MISSING
+ self.master.set_stream_large_bodies(None)
class TestHTTPAuth(tservers.HTTPProxTest):
authenticator = http_auth.BasicProxyAuth(http_auth.PassManSingleUser("test", "test"), "realm")
@@ -313,7 +324,7 @@ class TestProxy(tservers.HTTPProxTest):
# call pathod server, wait a second to complete the request
connection.send("GET http://localhost:%d/p/304:b@1k HTTP/1.1\r\n"%self.server.port)
time.sleep(1)
- connection.send("\r\n");
+ connection.send("\r\n")
connection.recv(50000)
connection.close()
@@ -340,10 +351,10 @@ class TestProxy(tservers.HTTPProxTest):
connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
connection.connect(("localhost", self.proxy.port))
connection.send("GET http://localhost:%d/p/304:b@1k HTTP/1.1\r\n"%self.server.port)
- connection.send("\r\n");
+ connection.send("\r\n")
connection.recv(5000)
connection.send("GET http://localhost:%d/p/304:b@1k HTTP/1.1\r\n"%self.server.port)
- connection.send("\r\n");
+ connection.send("\r\n")
connection.recv(5000)
connection.close()
diff --git a/test/tutils.py b/test/tutils.py
index 84a9bba0..69f79a91 100644
--- a/test/tutils.py
+++ b/test/tutils.py
@@ -1,5 +1,7 @@
+from cStringIO import StringIO
import os, shutil, tempfile, argparse
from contextlib import contextmanager
+import sys
from libmproxy import flow, utils, controller
from libmproxy.protocol import http
from libmproxy.proxy.connection import ClientConnection, ServerConnection
@@ -189,4 +191,12 @@ def raises(exc, obj, *args, **kwargs):
)
raise AssertionError("No exception raised.")
+
+@contextmanager
+def capture_stderr(command, *args, **kwargs):
+ out, sys.stderr = sys.stderr, StringIO()
+ command(*args, **kwargs)
+ yield sys.stderr.getvalue()
+ sys.stderr = out
+
test_data = utils.Data(__name__)