aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2014-02-07 02:36:39 +0100
committerMaximilian Hils <git@maximilianhils.com>2014-02-07 02:36:39 +0100
commit9f5f2b707165d14cbf0ace9a55ec2d1dc44d9802 (patch)
treefaaabe2a4ec11607076217bacca1b9d8ae866b23 /test
parent66090f9aea01094a42c53c762ae5852b7ee91e86 (diff)
downloadmitmproxy-9f5f2b707165d14cbf0ace9a55ec2d1dc44d9802.tar.gz
mitmproxy-9f5f2b707165d14cbf0ace9a55ec2d1dc44d9802.tar.bz2
mitmproxy-9f5f2b707165d14cbf0ace9a55ec2d1dc44d9802.zip
test libmproxy.app, increase coverage
Diffstat (limited to 'test')
-rw-r--r--test/test_app.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/test/test_app.py b/test/test_app.py
new file mode 100644
index 00000000..1ae81fc7
--- /dev/null
+++ b/test/test_app.py
@@ -0,0 +1,50 @@
+import mock, socket, os, sys
+from libmproxy import dump
+from netlib import certutils
+from libpathod.pathoc import Pathoc
+import tutils
+
+def get_free_port():
+ s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ s.bind(("127.0.0.1", 0))
+ port = s.getsockname()[1]
+ s.close()
+ return port
+
+
+class AppTestMixin(object):
+ def request(self, spec):
+ p = Pathoc(("127.0.0.1", self.port))
+ p.connect()
+ return p.request(spec)
+
+ def test_basic(self):
+ assert self.request("get:/").status_code == 200
+ assert self.request("get:/").status_code == 200 # Check for connection close
+ assert len(self.m.apps.apps) == 0
+
+ def test_cert(self):
+ with tutils.tmpdir() as d:
+ # Create Certs
+ path = os.path.join(d, "test")
+ assert certutils.dummy_ca(path)
+ self.m.server.config.cacert = path
+
+ for ext in ["pem", "p12"]:
+ resp = self.request("get:/cert/%s" % ext)
+ assert resp.status_code == 200
+ with open(path + "-cert.%s" % ext, "rb") as f:
+ assert resp.content == f.read()
+
+class TestAppExternal(AppTestMixin):
+ @classmethod
+ def setupAll(cls):
+ cls.port = get_free_port()
+ o = dump.Options(app=True, app_external=True, app_host="127.0.0.1", app_port=cls.port)
+ s = mock.MagicMock()
+ cls.m = dump.DumpMaster(s, o, None)
+
+
+ @classmethod
+ def teardownAll(cls):
+ cls.m.shutdown() \ No newline at end of file