mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 00:01:36 +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):
|
||||
"""
|
||||
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.
|
||||
"""
|
||||
try:
|
||||
@ -228,9 +228,9 @@ class Request(controller.Msg):
|
||||
|
||||
class Response(controller.Msg):
|
||||
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.code, self.msg = code, msg
|
||||
self.code, self.proto, self.msg = code, proto, msg
|
||||
self.headers, self.content = headers, content
|
||||
self.timestamp = timestamp or time.time()
|
||||
self.cached = False
|
||||
@ -438,7 +438,7 @@ class ServerConnection:
|
||||
content = None
|
||||
else:
|
||||
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):
|
||||
try:
|
||||
@ -534,15 +534,16 @@ class ProxyHandler(SocketServer.StreamRequestHandler):
|
||||
'\r\n'
|
||||
)
|
||||
self.wfile.flush()
|
||||
self.connection = ssl.wrap_socket(
|
||||
self.connection,
|
||||
kwargs = dict(
|
||||
certfile = self.find_cert(host,port),
|
||||
keyfile = self.find_key(host,port),
|
||||
server_side = True,
|
||||
ssl_version = ssl.PROTOCOL_SSLv23,
|
||||
ciphers = config.ciphers,
|
||||
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.wfile = FileLike(self.connection)
|
||||
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):
|
||||
libpry.raises(proxy.ProxyError, proxy.parse_proxy_request, "")
|
||||
libpry.raises(proxy.ProxyError, proxy.parse_request_line, "")
|
||||
|
||||
u = "GET ... HTTP/1.1"
|
||||
libpry.raises("invalid url", proxy.parse_proxy_request, u)
|
||||
|
||||
u = "MORK / HTTP/1.1"
|
||||
libpry.raises("unknown request method", proxy.parse_proxy_request, u)
|
||||
libpry.raises("invalid url", proxy.parse_request_line, u)
|
||||
|
||||
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 s == "http"
|
||||
assert h == "foo.com"
|
||||
assert po == 8888
|
||||
assert pa == "/test"
|
||||
assert minor == 1
|
||||
|
||||
def test_connect(self):
|
||||
u = "CONNECT host.com:443 HTTP/1.0"
|
||||
expected = ('CONNECT', None, 'host.com', 443, None)
|
||||
ret = proxy.parse_proxy_request(u)
|
||||
expected = ('CONNECT', None, 'host.com', 443, None, 0)
|
||||
ret = proxy.parse_request_line(u)
|
||||
assert expected == ret
|
||||
|
||||
def test_inner(self):
|
||||
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):
|
||||
@ -200,12 +198,6 @@ class u_parse_url(libpry.AutoTree):
|
||||
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):
|
||||
def test_wrap(self):
|
||||
s = cStringIO.StringIO("foobar\nfoobar")
|
||||
@ -282,8 +274,7 @@ tests = [
|
||||
uRequest(),
|
||||
uResponse(),
|
||||
uFileLike(),
|
||||
uConfig(),
|
||||
u_parse_proxy_request(),
|
||||
u_parse_request_line(),
|
||||
u_parse_url(),
|
||||
uError(),
|
||||
_TestServers(), [
|
||||
|
Loading…
Reference in New Issue
Block a user