aboutsummaryrefslogtreecommitdiffstats
path: root/test/tutils.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2012-06-15 09:20:10 +1200
committerAldo Cortesi <aldo@nullcube.com>2012-06-15 09:20:10 +1200
commita9495dc02fa0942d82e1247f875bb962872e8802 (patch)
treec52e505036f15650e78c2c327e8f617f30c6a289 /test/tutils.py
parent176d819559e01125c6fe2a34c86cb47c62f49b27 (diff)
downloadmitmproxy-a9495dc02fa0942d82e1247f875bb962872e8802.tar.gz
mitmproxy-a9495dc02fa0942d82e1247f875bb962872e8802.tar.bz2
mitmproxy-a9495dc02fa0942d82e1247f875bb962872e8802.zip
Refactor test suite to make room for transparent mode tests.
Diffstat (limited to 'test/tutils.py')
-rw-r--r--test/tutils.py77
1 files changed, 46 insertions, 31 deletions
diff --git a/test/tutils.py b/test/tutils.py
index 2fdf51a8..2556a57b 100644
--- a/test/tutils.py
+++ b/test/tutils.py
@@ -83,24 +83,15 @@ class ServerThread(threading.Thread):
self.server.shutdown()
-class ProxTest:
- ssl = None
- reverse = False
+class ProxTestBase:
@classmethod
def setupAll(cls):
cls.tqueue = Queue.Queue()
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
+ pconf = cls.get_proxy_config()
config = proxy.ProxyConfig(
certfile=test_data.path("data/testkey.pem"),
- reverse_proxy = reverse_proxy
+ **pconf
)
cls.proxy = ProxyThread(cls.tqueue, config)
cls.proxy.start()
@@ -113,25 +104,6 @@ class ProxTest:
def setUp(self):
self.proxy.tmaster.clear()
- def pathod(self, spec):
- """
- Constructs a pathod request, with the appropriate base and proxy.
- """
- 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"
@@ -157,6 +129,49 @@ class ProxTest:
return pthread.tmaster.log
+class HTTPProxTest(ProxTestBase):
+ ssl = None
+ @classmethod
+ def get_proxy_config(cls):
+ return dict()
+
+ def pathod(self, spec):
+ """
+ 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
+ )
+
+
+class ReverseProxTest(ProxTestBase):
+ ssl = None
+ @classmethod
+ def get_proxy_config(cls):
+ return dict(
+ reverse_proxy = (
+ "https" if cls.ssl else "http",
+ "127.0.0.1",
+ cls.server.port
+ )
+ )
+
+ def pathod(self, spec):
+ """
+ Constructs a pathod request, with the appropriate base and proxy.
+ """
+ r = hurl.get(
+ "http://127.0.0.1:%s"%self.proxy.port + "/p/" + spec,
+ validate_cert=False,
+ #debug=hurl.utils.stdout_debug
+ )
+ return r
+
+
+
@contextmanager
def tmpdir(*args, **kwargs):
orig_workdir = os.getcwd()