diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2012-07-20 13:21:33 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2012-07-20 13:21:33 +1200 |
commit | 03f4dcc02b87db6f881f7d334d64a2bd4dcad04c (patch) | |
tree | 1d1dc738acc9806657fd9ec0ed8ca5545b8a2540 /test/test_pathod.py | |
parent | 76f0c3ea783dbb46540a3b77b13f7700e9639ea4 (diff) | |
download | mitmproxy-03f4dcc02b87db6f881f7d334d64a2bd4dcad04c.tar.gz mitmproxy-03f4dcc02b87db6f881f7d334d64a2bd4dcad04c.tar.bz2 mitmproxy-03f4dcc02b87db6f881f7d334d64a2bd4dcad04c.zip |
Extend test suite to cover SSL. Log SSL connection errors.
Diffstat (limited to 'test/test_pathod.py')
-rw-r--r-- | test/test_pathod.py | 55 |
1 files changed, 42 insertions, 13 deletions
diff --git a/test/test_pathod.py b/test/test_pathod.py index 902074b7..9f01b25c 100644 --- a/test/test_pathod.py +++ b/test/test_pathod.py @@ -40,12 +40,13 @@ class TestPathod: assert len(p.get_log()) <= p.LOGBUF -class TestDaemon: +class _DaemonTests: @classmethod def setUpAll(self): self.d = test.Daemon( staticdir=tutils.test_data.path("data"), - anchors=[("/anchor/.*", "202")] + anchors=[("/anchor/.*", "202")], + ssl = self.SSL ) @classmethod @@ -56,19 +57,12 @@ class TestDaemon: self.d.clear_log() def getpath(self, path): - return requests.get("http://localhost:%s/%s"%(self.d.port, path)) + scheme = "https" if self.SSL else "http" + return requests.get("%s://localhost:%s/%s"%(scheme, self.d.port, path), verify=False) def get(self, spec): - return requests.get("http://localhost:%s/p/%s"%(self.d.port, spec)) - - def test_invalid_first_line(self): - c = tcp.TCPClient("localhost", self.d.port) - c.connect() - c.wfile.write("foo\n\n\n") - c.wfile.flush() - l = self.d.log()[0] - assert l["type"] == "error" - assert "foo" in l["msg"] + scheme = "https" if self.SSL else "http" + return requests.get("%s://localhost:%s/p/%s"%(scheme, self.d.port, spec), verify=False) def test_info(self): assert tuple(self.d.info()["version"]) == version.IVERSION @@ -96,3 +90,38 @@ class TestDaemon: def test_anchor(self): rsp = self.getpath("anchor/foo") assert rsp.status_code == 202 + + def test_invalid_first_line(self): + c = tcp.TCPClient("localhost", self.d.port) + c.connect() + if self.SSL: + c.convert_to_ssl() + c.wfile.write("foo\n\n\n") + c.wfile.flush() + l = self.d.log()[0] + assert l["type"] == "error" + assert "foo" in l["msg"] + + +class TestDaemon(_DaemonTests): + SSL = False + + +class TestDaemonSSL(_DaemonTests): + SSL = True + def test_ssl_conn_failure(self): + c = tcp.TCPClient("localhost", self.d.port) + c.rbufsize = 0 + c.wbufsize = 0 + c.connect() + try: + while 1: + c.wfile.write("\r\n\r\n\r\n") + except: + pass + l = self.d.log()[0] + assert l["type"] == "error" + assert "SSL" in l["msg"] + + + |