mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 08:11:00 +00:00
Make more of the pathod test suite use synchronisation
This commit is contained in:
parent
e9fb35b817
commit
9458eaece7
@ -17,43 +17,26 @@ def test_response():
|
|||||||
|
|
||||||
|
|
||||||
class PathocTestDaemon(tutils.DaemonTests):
|
class PathocTestDaemon(tutils.DaemonTests):
|
||||||
def tval(
|
def tval(self, requests, timeout=None, showssl=False, **kwargs):
|
||||||
self,
|
|
||||||
requests,
|
|
||||||
showreq=False,
|
|
||||||
showresp=False,
|
|
||||||
explain=False,
|
|
||||||
showssl=False,
|
|
||||||
hexdump=False,
|
|
||||||
timeout=None,
|
|
||||||
ignorecodes=(),
|
|
||||||
ignoretimeout=None,
|
|
||||||
showsummary=True
|
|
||||||
):
|
|
||||||
s = StringIO()
|
s = StringIO()
|
||||||
c = pathoc.Pathoc(
|
c = pathoc.Pathoc(
|
||||||
("127.0.0.1", self.d.port),
|
("127.0.0.1", self.d.port),
|
||||||
ssl=self.ssl,
|
ssl=self.ssl,
|
||||||
showreq=showreq,
|
fp=s,
|
||||||
showresp=showresp,
|
**kwargs
|
||||||
explain=explain,
|
|
||||||
hexdump=hexdump,
|
|
||||||
ignorecodes=ignorecodes,
|
|
||||||
ignoretimeout=ignoretimeout,
|
|
||||||
showsummary=showsummary,
|
|
||||||
fp=s
|
|
||||||
)
|
)
|
||||||
with c.connect(showssl=showssl, fp=s):
|
with c.connect(showssl=showssl, fp=s):
|
||||||
if timeout:
|
if timeout:
|
||||||
c.settimeout(timeout)
|
c.settimeout(timeout)
|
||||||
for i in requests:
|
for i in requests:
|
||||||
r = language.parse_pathoc(i).next()
|
r = language.parse_pathoc(i).next()
|
||||||
if explain:
|
if kwargs.get("explain"):
|
||||||
r = r.freeze(language.Settings())
|
r = r.freeze(language.Settings())
|
||||||
try:
|
try:
|
||||||
c.request(r)
|
c.request(r)
|
||||||
except NetlibException:
|
except NetlibException:
|
||||||
pass
|
pass
|
||||||
|
self.d.wait_for_silence()
|
||||||
return s.getvalue()
|
return s.getvalue()
|
||||||
|
|
||||||
|
|
||||||
@ -66,14 +49,10 @@ class TestDaemonSSL(PathocTestDaemon):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def test_sni(self):
|
def test_sni(self):
|
||||||
c = pathoc.Pathoc(
|
self.tval(
|
||||||
("127.0.0.1", self.d.port),
|
["get:/p/200"],
|
||||||
ssl=True,
|
sni="foobar.com"
|
||||||
sni="foobar.com",
|
|
||||||
fp=None
|
|
||||||
)
|
)
|
||||||
with c.connect():
|
|
||||||
c.request("get:/p/200")
|
|
||||||
log = self.d.log()
|
log = self.d.log()
|
||||||
assert log[0]["request"]["sni"] == "foobar.com"
|
assert log[0]["request"]["sni"] == "foobar.com"
|
||||||
|
|
||||||
@ -81,15 +60,10 @@ class TestDaemonSSL(PathocTestDaemon):
|
|||||||
assert "certificate chain" in self.tval(["get:/p/200"], showssl=True)
|
assert "certificate chain" in self.tval(["get:/p/200"], showssl=True)
|
||||||
|
|
||||||
def test_clientcert(self):
|
def test_clientcert(self):
|
||||||
c = pathoc.Pathoc(
|
self.tval(
|
||||||
("127.0.0.1", self.d.port),
|
["get:/p/200"],
|
||||||
ssl=True,
|
|
||||||
clientcert=tutils.test_data.path("data/clientcert/client.pem"),
|
clientcert=tutils.test_data.path("data/clientcert/client.pem"),
|
||||||
fp=None
|
|
||||||
)
|
)
|
||||||
with c.connect():
|
|
||||||
c.request("get:/p/200")
|
|
||||||
|
|
||||||
log = self.d.log()
|
log = self.d.log()
|
||||||
assert log[0]["request"]["clientcert"]["keyinfo"]
|
assert log[0]["request"]["clientcert"]["keyinfo"]
|
||||||
|
|
||||||
@ -170,9 +144,7 @@ class TestDaemon(PathocTestDaemon):
|
|||||||
assert "Invalid server response" in self.tval(["get:'/p/200:d2'"])
|
assert "Invalid server response" in self.tval(["get:'/p/200:d2'"])
|
||||||
|
|
||||||
def test_websocket_shutdown(self):
|
def test_websocket_shutdown(self):
|
||||||
c = pathoc.Pathoc(("127.0.0.1", self.d.port), fp=None)
|
self.tval(["ws:/"])
|
||||||
with c.connect():
|
|
||||||
c.request("ws:/")
|
|
||||||
|
|
||||||
def test_wait_finish(self):
|
def test_wait_finish(self):
|
||||||
c = pathoc.Pathoc(
|
c = pathoc.Pathoc(
|
||||||
|
Loading…
Reference in New Issue
Block a user