aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/handler.py3
-rw-r--r--test/test_flow.py7
-rw-r--r--test/test_proxy.py74
-rw-r--r--test/test_server.py75
-rw-r--r--test/tutils.py2
5 files changed, 79 insertions, 82 deletions
diff --git a/test/handler.py b/test/handler.py
index 5803b4d1..8b717733 100644
--- a/test/handler.py
+++ b/test/handler.py
@@ -10,6 +10,7 @@ class TestRequestHandler(BaseHTTPRequestHandler):
self.wfile = socket._fileobject(self.request, "wb", self.wbufsize)
def log_message(self, *args, **kwargs):
+ # Silence output
pass
def do_GET(self):
@@ -21,5 +22,3 @@ class TestRequestHandler(BaseHTTPRequestHandler):
self.end_headers()
self.wfile.write(data)
-
-
diff --git a/test/test_flow.py b/test/test_flow.py
index 7bf82028..0969cc16 100644
--- a/test/test_flow.py
+++ b/test/test_flow.py
@@ -50,7 +50,7 @@ class uClientPlaybackState(libpry.AutoTree):
c.tick(fm, testing=True)
assert c.count() == 1
- c.clear(first)
+ c.clear(c.current)
c.tick(fm, testing=True)
assert c.count() == 0
@@ -419,9 +419,6 @@ class uFlowMaster(libpry.AutoTree):
assert tf.request.headers["cookie"] == ["foo=bar"]
-
-
-
tests = [
uStickyCookieState(),
uServerPlaybackState(),
@@ -429,5 +426,5 @@ tests = [
uFlow(),
uState(),
uSerialize(),
- uFlowMaster()
+ uFlowMaster(),
]
diff --git a/test/test_proxy.py b/test/test_proxy.py
index 00857586..e5b3ed16 100644
--- a/test/test_proxy.py
+++ b/test/test_proxy.py
@@ -1,75 +1,9 @@
-import urllib, urllib2, cStringIO
+import cStringIO
import libpry
from libmproxy import proxy, controller, utils, dump, script
import tutils
-class uSanity(tutils.ProxTest):
- def test_http(self):
- """
- Just check that the HTTP server is running.
- """
- f = urllib.urlopen("http://127.0.0.1:%s"%tutils.HTTP_PORT)
- assert f.read()
-
- def test_https(self):
- """
- Just check that the HTTPS server is running.
- """
- f = urllib.urlopen("https://127.0.0.1:%s"%tutils.HTTPS_PORT)
- assert f.read()
-
-
-class uProxy(tutils.ProxTest):
- HOST = "127.0.0.1"
- def _get(self, host=HOST):
- r = urllib2.Request("http://%s:%s"%(host, tutils.HTTP_PORT))
- r.set_proxy("127.0.0.1:%s"%tutils.PROXL_PORT, "http")
- return urllib2.urlopen(r)
-
- def _sget(self, host=HOST):
- proxy_support = urllib2.ProxyHandler(
- {"https" : "https://127.0.0.1:%s"%tutils.PROXL_PORT}
- )
- opener = urllib2.build_opener(proxy_support)
- r = urllib2.Request("https://%s:%s"%(host, tutils.HTTPS_PORT))
- return opener.open(r)
-
- def test_http(self):
- f = self._get()
- assert f.code == 200
- assert f.read()
- f.close()
-
- l = self.log()
- assert l[0].address
- assert l[1].headers.has_key("host")
- assert l[2].code == 200
-
- def test_https(self):
- f = self._sget()
- assert f.code == 200
- assert f.read()
- f.close()
-
- l = self.log()
- assert l[0].address
- assert l[1].headers.has_key("host")
- assert l[2].code == 200
-
- # Disable these two for now: they take a long time.
- def _test_http_nonexistent(self):
- f = self._get("nonexistent")
- assert f.code == 200
- assert "Error" in f.read()
-
- def _test_https_nonexistent(self):
- f = self._sget("nonexistent")
- assert f.code == 200
- assert "Error" in f.read()
-
-
-
class u_parse_request_line(libpry.AutoTree):
def test_simple(self):
libpry.raises(proxy.ProxyError, proxy.parse_request_line, "")
@@ -202,7 +136,6 @@ class uError(libpry.AutoTree):
assert e == e2
-
class uProxyError(libpry.AutoTree):
def test_simple(self):
p = proxy.ProxyError(111, "msg")
@@ -221,7 +154,6 @@ class uClientConnect(libpry.AutoTree):
assert c == c2
-
tests = [
uProxyError(),
uRequest(),
@@ -231,8 +163,4 @@ tests = [
u_parse_url(),
uError(),
uClientConnect(),
- tutils.TestServers(), [
- uSanity(),
- uProxy(),
- ],
]
diff --git a/test/test_server.py b/test/test_server.py
new file mode 100644
index 00000000..3559248e
--- /dev/null
+++ b/test/test_server.py
@@ -0,0 +1,75 @@
+import urllib, urllib2
+from libmproxy import flow
+import tutils
+
+class uSanity(tutils.ProxTest):
+ def test_http(self):
+ """
+ Just check that the HTTP server is running.
+ """
+ f = urllib.urlopen("http://127.0.0.1:%s"%tutils.HTTP_PORT)
+ assert f.read()
+
+ def test_https(self):
+ """
+ Just check that the HTTPS server is running.
+ """
+ f = urllib.urlopen("https://127.0.0.1:%s"%tutils.HTTPS_PORT)
+ assert f.read()
+
+
+class uProxy(tutils.ProxTest):
+ HOST = "127.0.0.1"
+ def _get(self, host=HOST):
+ r = urllib2.Request("http://%s:%s"%(host, tutils.HTTP_PORT))
+ r.set_proxy("127.0.0.1:%s"%tutils.PROXL_PORT, "http")
+ return urllib2.urlopen(r)
+
+ def _sget(self, host=HOST):
+ proxy_support = urllib2.ProxyHandler(
+ {"https" : "https://127.0.0.1:%s"%tutils.PROXL_PORT}
+ )
+ opener = urllib2.build_opener(proxy_support)
+ r = urllib2.Request("https://%s:%s"%(host, tutils.HTTPS_PORT))
+ return opener.open(r)
+
+ def test_http(self):
+ f = self._get()
+ assert f.code == 200
+ assert f.read()
+ f.close()
+
+ l = self.log()
+ assert l[0].address
+ assert l[1].headers.has_key("host")
+ assert l[2].code == 200
+
+ def test_https(self):
+ f = self._sget()
+ assert f.code == 200
+ assert f.read()
+ f.close()
+
+ l = self.log()
+ assert l[0].address
+ assert l[1].headers.has_key("host")
+ assert l[2].code == 200
+
+ # Disable these two for now: they take a long time.
+ def _test_http_nonexistent(self):
+ f = self._get("nonexistent")
+ assert f.code == 200
+ assert "Error" in f.read()
+
+ def _test_https_nonexistent(self):
+ f = self._sget("nonexistent")
+ assert f.code == 200
+ assert "Error" in f.read()
+
+
+tests = [
+ tutils.TestServers(), [
+ uSanity(),
+ uProxy(),
+ ]
+]
diff --git a/test/tutils.py b/test/tutils.py
index 99ed81a7..ec2c71a8 100644
--- a/test/tutils.py
+++ b/test/tutils.py
@@ -32,8 +32,6 @@ def tflow_full():
return f
-
-
# Yes, the random ports are horrible. During development, sockets are often not
# properly closed during error conditions, which means you have to wait until
# you can re-bind to the same port. This is a pain in the ass, so we just pick