aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2012-06-07 17:02:17 +1200
committerAldo Cortesi <aldo@nullcube.com>2012-06-07 17:02:17 +1200
commita29ebe31dc86462398ed8d5910cd700fb49571d3 (patch)
treef1bb5075086a434e2107ec461aef7a5155dc7e6e
parent81fc990314e1f251f12e22b029cb20a64947f150 (diff)
downloadmitmproxy-a29ebe31dc86462398ed8d5910cd700fb49571d3.tar.gz
mitmproxy-a29ebe31dc86462398ed8d5910cd700fb49571d3.tar.bz2
mitmproxy-a29ebe31dc86462398ed8d5910cd700fb49571d3.zip
SSL support for test struss.
Also, rewrite requests usage for latest version.
-rw-r--r--libpathod/test.py29
-rw-r--r--test/test_test.py28
2 files changed, 41 insertions, 16 deletions
diff --git a/libpathod/test.py b/libpathod/test.py
index 53cbd8d5..508605bf 100644
--- a/libpathod/test.py
+++ b/libpathod/test.py
@@ -1,36 +1,41 @@
import json, threading, Queue
import requests
-import pathod
+import pathod, utils
IFACE = "127.0.0.1"
class Daemon:
- def __init__(self, staticdir=None, anchors=()):
+ def __init__(self, staticdir=None, anchors=(), ssl=None):
self.app = pathod.make_app(staticdir=staticdir, anchors=anchors)
self.q = Queue.Queue()
- self.thread = PaThread(self.q, self.app)
+ self.thread = PaThread(self.q, self.app, ssl)
self.thread.start()
self.port = self.q.get(True, 5)
- self.urlbase = "http://%s:%s"%(IFACE, self.port)
+ self.urlbase = "%s://%s:%s"%("https" if ssl else "http", IFACE, self.port)
def info(self):
- resp = requests.get("%s/api/info"%self.urlbase)
- if resp.ok:
- return json.loads(resp.read())
+ resp = requests.get("%s/api/info"%self.urlbase, verify=False)
+ return resp.json
def shutdown(self):
- requests.post("%s/api/shutdown"%self.urlbase)
+ requests.post("%s/api/shutdown"%self.urlbase, verify=False)
class PaThread(threading.Thread):
- def __init__(self, q, app):
+ def __init__(self, q, app, ssl):
threading.Thread.__init__(self)
- self.q = q
- self.app = app
+ self.q, self.app, self.ssl = q, app, ssl
self.port = None
# begin nocover
def run(self):
- self.server, self.port = pathod.make_server(self.app, 0, IFACE, None)
+ if self.ssl is True:
+ ssloptions = dict(
+ keyfile = utils.data.path("resources/server.key"),
+ certfile = utils.data.path("resources/server.crt"),
+ )
+ else:
+ ssloptions = self.ssl
+ self.server, self.port = pathod.make_server(self.app, 0, IFACE, ssloptions)
self.q.put(self.port)
pathod.run(self.server)
diff --git a/test/test_test.py b/test/test_test.py
index c10cee4c..086f3dfc 100644
--- a/test/test_test.py
+++ b/test/test_test.py
@@ -1,8 +1,9 @@
-import time
+import time, logging
import libpry
import requests
-from libpathod import test, version
+from libpathod import test, version, utils
+logging.disable(logging.CRITICAL)
class uDaemonManual(libpry.AutoTree):
def test_startstop(self):
@@ -11,8 +12,27 @@ class uDaemonManual(libpry.AutoTree):
assert rsp.ok
assert rsp.status_code == 202
d.shutdown()
- rsp = requests.get("http://localhost:%s/p/202"%d.port)
- assert not rsp.ok
+ libpry.raises(requests.ConnectionError, requests.get, "http://localhost:%s/p/202"%d.port)
+
+ def test_startstop_ssl(self):
+ d = test.Daemon(ssl=True)
+ rsp = requests.get("https://localhost:%s/p/202"%d.port, verify=False)
+ assert rsp.ok
+ assert rsp.status_code == 202
+ d.shutdown()
+ libpry.raises(requests.ConnectionError, requests.get, "http://localhost:%s/p/202"%d.port)
+
+ def test_startstop_ssl_explicit(self):
+ ssloptions = dict(
+ keyfile = utils.data.path("resources/server.key"),
+ certfile = utils.data.path("resources/server.crt"),
+ )
+ d = test.Daemon(ssl=ssloptions)
+ rsp = requests.get("https://localhost:%s/p/202"%d.port, verify=False)
+ assert rsp.ok
+ assert rsp.status_code == 202
+ d.shutdown()
+ libpry.raises(requests.ConnectionError, requests.get, "http://localhost:%s/p/202"%d.port)
class uDaemon(libpry.AutoTree):