aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/test_proxy.py15
-rw-r--r--test/tutils.py10
2 files changed, 24 insertions, 1 deletions
diff --git a/test/test_proxy.py b/test/test_proxy.py
index 614bb8b9..b33cdcfd 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
@@ -119,6 +119,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):
@@ -126,3 +132,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 \ No newline at end of file
diff --git a/test/tutils.py b/test/tutils.py
index dc049adb..05f65a21 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
@@ -185,4 +187,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__)