diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/test_console_contentview.py | 16 | ||||
-rw-r--r-- | test/test_dump.py | 10 | ||||
-rw-r--r-- | test/test_flow.py | 4 | ||||
-rw-r--r-- | test/test_platform_pf.py | 2 | ||||
-rw-r--r-- | test/test_proxy.py | 5 | ||||
-rw-r--r-- | test/test_server.py | 10 | ||||
-rw-r--r-- | test/test_utils.py | 2 | ||||
-rw-r--r-- | test/tservers.py | 9 | ||||
-rw-r--r-- | test/tutils.py | 2 |
9 files changed, 28 insertions, 32 deletions
diff --git a/test/test_console_contentview.py b/test/test_console_contentview.py index 1798ce85..f6b45f67 100644 --- a/test/test_console_contentview.py +++ b/test/test_console_contentview.py @@ -114,16 +114,16 @@ class TestContentView: def test_view_image(self): v = cv.ViewImage() p = tutils.test_data.path("data/image.png") - assert v([], file(p).read(), sys.maxint) + assert v([], file(p,"rb").read(), sys.maxint) p = tutils.test_data.path("data/image.gif") - assert v([], file(p).read(), sys.maxint) + assert v([], file(p,"rb").read(), sys.maxint) p = tutils.test_data.path("data/image-err1.jpg") - assert v([], file(p).read(), sys.maxint) + assert v([], file(p,"rb").read(), sys.maxint) p = tutils.test_data.path("data/image.ico") - assert v([], file(p).read(), sys.maxint) + assert v([], file(p,"rb").read(), sys.maxint) assert not v([], "flibble", sys.maxint) @@ -224,22 +224,22 @@ if pyamf: v = cv.ViewAMF() p = tutils.test_data.path("data/amf01") - assert v([], file(p).read(), sys.maxint) + assert v([], file(p,"rb").read(), sys.maxint) p = tutils.test_data.path("data/amf02") - assert v([], file(p).read(), sys.maxint) + assert v([], file(p,"rb").read(), sys.maxint) def test_view_amf_response(): v = cv.ViewAMF() p = tutils.test_data.path("data/amf03") - assert v([], file(p).read(), sys.maxint) + assert v([], file(p,"rb").read(), sys.maxint) if cv.ViewProtobuf.is_available(): def test_view_protobuf_request(): v = cv.ViewProtobuf() p = tutils.test_data.path("data/protobuf01") - content_type, output = v([], file(p).read(), sys.maxint) + content_type, output = v([], file(p,"rb").read(), sys.maxint) assert content_type == "Protobuf" assert output[0].text == '1: "3bbc333c-e61c-433b-819a-0b9a8cc103b8"' diff --git a/test/test_dump.py b/test/test_dump.py index 94d0b195..b195d5f0 100644 --- a/test/test_dump.py +++ b/test/test_dump.py @@ -46,7 +46,7 @@ class TestDumpMaster: return cs.getvalue() def _flowfile(self, path): - f = open(path, "w") + f = open(path, "wb") fw = flow.FlowWriter(f) t = tutils.tflow_full() t.response = tutils.tresp(t.request) @@ -106,6 +106,12 @@ class TestDumpMaster: def test_filter(self): assert not "GET" in self._dummy_cycle(1, "~u foo", "", verbosity=1) + def test_app(self): + o = dump.Options(app=True) + s = mock.MagicMock() + m = dump.DumpMaster(s, o, None) + assert s.apps.add.call_count == 2 + def test_replacements(self): o = dump.Options(replacements=[(".*", "content", "foo")]) m = dump.DumpMaster(None, o, None) @@ -128,7 +134,7 @@ class TestDumpMaster: with tutils.tmpdir() as d: p = os.path.join(d, "a") self._dummy_cycle(1, None, "", wfile=p, verbosity=0) - assert len(list(flow.FlowReader(open(p)).stream())) == 1 + assert len(list(flow.FlowReader(open(p,"rb")).stream())) == 1 def test_write_err(self): tutils.raises( diff --git a/test/test_flow.py b/test/test_flow.py index 085801af..68aa14cd 100644 --- a/test/test_flow.py +++ b/test/test_flow.py @@ -600,7 +600,7 @@ class TestFlowMaster: s = flow.State() fm = flow.FlowMaster(None, s) f = tutils.tflow_full() - fm.load_flow(f) + f = fm.load_flow(f) assert s.flow_count() == 1 f2 = fm.duplicate_flow(f) assert f2.response @@ -742,7 +742,7 @@ class TestFlowMaster: with tutils.tmpdir() as tdir: p = os.path.join(tdir, "foo") def r(): - r = flow.FlowReader(open(p)) + r = flow.FlowReader(open(p,"rb")) return list(r.stream()) s = flow.State() diff --git a/test/test_platform_pf.py b/test/test_platform_pf.py index a2e7c3c1..f048fdcc 100644 --- a/test/test_platform_pf.py +++ b/test/test_platform_pf.py @@ -5,7 +5,7 @@ from libmproxy.platform import pf class TestLookup: def test_simple(self): p = tutils.test_data.path("data/pf01") - d = open(p).read() + d = open(p,"rb").read() assert pf.lookup("192.168.1.111", 40000, d) == ("5.5.5.5", 80) assert not pf.lookup("192.168.1.112", 40000, d) assert not pf.lookup("192.168.1.111", 40001, d) diff --git a/test/test_proxy.py b/test/test_proxy.py index 5828d077..85be82cb 100644 --- a/test/test_proxy.py +++ b/test/test_proxy.py @@ -56,7 +56,7 @@ class TestServerConnection: sc = proxy.ServerConnection(proxy.ProxyConfig(), "http", self.d.IFACE, self.d.port, "host.com") sc.connect() sc.connection = mock.Mock() - sc.connection.close = mock.Mock(side_effect=IOError) + sc.connection.flush = mock.Mock(side_effect=tcp.NetLibDisconnect) sc.terminate() @@ -116,9 +116,6 @@ class TestProcessProxyOptions: self.assert_noerr("--client-certs", confdir) self.assert_err("directory does not exist", "--client-certs", "nonexistent") - self.assert_noerr("--dummy-certs", confdir) - self.assert_err("directory does not exist", "--dummy-certs", "nonexistent") - def test_auth(self): p = self.assert_noerr("--nonanonymous") assert p.authenticator diff --git a/test/test_server.py b/test/test_server.py index 079ed8ce..e9a6b727 100644 --- a/test/test_server.py +++ b/test/test_server.py @@ -191,16 +191,6 @@ class TestHTTPS(tservers.HTTPProxTest, CommonMixin): assert p.request("get:/:i0,'invalid\r\n\r\n'").status_code == 400 -class TestHTTPSNoUpstream(tservers.HTTPProxTest, CommonMixin): - ssl = True - no_upstream_cert = True - def test_cert_gen_error(self): - f = self.pathoc_raw() - f.connect((u"foo..bar".encode("utf8"), 0)) - f.request("get:/") - assert "dummy cert" in "".join(self.proxy.log) - - class TestHTTPSCertfile(tservers.HTTPProxTest, CommonMixin): ssl = True certfile = True diff --git a/test/test_utils.py b/test/test_utils.py index db6feb4d..f40e0a31 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -38,7 +38,7 @@ def test_pretty_size(): assert utils.pretty_size(100) == "100B" assert utils.pretty_size(1024) == "1kB" assert utils.pretty_size(1024 + (1024/2.0)) == "1.5kB" - assert utils.pretty_size(1024*1024) == "1M" + assert utils.pretty_size(1024*1024) == "1MB" def test_pkg_data(): diff --git a/test/tservers.py b/test/tservers.py index 1197fb69..0606bd9c 100644 --- a/test/tservers.py +++ b/test/tservers.py @@ -4,6 +4,9 @@ import libpathod.test, libpathod.pathoc from libmproxy import proxy, flow, controller import tutils +APP_DOMAIN = "mitm" +APP_IP = "1.1.1.1" + testapp = flask.Flask(__name__) @testapp.route("/") @@ -28,6 +31,7 @@ class TestMaster(flow.FlowMaster): flow.FlowMaster.__init__(self, s, state) self.testq = testq self.clear_log() + self.start_app(APP_DOMAIN, APP_IP) def handle_request(self, m): flow.FlowMaster.handle_request(self, m) @@ -85,7 +89,6 @@ class ProxTestBase: no_upstream_cert = cls.no_upstream_cert, cacert = tutils.test_data.path("data/serverkey.pem"), authenticator = cls.authenticator, - app = True, **pconf ) tmaster = cls.masterclass(cls.tqueue, config) @@ -162,12 +165,12 @@ class HTTPProxTest(ProxTestBase): if self.ssl: p = libpathod.pathoc.Pathoc("127.0.0.1", self.proxy.port, True) print "PRE" - p.connect((proxy.APP_IP, 80)) + p.connect((APP_IP, 80)) print "POST" return p.request("get:'/%s'"%page) else: p = self.pathoc() - return p.request("get:'http://%s/%s'"%(proxy.APP_DOMAIN, page)) + return p.request("get:'http://%s/%s'"%(APP_DOMAIN, page)) class TResolver: diff --git a/test/tutils.py b/test/tutils.py index 1a1c8724..fbce615a 100644 --- a/test/tutils.py +++ b/test/tutils.py @@ -20,7 +20,7 @@ def tresp(req=None): req = treq() headers = flow.ODictCaseless() headers["header_response"] = ["svalue"] - cert = certutils.SSLCert.from_der(file(test_data.path("data/dercert")).read()) + cert = certutils.SSLCert.from_der(file(test_data.path("data/dercert"),"rb").read()) resp = flow.Response(req, (1, 1), 200, "message", headers, "content_response", cert) resp.reply = controller.DummyReply() return resp |