aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2013-01-05 19:44:12 -0800
committerAldo Cortesi <aldo@nullcube.com>2013-01-05 19:44:12 -0800
commitd0ee4d60d09c607a208ae1b190e619a4f106538e (patch)
treed61b69df2c120f1100e9639072f3b1d8d2231558 /test
parent060e3198bca48f327984b2d1d73a5d4592866736 (diff)
downloadmitmproxy-d0ee4d60d09c607a208ae1b190e619a4f106538e.tar.gz
mitmproxy-d0ee4d60d09c607a208ae1b190e619a4f106538e.tar.bz2
mitmproxy-d0ee4d60d09c607a208ae1b190e619a4f106538e.zip
Unit tests and minor code refactoring for ServerConnection.
Diffstat (limited to 'test')
-rw-r--r--test/test_proxy.py32
-rw-r--r--test/test_server.py24
-rw-r--r--test/tutils.py5
3 files changed, 51 insertions, 10 deletions
diff --git a/test/test_proxy.py b/test/test_proxy.py
index e137c687..89e5a825 100644
--- a/test/test_proxy.py
+++ b/test/test_proxy.py
@@ -1,5 +1,7 @@
-from libmproxy import proxy
+from libmproxy import proxy, flow
import tutils
+from libpathod import test
+from netlib import http
def test_proxy_error():
@@ -26,3 +28,31 @@ def test_app_registry():
assert not ar.get(r)
r.headers["host"] = ["domain"]
assert ar.get(r)
+
+
+
+class TestServerConnection:
+ def setUp(self):
+ self.d = test.Daemon()
+
+ def tearDown(self):
+ self.d.shutdown()
+
+ def test_simple(self):
+ sc = proxy.ServerConnection(proxy.ProxyConfig(), self.d.IFACE, self.d.port)
+ sc.connect("http")
+ r = tutils.treq()
+ r.path = "/p/200:da"
+ sc.send(r)
+ assert http.read_response(sc.rfile, r.method, 1000)
+ assert self.d.last_log()
+
+ r.content = flow.CONTENT_MISSING
+ tutils.raises("incomplete request", sc.send, r)
+
+ def test_send_error(self):
+ sc = proxy.ServerConnection(proxy.ProxyConfig(), self.d.IFACE, self.d.port)
+ sc.connect("http")
+ r = tutils.treq()
+ sc.send(r)
+
diff --git a/test/test_server.py b/test/test_server.py
index 38d33d90..ba263e96 100644
--- a/test/test_server.py
+++ b/test/test_server.py
@@ -1,4 +1,5 @@
from netlib import tcp
+from libpathod import pathoc
import tutils
"""
@@ -52,6 +53,20 @@ class TestHTTP(tutils.HTTPProxTest, SanityMixin):
t.wfile.flush()
assert "Bad Request" in t.rfile.readline()
+ def test_upstream_ssl_error(self):
+ p = self.pathoc()
+ ret = p.request("get:'https://localhost:%s/'"%self.server.port)
+ assert ret[1] == 400
+
+ def test_http(self):
+ f = self.pathod("304")
+ assert f.status_code == 304
+
+ l = self.master.state.view[0]
+ assert l.request.client_conn.address
+ assert "host" in l.request.headers
+ assert l.response.code == 304
+
class TestHTTPS(tutils.HTTPProxTest, SanityMixin):
ssl = True
@@ -65,12 +80,3 @@ class TestTransparent(tutils.TransparentProxTest, SanityMixin):
transparent = True
-class TestProxy(tutils.HTTPProxTest):
- def test_http(self):
- f = self.pathod("304")
- assert f.status_code == 304
-
- l = self.master.state.view[0]
- assert l.request.client_conn.address
- assert "host" in l.request.headers
- assert l.response.code == 304
diff --git a/test/tutils.py b/test/tutils.py
index 5ce56cb4..9b5ac0f1 100644
--- a/test/tutils.py
+++ b/test/tutils.py
@@ -127,6 +127,11 @@ class HTTPProxTest(ProxTestBase):
def get_proxy_config(cls):
return dict()
+ def pathoc(self, connect_to = None):
+ p = libpathod.pathoc.Pathoc("localhost", self.proxy.port)
+ p.connect(connect_to)
+ return p
+
def pathod(self, spec):
"""
Constructs a pathod request, with the appropriate base and proxy.