diff --git a/libmproxy/proxy.py b/libmproxy/proxy.py index 964c15a9f..a6a72d55b 100644 --- a/libmproxy/proxy.py +++ b/libmproxy/proxy.py @@ -306,7 +306,7 @@ class ProxyHandler(tcp.BaseHandler): host = conn.cert.cn.decode("utf8").encode("idna") ret = self.config.certstore.get_cert(host, sans, self.config.cacert) if not ret: - raise ProxyError(502, "mitmproxy: Unable to generate dummy cert.") + raise ProxyError(502, "Unable to generate dummy cert.") return ret def get_line(self, fp): diff --git a/test/test_proxy.py b/test/test_proxy.py index 3995b393a..0788edbf8 100644 --- a/test/test_proxy.py +++ b/test/test_proxy.py @@ -22,7 +22,6 @@ def test_app_registry(): r.port = 81 assert not ar.get(r) - r = tutils.treq() r.host = "domain2" r.port = 80 diff --git a/test/test_server.py b/test/test_server.py index 47bd56b1b..86a75452e 100644 --- a/test/test_server.py +++ b/test/test_server.py @@ -141,6 +141,16 @@ class TestHTTPS(tservers.HTTPProxTest, CommonMixin): assert self.server.last_log()["request"]["sni"] == "testserver.com" +class TestHTTPSNoUpstream(tservers.HTTPProxTest, CommonMixin): + ssl = True + no_upstream_cert = True + def test_cert_gen_error(self): + f = self.pathoc_raw() + f.connect((u"\u2102\u0001".encode("utf8"), 0)) + f.request("get:/") + assert "dummy cert" in "".join(self.proxy.log) + + class TestHTTPSCertfile(tservers.HTTPProxTest, CommonMixin): ssl = True certfile = True @@ -227,7 +237,6 @@ class MasterFakeResponse(tservers.TestMaster): class TestFakeResponse(tservers.HTTPProxTest): masterclass = MasterFakeResponse def test_kill(self): - p = self.pathoc() f = self.pathod("200") assert "header_response" in f.headers.keys() @@ -241,7 +250,6 @@ class MasterKillRequest(tservers.TestMaster): class TestKillRequest(tservers.HTTPProxTest): masterclass = MasterKillRequest def test_kill(self): - p = self.pathoc() tutils.raises("server disconnect", self.pathod, "200") # Nothing should have hit the server assert not self.server.last_log() @@ -255,7 +263,6 @@ class MasterKillResponse(tservers.TestMaster): class TestKillResponse(tservers.HTTPProxTest): masterclass = MasterKillResponse def test_kill(self): - p = self.pathoc() tutils.raises("server disconnect", self.pathod, "200") # The server should have seen a request assert self.server.last_log() diff --git a/test/tservers.py b/test/tservers.py index d405e745c..4efed7e2d 100644 --- a/test/tservers.py +++ b/test/tservers.py @@ -71,6 +71,7 @@ class ProxTestBase: ssl = None clientcerts = False certfile = None + no_upstream_cert = False masterclass = TestMaster @classmethod @@ -80,6 +81,7 @@ class ProxTestBase: cls.server2 = libpathod.test.Daemon(ssl=cls.ssl) pconf = cls.get_proxy_config() config = proxy.ProxyConfig( + no_upstream_cert = cls.no_upstream_cert, cacert = tutils.test_data.path("data/serverkey.pem"), **pconf ) @@ -127,23 +129,28 @@ class ProxTestBase: class HTTPProxTest(ProxTestBase): - def pathoc(self, connect_to = None, sni=None): + def pathoc_raw(self): + return libpathod.pathoc.Pathoc("127.0.0.1", self.proxy.port) + + def pathoc(self, sni=None): """ Returns a connected Pathoc instance. """ p = libpathod.pathoc.Pathoc("localhost", self.proxy.port, ssl=self.ssl, sni=sni) - p.connect(connect_to) + if self.ssl: + p.connect(("127.0.0.1", self.server.port)) + else: + p.connect() return p def pathod(self, spec, sni=None): """ Constructs a pathod GET request, with the appropriate base and proxy. """ + p = self.pathoc(sni=sni) if self.ssl: - p = self.pathoc(("127.0.0.1", self.server.port), sni=sni) q = "get:'/p/%s'"%spec else: - p = self.pathoc() q = "get:'%s/p/%s'"%(self.server.urlbase, spec) return p.request(q)