aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2013-03-03 12:13:33 +1300
committerAldo Cortesi <aldo@nullcube.com>2013-03-03 12:13:33 +1300
commit2465b8a376a7eb04eef6a1cce46dd11a8f1830d8 (patch)
tree7f2cebe563ec824af8ad72eef982f745c5e4bc12
parentd5876a12ed09940df77da823bf857437f7496524 (diff)
downloadmitmproxy-2465b8a376a7eb04eef6a1cce46dd11a8f1830d8.tar.gz
mitmproxy-2465b8a376a7eb04eef6a1cce46dd11a8f1830d8.tar.bz2
mitmproxy-2465b8a376a7eb04eef6a1cce46dd11a8f1830d8.zip
100% unit test coverage on proxy.py. Hallelujah!
-rw-r--r--libmproxy/proxy.py7
-rw-r--r--test/test_proxy.py16
-rw-r--r--test/test_server.py18
3 files changed, 34 insertions, 7 deletions
diff --git a/libmproxy/proxy.py b/libmproxy/proxy.py
index 9fe878a9..75e195ea 100644
--- a/libmproxy/proxy.py
+++ b/libmproxy/proxy.py
@@ -504,10 +504,7 @@ class ProxyServer(tcp.TCPServer):
def handle_connection(self, request, client_address):
h = ProxyHandler(self.config, request, client_address, self, self.channel, self.server_version)
h.handle()
- try:
- h.finish()
- except tcp.NetLibDisconnect, e:
- pass
+ h.finish()
def handle_shutdown(self):
self.config.certstore.cleanup()
@@ -540,7 +537,7 @@ class DummyServer:
def __init__(self, config):
self.config = config
- def start_slave(self, klass, channel):
+ def start_slave(self, *args):
pass
def shutdown(self):
diff --git a/test/test_proxy.py b/test/test_proxy.py
index 098a8d63..13feaead 100644
--- a/test/test_proxy.py
+++ b/test/test_proxy.py
@@ -69,7 +69,7 @@ class MockParser:
def __repr__(self):
return "ParseError(%s)"%self.err
-
+
class TestProcessProxyOptions:
def p(self, *args):
@@ -132,4 +132,18 @@ class TestProcessProxyOptions:
self.assert_err("invalid single-user specification", "--singleuser", "test")
+class TestProxyServer:
+ def test_err(self):
+ parser = argparse.ArgumentParser()
+ cmdline.common_options(parser)
+ opts = parser.parse_args(args=[])
+ tutils.raises("error starting proxy server", proxy.ProxyServer, opts, 1)
+
+
+class TestDummyServer:
+ def test_simple(self):
+ d = proxy.DummyServer(None)
+ d.start_slave()
+ d.shutdown()
+
diff --git a/test/test_server.py b/test/test_server.py
index 8a6228ad..cc1fa8ce 100644
--- a/test/test_server.py
+++ b/test/test_server.py
@@ -277,7 +277,7 @@ class MasterFakeResponse(tservers.TestMaster):
class TestFakeResponse(tservers.HTTPProxTest):
masterclass = MasterFakeResponse
- def test_kill(self):
+ def test_fake(self):
f = self.pathod("200")
assert "header_response" in f.headers.keys()
@@ -319,3 +319,19 @@ class TestTransparentResolveError(tservers.TransparentProxTest):
def test_resolve_error(self):
assert self.pathod("304").status_code == 502
+
+
+class MasterIncomplete(tservers.TestMaster):
+ def handle_request(self, m):
+ resp = tutils.tresp()
+ resp.content = flow.CONTENT_MISSING
+ m.reply(resp)
+
+
+class TestIncompleteResponse(tservers.HTTPProxTest):
+ masterclass = MasterIncomplete
+ def test_incomplete(self):
+ assert self.pathod("200").status_code == 502
+
+
+