aboutsummaryrefslogtreecommitdiffstats
path: root/test/tutils.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2012-06-09 20:41:28 +1200
committerAldo Cortesi <aldo@nullcube.com>2012-06-09 20:41:28 +1200
commit18c1b444759b38d1a2643c908bfd6cab0e016e69 (patch)
tree8bc5397957d148cd2fb21c223d9661ca5890a7f4 /test/tutils.py
parent05492baf8d2c970c5e5c3d207549893490ead751 (diff)
downloadmitmproxy-18c1b444759b38d1a2643c908bfd6cab0e016e69.tar.gz
mitmproxy-18c1b444759b38d1a2643c908bfd6cab0e016e69.tar.bz2
mitmproxy-18c1b444759b38d1a2643c908bfd6cab0e016e69.zip
Reverse proxy testing.
Diffstat (limited to 'test/tutils.py')
-rw-r--r--test/tutils.py53
1 files changed, 38 insertions, 15 deletions
diff --git a/test/tutils.py b/test/tutils.py
index e1bb49a5..5f4739c6 100644
--- a/test/tutils.py
+++ b/test/tutils.py
@@ -43,8 +43,8 @@ def tflow_err():
class TestMaster(controller.Master):
- def __init__(self, port, testq):
- s = proxy.ProxyServer(proxy.ProxyConfig(test_data.path("data/testkey.pem")), port)
+ def __init__(self, port, testq, config):
+ s = proxy.ProxyServer(config, port)
controller.Master.__init__(self, s)
self.testq = testq
self.log = []
@@ -58,9 +58,9 @@ class TestMaster(controller.Master):
class ProxyThread(threading.Thread):
- def __init__(self, testq):
+ def __init__(self, testq, config):
self.port = random.randint(10000, 20000)
- self.tmaster = TestMaster(self.port, testq)
+ self.tmaster = TestMaster(self.port, testq, config)
controller.should_exit = False
threading.Thread.__init__(self)
@@ -85,14 +85,25 @@ class ServerThread(threading.Thread):
class ProxTest:
ssl = None
+ reverse = False
@classmethod
def setupAll(cls):
cls.tqueue = Queue.Queue()
- # We don't make any concurrent requests, so we can access
- # the attributes on this object safely.
- cls.proxy = ProxyThread(cls.tqueue)
- cls.proxy.start()
cls.server = libpathod.test.Daemon(ssl=cls.ssl)
+ if cls.reverse:
+ reverse_proxy = (
+ "https" if cls.ssl else "http",
+ "127.0.0.1",
+ cls.server.port
+ )
+ else:
+ reverse_proxy = None
+ config = proxy.ProxyConfig(
+ certfile=test_data.path("data/testkey.pem"),
+ reverse_proxy = reverse_proxy
+ )
+ cls.proxy = ProxyThread(cls.tqueue, config)
+ cls.proxy.start()
@classmethod
def teardownAll(cls):
@@ -106,12 +117,24 @@ class ProxTest:
"""
Constructs a pathod request, with the appropriate base and proxy.
"""
- return hurl.get(
- self.urlbase + "/p/" + spec,
- proxy=self.proxies,
- validate_cert=False,
- #debug=hurl.utils.stdout_debug
- )
+ if self.reverse:
+ r = hurl.get(
+ "http://127.0.0.1:%s"%self.proxy.port + "/p/" + spec,
+ validate_cert=False,
+ #debug=hurl.utils.stdout_debug
+ )
+ return r
+ else:
+ return hurl.get(
+ self.urlbase + "/p/" + spec,
+ proxy=self.proxies,
+ validate_cert=False,
+ #debug=hurl.utils.stdout_debug
+ )
+
+ @property
+ def scheme(self):
+ return "https" if self.ssl else "http"
@property
def proxies(self):
@@ -119,7 +142,7 @@ class ProxTest:
The URL base for the server instance.
"""
return (
- ("https" if self.ssl else "http", ("127.0.0.1", self.proxy.port))
+ (self.scheme, ("127.0.0.1", self.proxy.port))
)
@property