mitmproxy/test/test_proxy.py

59 lines
1.2 KiB
Python
Raw Normal View History

from libmproxy import proxy, flow
import tutils
from libpathod import test
from netlib import http
2010-02-16 04:09:07 +00:00
def test_proxy_error():
p = proxy.ProxyError(111, "msg")
assert str(p)
2010-02-16 04:09:07 +00:00
2012-06-18 22:42:55 +00:00
def test_app_registry():
ar = proxy.AppRegistry()
ar.add("foo", "domain", 80)
2012-06-18 22:42:55 +00:00
r = tutils.treq()
r.host = "domain"
r.port = 80
assert ar.get(r)
2012-06-18 22:42:55 +00:00
r.port = 81
assert not ar.get(r)
r = tutils.treq()
r.host = "domain2"
r.port = 80
assert not ar.get(r)
r.headers["host"] = ["domain"]
assert ar.get(r)
class TestServerConnection:
def setUp(self):
self.d = test.Daemon()
def tearDown(self):
self.d.shutdown()
def test_simple(self):
sc = proxy.ServerConnection(proxy.ProxyConfig(), self.d.IFACE, self.d.port)
sc.connect("http")
r = tutils.treq()
r.path = "/p/200:da"
sc.send(r)
assert http.read_response(sc.rfile, r.method, 1000)
assert self.d.last_log()
r.content = flow.CONTENT_MISSING
tutils.raises("incomplete request", sc.send, r)
def test_send_error(self):
sc = proxy.ServerConnection(proxy.ProxyConfig(), self.d.IFACE, self.d.port)
sc.connect("http")
r = tutils.treq()
sc.send(r)