mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-27 02:24:18 +00:00
adjust to netlib changes
This commit is contained in:
parent
a163dba582
commit
fa722e0290
@ -290,9 +290,9 @@ class Pathoc(tcp.TCPClient):
|
|||||||
self.sslinfo = None
|
self.sslinfo = None
|
||||||
if self.ssl:
|
if self.ssl:
|
||||||
try:
|
try:
|
||||||
alpn_protos = [http.ALPN_PROTO_HTTP1]
|
alpn_protos = [b'http/1.1']
|
||||||
if self.use_http2:
|
if self.use_http2:
|
||||||
alpn_protos.append(http.ALPN_PROTO_H2)
|
alpn_protos.append(b'h2')
|
||||||
|
|
||||||
self.convert_to_ssl(
|
self.convert_to_ssl(
|
||||||
sni=self.sni,
|
sni=self.sni,
|
||||||
@ -424,7 +424,7 @@ class Pathoc(tcp.TCPClient):
|
|||||||
finally:
|
finally:
|
||||||
if resp:
|
if resp:
|
||||||
lg("<< %s %s: %s bytes" % (
|
lg("<< %s %s: %s bytes" % (
|
||||||
resp.status_code, utils.xrepr(resp.msg), len(resp.body)
|
resp.status_code, utils.xrepr(resp.msg), len(resp.content)
|
||||||
))
|
))
|
||||||
if resp.status_code in self.ignorecodes:
|
if resp.status_code in self.ignorecodes:
|
||||||
lg.suppress()
|
lg.suppress()
|
||||||
|
@ -41,7 +41,7 @@ class SSLOptions(object):
|
|||||||
ssl_options=tcp.SSL_DEFAULT_OPTIONS,
|
ssl_options=tcp.SSL_DEFAULT_OPTIONS,
|
||||||
ciphers=None,
|
ciphers=None,
|
||||||
certs=None,
|
certs=None,
|
||||||
alpn_select=http.ALPN_PROTO_H2,
|
alpn_select=b'h2',
|
||||||
):
|
):
|
||||||
self.confdir = confdir
|
self.confdir = confdir
|
||||||
self.cn = cn
|
self.cn = cn
|
||||||
@ -140,7 +140,7 @@ class PathodHandler(tcp.BaseHandler):
|
|||||||
path = req.path
|
path = req.path
|
||||||
http_version = req.http_version
|
http_version = req.http_version
|
||||||
headers = req.headers
|
headers = req.headers
|
||||||
body = req.body
|
body = req.content
|
||||||
|
|
||||||
clientcert = None
|
clientcert = None
|
||||||
if self.clientcert:
|
if self.clientcert:
|
||||||
@ -259,7 +259,7 @@ class PathodHandler(tcp.BaseHandler):
|
|||||||
return
|
return
|
||||||
|
|
||||||
alp = self.get_alpn_proto_negotiated()
|
alp = self.get_alpn_proto_negotiated()
|
||||||
if alp == http.ALPN_PROTO_H2:
|
if alp == b'h2':
|
||||||
self.protocol = protocols.http2.HTTP2Protocol(self)
|
self.protocol = protocols.http2.HTTP2Protocol(self)
|
||||||
self.use_http2 = True
|
self.use_http2 = True
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ class TestApp(tutils.DaemonTests):
|
|||||||
def test_index(self):
|
def test_index(self):
|
||||||
r = self.getpath("/")
|
r = self.getpath("/")
|
||||||
assert r.status_code == 200
|
assert r.status_code == 200
|
||||||
assert r.body
|
assert r.content
|
||||||
|
|
||||||
def test_about(self):
|
def test_about(self):
|
||||||
r = self.getpath("/about")
|
r = self.getpath("/about")
|
||||||
@ -38,48 +38,48 @@ class TestApp(tutils.DaemonTests):
|
|||||||
def test_response_preview(self):
|
def test_response_preview(self):
|
||||||
r = self.getpath("/response_preview", params=dict(spec="200"))
|
r = self.getpath("/response_preview", params=dict(spec="200"))
|
||||||
assert r.status_code == 200
|
assert r.status_code == 200
|
||||||
assert 'Response' in r.body
|
assert 'Response' in r.content
|
||||||
|
|
||||||
r = self.getpath("/response_preview", params=dict(spec="foo"))
|
r = self.getpath("/response_preview", params=dict(spec="foo"))
|
||||||
assert r.status_code == 200
|
assert r.status_code == 200
|
||||||
assert 'Error' in r.body
|
assert 'Error' in r.content
|
||||||
|
|
||||||
r = self.getpath("/response_preview", params=dict(spec="200:b@100m"))
|
r = self.getpath("/response_preview", params=dict(spec="200:b@100m"))
|
||||||
assert r.status_code == 200
|
assert r.status_code == 200
|
||||||
assert "too large" in r.body
|
assert "too large" in r.content
|
||||||
|
|
||||||
r = self.getpath("/response_preview", params=dict(spec="200:b@5k"))
|
r = self.getpath("/response_preview", params=dict(spec="200:b@5k"))
|
||||||
assert r.status_code == 200
|
assert r.status_code == 200
|
||||||
assert 'Response' in r.body
|
assert 'Response' in r.content
|
||||||
|
|
||||||
r = self.getpath(
|
r = self.getpath(
|
||||||
"/response_preview",
|
"/response_preview",
|
||||||
params=dict(
|
params=dict(
|
||||||
spec="200:b<nonexistent"))
|
spec="200:b<nonexistent"))
|
||||||
assert r.status_code == 200
|
assert r.status_code == 200
|
||||||
assert 'File access denied' in r.body
|
assert 'File access denied' in r.content
|
||||||
|
|
||||||
r = self.getpath("/response_preview", params=dict(spec="200:b<file"))
|
r = self.getpath("/response_preview", params=dict(spec="200:b<file"))
|
||||||
assert r.status_code == 200
|
assert r.status_code == 200
|
||||||
assert 'testfile' in r.body
|
assert 'testfile' in r.content
|
||||||
|
|
||||||
def test_request_preview(self):
|
def test_request_preview(self):
|
||||||
r = self.getpath("/request_preview", params=dict(spec="get:/"))
|
r = self.getpath("/request_preview", params=dict(spec="get:/"))
|
||||||
assert r.status_code == 200
|
assert r.status_code == 200
|
||||||
assert 'Request' in r.body
|
assert 'Request' in r.content
|
||||||
|
|
||||||
r = self.getpath("/request_preview", params=dict(spec="foo"))
|
r = self.getpath("/request_preview", params=dict(spec="foo"))
|
||||||
assert r.status_code == 200
|
assert r.status_code == 200
|
||||||
assert 'Error' in r.body
|
assert 'Error' in r.content
|
||||||
|
|
||||||
r = self.getpath("/request_preview", params=dict(spec="get:/:b@100m"))
|
r = self.getpath("/request_preview", params=dict(spec="get:/:b@100m"))
|
||||||
assert r.status_code == 200
|
assert r.status_code == 200
|
||||||
assert "too large" in r.body
|
assert "too large" in r.content
|
||||||
|
|
||||||
r = self.getpath("/request_preview", params=dict(spec="get:/:b@5k"))
|
r = self.getpath("/request_preview", params=dict(spec="get:/:b@5k"))
|
||||||
assert r.status_code == 200
|
assert r.status_code == 200
|
||||||
assert 'Request' in r.body
|
assert 'Request' in r.content
|
||||||
|
|
||||||
r = self.getpath("/request_preview", params=dict(spec=""))
|
r = self.getpath("/request_preview", params=dict(spec=""))
|
||||||
assert r.status_code == 200
|
assert r.status_code == 200
|
||||||
assert 'empty spec' in r.body
|
assert 'empty spec' in r.content
|
||||||
|
@ -47,7 +47,7 @@ class _TestDaemon:
|
|||||||
)
|
)
|
||||||
c.connect()
|
c.connect()
|
||||||
resp = c.request("get:/api/info")
|
resp = c.request("get:/api/info")
|
||||||
assert tuple(json.loads(resp.body)["version"]) == version.IVERSION
|
assert tuple(json.loads(resp.content)["version"]) == version.IVERSION
|
||||||
|
|
||||||
def tval(
|
def tval(
|
||||||
self,
|
self,
|
||||||
@ -94,7 +94,7 @@ class TestDaemonSSL(_TestDaemon):
|
|||||||
ssloptions = pathod.SSLOptions(
|
ssloptions = pathod.SSLOptions(
|
||||||
request_client_cert=True,
|
request_client_cert=True,
|
||||||
sans=["test1.com", "test2.com"],
|
sans=["test1.com", "test2.com"],
|
||||||
alpn_select=http.ALPN_PROTO_H2,
|
alpn_select=b'h2',
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_sni(self):
|
def test_sni(self):
|
||||||
@ -107,7 +107,7 @@ class TestDaemonSSL(_TestDaemon):
|
|||||||
c.connect()
|
c.connect()
|
||||||
c.request("get:/p/200")
|
c.request("get:/p/200")
|
||||||
r = c.request("get:/api/log")
|
r = c.request("get:/api/log")
|
||||||
d = json.loads(r.body)
|
d = json.loads(r.content)
|
||||||
assert d["log"][0]["request"]["sni"] == "foobar.com"
|
assert d["log"][0]["request"]["sni"] == "foobar.com"
|
||||||
|
|
||||||
def test_showssl(self):
|
def test_showssl(self):
|
||||||
@ -123,7 +123,7 @@ class TestDaemonSSL(_TestDaemon):
|
|||||||
c.connect()
|
c.connect()
|
||||||
c.request("get:/p/200")
|
c.request("get:/p/200")
|
||||||
r = c.request("get:/api/log")
|
r = c.request("get:/api/log")
|
||||||
d = json.loads(r.body)
|
d = json.loads(r.content)
|
||||||
assert d["log"][0]["request"]["clientcert"]["keyinfo"]
|
assert d["log"][0]["request"]["clientcert"]["keyinfo"]
|
||||||
|
|
||||||
def test_http2_without_ssl(self):
|
def test_http2_without_ssl(self):
|
||||||
|
@ -52,7 +52,7 @@ class TestNoApi(tutils.DaemonTests):
|
|||||||
assert self.getpath("/log").status_code == 404
|
assert self.getpath("/log").status_code == 404
|
||||||
r = self.getpath("/")
|
r = self.getpath("/")
|
||||||
assert r.status_code == 200
|
assert r.status_code == 200
|
||||||
assert not "Log" in r.body
|
assert not "Log" in r.content
|
||||||
|
|
||||||
|
|
||||||
class TestNotAfterConnect(tutils.DaemonTests):
|
class TestNotAfterConnect(tutils.DaemonTests):
|
||||||
@ -120,7 +120,7 @@ class TestNocraft(tutils.DaemonTests):
|
|||||||
def test_nocraft(self):
|
def test_nocraft(self):
|
||||||
r = self.get(r"200:b'\xf0'")
|
r = self.get(r"200:b'\xf0'")
|
||||||
assert r.status_code == 800
|
assert r.status_code == 800
|
||||||
assert "Crafting disabled" in r.body
|
assert "Crafting disabled" in r.content
|
||||||
|
|
||||||
|
|
||||||
class CommonTests(tutils.DaemonTests):
|
class CommonTests(tutils.DaemonTests):
|
||||||
@ -153,7 +153,7 @@ class CommonTests(tutils.DaemonTests):
|
|||||||
|
|
||||||
def test_disconnect(self):
|
def test_disconnect(self):
|
||||||
rsp = self.get("202:b@100k:d200")
|
rsp = self.get("202:b@100k:d200")
|
||||||
assert len(rsp.body) < 200
|
assert len(rsp.content) < 200
|
||||||
|
|
||||||
def test_parserr(self):
|
def test_parserr(self):
|
||||||
rsp = self.get("400:msg,b:")
|
rsp = self.get("400:msg,b:")
|
||||||
@ -162,7 +162,7 @@ class CommonTests(tutils.DaemonTests):
|
|||||||
def test_static(self):
|
def test_static(self):
|
||||||
rsp = self.get("200:b<file")
|
rsp = self.get("200:b<file")
|
||||||
assert rsp.status_code == 200
|
assert rsp.status_code == 200
|
||||||
assert rsp.body.strip() == "testfile"
|
assert rsp.content.strip() == "testfile"
|
||||||
|
|
||||||
def test_anchor(self):
|
def test_anchor(self):
|
||||||
rsp = self.getpath("anchor/foo")
|
rsp = self.getpath("anchor/foo")
|
||||||
@ -202,7 +202,7 @@ class CommonTests(tutils.DaemonTests):
|
|||||||
def test_source_access_denied(self):
|
def test_source_access_denied(self):
|
||||||
rsp = self.get("200:b</foo")
|
rsp = self.get("200:b</foo")
|
||||||
assert rsp.status_code == 800
|
assert rsp.status_code == 800
|
||||||
assert "File access denied" in rsp.body
|
assert "File access denied" in rsp.content
|
||||||
|
|
||||||
def test_proxy(self):
|
def test_proxy(self):
|
||||||
r, _ = self.pathoc([r"get:'http://foo.com/p/202':da"])
|
r, _ = self.pathoc([r"get:'http://foo.com/p/202':da"])
|
||||||
|
@ -73,12 +73,10 @@ class DaemonTests(object):
|
|||||||
verify=False,
|
verify=False,
|
||||||
params=params
|
params=params
|
||||||
)
|
)
|
||||||
resp.body = resp.content
|
|
||||||
return resp
|
return resp
|
||||||
|
|
||||||
def get(self, spec):
|
def get(self, spec):
|
||||||
resp = requests.get(self.d.p(spec), verify=False)
|
resp = requests.get(self.d.p(spec), verify=False)
|
||||||
resp.body = resp.content
|
|
||||||
return resp
|
return resp
|
||||||
|
|
||||||
def pathoc(
|
def pathoc(
|
||||||
|
Loading…
Reference in New Issue
Block a user