mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 00:01:36 +00:00
disable asyncio debug mode, fix tests
This commit is contained in:
parent
05968a29bb
commit
74f94fe5a3
@ -8,12 +8,10 @@ The very high level overview is as follows:
|
||||
"""
|
||||
import abc
|
||||
import asyncio
|
||||
import logging
|
||||
import socket
|
||||
import time
|
||||
import traceback
|
||||
import typing
|
||||
from abc import ABC
|
||||
from contextlib import contextmanager
|
||||
from dataclasses import dataclass
|
||||
|
||||
@ -90,9 +88,6 @@ class ConnectionHandler(metaclass=abc.ABCMeta):
|
||||
self.timeout_watchdog = TimeoutWatchdog(self.on_timeout)
|
||||
|
||||
async def handle_client(self) -> None:
|
||||
# Hack: Work around log suppression in core.
|
||||
logging.getLogger('asyncio').setLevel(logging.DEBUG)
|
||||
asyncio.get_event_loop().set_debug(True)
|
||||
watch = asyncio.ensure_future(self.timeout_watchdog.watch())
|
||||
|
||||
self.log("client connect")
|
||||
@ -309,7 +304,7 @@ if __name__ == "__main__":
|
||||
to the reverse proxy target.
|
||||
"""
|
||||
)
|
||||
opts.mode = "reverse:http://localhost:3000/"
|
||||
opts.mode = "reverse:http://127.0.0.1:3000/"
|
||||
|
||||
|
||||
async def handle(reader, writer):
|
||||
|
@ -53,7 +53,7 @@ class TestTlsConfig:
|
||||
with taddons.context(ta) as tctx:
|
||||
ta.configure(["confdir"])
|
||||
|
||||
ctx = context.Context(context.Client(("client", 1234), ("127.0.0.1", 8080)), tctx.options)
|
||||
ctx = context.Context(context.Client(("client", 1234), ("127.0.0.1", 8080), 1605699329), tctx.options)
|
||||
|
||||
# Edge case first: We don't have _any_ idea about the server, so we just return "mitmproxy" as subject.
|
||||
cert, pkey, chainfile = ta.get_cert(ctx)
|
||||
@ -76,7 +76,7 @@ class TestTlsConfig:
|
||||
# only really testing for coverage here, there's no point in mirroring the individual conditions
|
||||
ta = tlsconfig.TlsConfig()
|
||||
with taddons.context(ta) as tctx:
|
||||
ctx = context.Context(context.Client(("client", 1234), ("127.0.0.1", 8080)), tctx.options)
|
||||
ctx = context.Context(context.Client(("client", 1234), ("127.0.0.1", 8080), 1605699329), tctx.options)
|
||||
ch = tls.ClientHelloData(ctx)
|
||||
ta.tls_clienthello(ch)
|
||||
assert not ch.establish_server_tls_first
|
||||
@ -108,7 +108,7 @@ class TestTlsConfig:
|
||||
with taddons.context(ta) as tctx:
|
||||
ta.configure(["confdir"])
|
||||
tctx.configure(ta, certs=[tdata.path("mitmproxy/net/data/verificationcerts/trusted-leaf.pem")])
|
||||
ctx = context.Context(context.Client(("client", 1234), ("127.0.0.1", 8080)), tctx.options)
|
||||
ctx = context.Context(context.Client(("client", 1234), ("127.0.0.1", 8080), 1605699329), tctx.options)
|
||||
tctx.options.add_upstream_certs_to_client_chain = True
|
||||
|
||||
tls_start = tls.TlsStartData(ctx.client, context=ctx)
|
||||
@ -121,7 +121,7 @@ class TestTlsConfig:
|
||||
def test_create_proxy_server_ssl_conn_verify_failed(self):
|
||||
ta = tlsconfig.TlsConfig()
|
||||
with taddons.context(ta) as tctx:
|
||||
ctx = context.Context(context.Client(("client", 1234), ("127.0.0.1", 8080)), tctx.options)
|
||||
ctx = context.Context(context.Client(("client", 1234), ("127.0.0.1", 8080), 1605699329), tctx.options)
|
||||
ctx.client.alpn_offers = [b"h2"]
|
||||
ctx.client.cipher_list = ["TLS_AES_256_GCM_SHA384", "ECDHE-RSA-AES128-SHA"]
|
||||
ctx.server.address = ("example.mitmproxy.org", 443)
|
||||
@ -136,7 +136,7 @@ class TestTlsConfig:
|
||||
def test_create_proxy_server_ssl_conn_verify_ok(self, tdata):
|
||||
ta = tlsconfig.TlsConfig()
|
||||
with taddons.context(ta) as tctx:
|
||||
ctx = context.Context(context.Client(("client", 1234), ("127.0.0.1", 8080)), tctx.options)
|
||||
ctx = context.Context(context.Client(("client", 1234), ("127.0.0.1", 8080), 1605699329), tctx.options)
|
||||
ctx.server.address = ("example.mitmproxy.org", 443)
|
||||
tctx.configure(ta, ssl_verify_upstream_trusted_ca=tdata.path(
|
||||
"mitmproxy/net/data/verificationcerts/trusted-root.crt"))
|
||||
@ -150,7 +150,7 @@ class TestTlsConfig:
|
||||
def test_create_proxy_server_ssl_conn_insecure(self):
|
||||
ta = tlsconfig.TlsConfig()
|
||||
with taddons.context(ta) as tctx:
|
||||
ctx = context.Context(context.Client(("client", 1234), ("127.0.0.1", 8080)), tctx.options)
|
||||
ctx = context.Context(context.Client(("client", 1234), ("127.0.0.1", 8080), 1605699329), tctx.options)
|
||||
ctx.server.address = ("example.mitmproxy.org", 443)
|
||||
|
||||
tctx.configure(
|
||||
@ -176,7 +176,7 @@ class TestTlsConfig:
|
||||
def test_client_cert_file(self, tdata, client_certs):
|
||||
ta = tlsconfig.TlsConfig()
|
||||
with taddons.context(ta) as tctx:
|
||||
ctx = context.Context(context.Client(("client", 1234), ("127.0.0.1", 8080)), tctx.options)
|
||||
ctx = context.Context(context.Client(("client", 1234), ("127.0.0.1", 8080), 1605699329), tctx.options)
|
||||
ctx.server.address = ("example.mitmproxy.org", 443)
|
||||
tctx.configure(
|
||||
ta,
|
||||
|
@ -12,7 +12,8 @@ def tctx() -> context.Context:
|
||||
return context.Context(
|
||||
context.Client(
|
||||
("client", 1234),
|
||||
("127.0.0.1", 8080)
|
||||
("127.0.0.1", 8080),
|
||||
1605699329
|
||||
),
|
||||
opts
|
||||
)
|
||||
|
@ -101,7 +101,7 @@ def h2_responses(draw):
|
||||
|
||||
@given(chunks(mutations(h1_requests())))
|
||||
def test_fuzz_h1_request(data):
|
||||
tctx = context.Context(context.Client(("client", 1234), ("127.0.0.1", 8080)), opts)
|
||||
tctx = context.Context(context.Client(("client", 1234), ("127.0.0.1", 8080), 1605699329), opts)
|
||||
|
||||
layer = http.HttpLayer(tctx, HTTPMode.regular)
|
||||
for _ in layer.handle_event(Start()):
|
||||
@ -114,7 +114,7 @@ def test_fuzz_h1_request(data):
|
||||
@given(chunks(mutations(h2_responses())))
|
||||
@example([b'0 OK\r\n\r\n', b'\r\n', b'5\r\n12345\r\n0\r\n\r\n'])
|
||||
def test_fuzz_h1_response(data):
|
||||
tctx = context.Context(context.Client(("client", 1234), ("127.0.0.1", 8080)), opts)
|
||||
tctx = context.Context(context.Client(("client", 1234), ("127.0.0.1", 8080), 1605699329), opts)
|
||||
server = Placeholder(context.Server)
|
||||
playbook = Playbook(http.HttpLayer(tctx, HTTPMode.regular), hooks=False)
|
||||
assert (
|
||||
@ -208,7 +208,7 @@ def h2_frames(draw):
|
||||
|
||||
|
||||
def h2_layer(opts):
|
||||
tctx = context.Context(context.Client(("client", 1234), ("127.0.0.1", 8080)), opts)
|
||||
tctx = context.Context(context.Client(("client", 1234), ("127.0.0.1", 8080), 1605699329), opts)
|
||||
tctx.client.alpn = b"h2"
|
||||
|
||||
layer = http.HttpLayer(tctx, HTTPMode.regular)
|
||||
@ -246,7 +246,7 @@ def test_fuzz_h2_request_mutations(chunks):
|
||||
|
||||
|
||||
def _h2_response(chunks):
|
||||
tctx = context.Context(context.Client(("client", 1234), ("127.0.0.1", 8080)), opts)
|
||||
tctx = context.Context(context.Client(("client", 1234), ("127.0.0.1", 8080), 1605699329), opts)
|
||||
playbook = Playbook(http.HttpLayer(tctx, HTTPMode.regular), hooks=False)
|
||||
server = Placeholder(context.Server)
|
||||
assert (
|
||||
|
Loading…
Reference in New Issue
Block a user