mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-26 18:18:25 +00:00
Repair unit test suite.
This commit is contained in:
parent
51cdd7b95d
commit
759496e24e
@ -92,7 +92,7 @@ def parse_url(url):
|
|||||||
|
|
||||||
def parse_request_line(request):
|
def parse_request_line(request):
|
||||||
"""
|
"""
|
||||||
Parse a proxy request line. Return (method, scheme, host, port, path).
|
Parse a proxy request line. Return (method, scheme, host, port, path, minor).
|
||||||
Raise ProxyError on error.
|
Raise ProxyError on error.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
@ -228,9 +228,9 @@ class Request(controller.Msg):
|
|||||||
|
|
||||||
class Response(controller.Msg):
|
class Response(controller.Msg):
|
||||||
FMT = '%s\r\n%s\r\n%s'
|
FMT = '%s\r\n%s\r\n%s'
|
||||||
def __init__(self, request, code, msg, headers, content, timestamp=None):
|
def __init__(self, request, code, proto, msg, headers, content, timestamp=None):
|
||||||
self.request = request
|
self.request = request
|
||||||
self.code, self.msg = code, msg
|
self.code, self.proto, self.msg = code, proto, msg
|
||||||
self.headers, self.content = headers, content
|
self.headers, self.content = headers, content
|
||||||
self.timestamp = timestamp or time.time()
|
self.timestamp = timestamp or time.time()
|
||||||
self.cached = False
|
self.cached = False
|
||||||
@ -438,7 +438,7 @@ class ServerConnection:
|
|||||||
content = None
|
content = None
|
||||||
else:
|
else:
|
||||||
content = read_http_body(self.rfile, self, headers, True)
|
content = read_http_body(self.rfile, self, headers, True)
|
||||||
return Response(self.request, code, msg, headers, content)
|
return Response(self.request, code, proto, msg, headers, content)
|
||||||
|
|
||||||
def terminate(self):
|
def terminate(self):
|
||||||
try:
|
try:
|
||||||
@ -534,15 +534,16 @@ class ProxyHandler(SocketServer.StreamRequestHandler):
|
|||||||
'\r\n'
|
'\r\n'
|
||||||
)
|
)
|
||||||
self.wfile.flush()
|
self.wfile.flush()
|
||||||
self.connection = ssl.wrap_socket(
|
kwargs = dict(
|
||||||
self.connection,
|
|
||||||
certfile = self.find_cert(host,port),
|
certfile = self.find_cert(host,port),
|
||||||
keyfile = self.find_key(host,port),
|
keyfile = self.find_key(host,port),
|
||||||
server_side = True,
|
server_side = True,
|
||||||
ssl_version = ssl.PROTOCOL_SSLv23,
|
ssl_version = ssl.PROTOCOL_SSLv23,
|
||||||
ciphers = config.ciphers,
|
|
||||||
do_handshake_on_connect = False
|
do_handshake_on_connect = False
|
||||||
)
|
)
|
||||||
|
if sys.version_info[1] > 6:
|
||||||
|
kwargs["ciphers"] = config.ciphers
|
||||||
|
self.connection = ssl.wrap_socket(self.connection, **kwargs)
|
||||||
self.rfile = FileLike(self.connection)
|
self.rfile = FileLike(self.connection)
|
||||||
self.wfile = FileLike(self.connection)
|
self.wfile = FileLike(self.connection)
|
||||||
method, scheme, host, port, path, httpminor = parse_request_line(self.rfile.readline())
|
method, scheme, host, port, path, httpminor = parse_request_line(self.rfile.readline())
|
||||||
|
@ -147,33 +147,31 @@ class uProxy(_ProxTests):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class u_parse_proxy_request(libpry.AutoTree):
|
class u_parse_request_line(libpry.AutoTree):
|
||||||
def test_simple(self):
|
def test_simple(self):
|
||||||
libpry.raises(proxy.ProxyError, proxy.parse_proxy_request, "")
|
libpry.raises(proxy.ProxyError, proxy.parse_request_line, "")
|
||||||
|
|
||||||
u = "GET ... HTTP/1.1"
|
u = "GET ... HTTP/1.1"
|
||||||
libpry.raises("invalid url", proxy.parse_proxy_request, u)
|
libpry.raises("invalid url", proxy.parse_request_line, u)
|
||||||
|
|
||||||
u = "MORK / HTTP/1.1"
|
|
||||||
libpry.raises("unknown request method", proxy.parse_proxy_request, u)
|
|
||||||
|
|
||||||
u = "GET http://foo.com:8888/test HTTP/1.1"
|
u = "GET http://foo.com:8888/test HTTP/1.1"
|
||||||
m, s, h, po, pa = proxy.parse_proxy_request(u)
|
m, s, h, po, pa, minor = proxy.parse_request_line(u)
|
||||||
assert m == "GET"
|
assert m == "GET"
|
||||||
assert s == "http"
|
assert s == "http"
|
||||||
assert h == "foo.com"
|
assert h == "foo.com"
|
||||||
assert po == 8888
|
assert po == 8888
|
||||||
assert pa == "/test"
|
assert pa == "/test"
|
||||||
|
assert minor == 1
|
||||||
|
|
||||||
def test_connect(self):
|
def test_connect(self):
|
||||||
u = "CONNECT host.com:443 HTTP/1.0"
|
u = "CONNECT host.com:443 HTTP/1.0"
|
||||||
expected = ('CONNECT', None, 'host.com', 443, None)
|
expected = ('CONNECT', None, 'host.com', 443, None, 0)
|
||||||
ret = proxy.parse_proxy_request(u)
|
ret = proxy.parse_request_line(u)
|
||||||
assert expected == ret
|
assert expected == ret
|
||||||
|
|
||||||
def test_inner(self):
|
def test_inner(self):
|
||||||
u = "GET / HTTP/1.1"
|
u = "GET / HTTP/1.1"
|
||||||
assert proxy.parse_proxy_request(u) == ('GET', None, None, None, '/')
|
assert proxy.parse_request_line(u) == ('GET', None, None, None, '/', 1)
|
||||||
|
|
||||||
|
|
||||||
class u_parse_url(libpry.AutoTree):
|
class u_parse_url(libpry.AutoTree):
|
||||||
@ -200,12 +198,6 @@ class u_parse_url(libpry.AutoTree):
|
|||||||
assert po == 443
|
assert po == 443
|
||||||
|
|
||||||
|
|
||||||
class uConfig(libpry.AutoTree):
|
|
||||||
def test_pem(self):
|
|
||||||
c = proxy.Config(pemfile="data/testkey.pem")
|
|
||||||
assert c.pemfile
|
|
||||||
|
|
||||||
|
|
||||||
class uFileLike(libpry.AutoTree):
|
class uFileLike(libpry.AutoTree):
|
||||||
def test_wrap(self):
|
def test_wrap(self):
|
||||||
s = cStringIO.StringIO("foobar\nfoobar")
|
s = cStringIO.StringIO("foobar\nfoobar")
|
||||||
@ -282,8 +274,7 @@ tests = [
|
|||||||
uRequest(),
|
uRequest(),
|
||||||
uResponse(),
|
uResponse(),
|
||||||
uFileLike(),
|
uFileLike(),
|
||||||
uConfig(),
|
u_parse_request_line(),
|
||||||
u_parse_proxy_request(),
|
|
||||||
u_parse_url(),
|
u_parse_url(),
|
||||||
uError(),
|
uError(),
|
||||||
_TestServers(), [
|
_TestServers(), [
|
||||||
|
Loading…
Reference in New Issue
Block a user