Skip to content

Commit

Permalink
Declare Support for Python 3.12 (#6434)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhils committed Oct 31, 2023
1 parent f55ee1d commit c637032
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .github/python-version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.11
3.12
6 changes: 4 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ jobs:
matrix:
include:
- os: ubuntu-latest
py: "3.11"
py: "3.12"
- os: windows-latest
py: "3.11"
py: "3.12"
- os: macos-latest
py: "3.12"
- os: ubuntu-latest
py: "3.11"
- os: ubuntu-latest
py: "3.10"
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
([#6410](https://github.com/mitmproxy/mitmproxy/pull/6410), @mmaxim)
* Fix path() documentation that the return value might include the query string
([#6412](https://github.com/mitmproxy/mitmproxy/pull/6412), @tddschn)
* mitmproxy now officially supports Python 3.12.
([#6434](https://github.com/mitmproxy/mitmproxy/pull/6434), @mhils)
* Fix root-relative URLs so that mitmweb can run in subdirectories.
([#6411](https://github.com/mitmproxy/mitmproxy/pull/6411), @davet2001)
* Add an optional parameter(ldap search filter key) to ProxyAuth-LDAP.
Expand Down
9 changes: 6 additions & 3 deletions mitmproxy/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,12 @@ def __init__(self, *args, **kwargs):

def filter(self, record: logging.LogRecord) -> bool:
# We can't remove stale handlers here because that would modify .handlers during iteration!
return super().filter(record) and (
not self._initiated_in_test
or self._initiated_in_test == os.environ.get("PYTEST_CURRENT_TEST")
return bool(
super().filter(record)
and (
not self._initiated_in_test
or self._initiated_in_test == os.environ.get("PYTEST_CURRENT_TEST")
)
)

def install(self) -> None:
Expand Down
3 changes: 2 additions & 1 deletion mitmproxy/proxy/mode_servers.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,8 @@ async def _stop(self) -> None:
try:
for s in self._servers:
s.close()
await asyncio.gather(*[s.wait_closed() for s in self._servers])
# https://github.com/python/cpython/issues/104344
# await asyncio.gather(*[s.wait_closed() for s in self._servers])
finally:
# we always reset _server and ignore failures
self._servers = []
Expand Down
9 changes: 5 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ classifiers = [
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: Implementation :: CPython",
"Topic :: Security",
"Topic :: Internet :: WWW/HTTP",
Expand All @@ -30,7 +31,7 @@ classifiers = [
# https://packaging.python.org/en/latest/discussions/install-requires-vs-requirements/#install-requires
# It is not considered best practice to use install_requires to pin dependencies to specific versions.
dependencies = [
"aioquic_mitmproxy>=0.9.20,<0.10",
"aioquic_mitmproxy>=0.9.21,<0.10",
"asgiref>=3.2.10,<3.8",
"Brotli>=1.0,<1.2",
"certifi>=2019.9.11", # no semver here - this should always be on the last release!
Expand Down Expand Up @@ -204,13 +205,13 @@ commands =
[testenv:mypy]
deps =
mypy==1.4.1
mypy==1.6.1
types-certifi==2021.10.8.3
types-Flask==1.1.6
types-Werkzeug==1.0.9
types-requests==2.31.0.2
types-requests==2.31.0.10
types-cryptography==3.3.23.2
types-pyOpenSSL==23.2.0.2
types-pyOpenSSL==23.3.0.0
-e .[dev]
commands =
Expand Down
48 changes: 24 additions & 24 deletions test/mitmproxy/addons/test_next_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def test_next_layer(self, monkeypatch, caplog):


@dataclass
class TestConf:
class TConf:
before: list[type[Layer]]
after: list[type[Layer]]
proxy_mode: str = "regular"
Expand All @@ -296,37 +296,37 @@ class TestConf:

explicit_proxy_configs = [
pytest.param(
TestConf(
TConf(
before=[modes.HttpProxy],
after=[modes.HttpProxy, HttpLayer],
),
id=f"explicit proxy: regular http",
),
pytest.param(
TestConf(
TConf(
before=[modes.HttpProxy],
after=[modes.HttpProxy, ClientTLSLayer, HttpLayer],
data_client=client_hello_no_extensions,
),
id=f"explicit proxy: secure web proxy",
),
pytest.param(
TestConf(
TConf(
before=[modes.HttpUpstreamProxy],
after=[modes.HttpUpstreamProxy, HttpLayer],
),
id=f"explicit proxy: upstream proxy",
),
pytest.param(
TestConf(
TConf(
before=[modes.HttpUpstreamProxy],
after=[modes.HttpUpstreamProxy, ClientQuicLayer, HttpLayer],
transport_protocol="udp",
),
id=f"explicit proxy: experimental http3",
),
pytest.param(
TestConf(
TConf(
before=[
modes.HttpProxy,
partial(HttpLayer, mode=HTTPMode.regular),
Expand All @@ -338,7 +338,7 @@ class TestConf:
id=f"explicit proxy: HTTP over regular proxy",
),
pytest.param(
TestConf(
TConf(
before=[
modes.HttpProxy,
partial(HttpLayer, mode=HTTPMode.regular),
Expand All @@ -356,7 +356,7 @@ class TestConf:
id=f"explicit proxy: TLS over regular proxy",
),
pytest.param(
TestConf(
TConf(
before=[
modes.HttpProxy,
partial(HttpLayer, mode=HTTPMode.regular),
Expand All @@ -377,7 +377,7 @@ class TestConf:
id=f"explicit proxy: HTTPS over regular proxy",
),
pytest.param(
TestConf(
TConf(
before=[
modes.HttpProxy,
partial(HttpLayer, mode=HTTPMode.regular),
Expand All @@ -404,15 +404,15 @@ class TestConf:
reverse_proxy_configs.extend(
[
pytest.param(
TestConf(
TConf(
before=[modes.ReverseProxy],
after=[modes.ReverseProxy, app_layer],
proxy_mode=f"reverse:{proto_plain}://example.com:42",
),
id=f"reverse proxy: {proto_plain} -> {proto_plain}",
),
pytest.param(
TestConf(
TConf(
before=[modes.ReverseProxy],
after=[
modes.ReverseProxy,
Expand All @@ -426,7 +426,7 @@ class TestConf:
id=f"reverse proxy: {proto_enc} -> {proto_enc}",
),
pytest.param(
TestConf(
TConf(
before=[modes.ReverseProxy],
after=[modes.ReverseProxy, ClientTLSLayer, app_layer],
proxy_mode=f"reverse:{proto_plain}://example.com:42",
Expand All @@ -435,7 +435,7 @@ class TestConf:
id=f"reverse proxy: {proto_enc} -> {proto_plain}",
),
pytest.param(
TestConf(
TConf(
before=[modes.ReverseProxy],
after=[modes.ReverseProxy, ServerTLSLayer, app_layer],
proxy_mode=f"reverse:{proto_enc}://example.com:42",
Expand All @@ -448,23 +448,23 @@ class TestConf:
reverse_proxy_configs.extend(
[
pytest.param(
TestConf(
TConf(
before=[modes.ReverseProxy],
after=[modes.ReverseProxy, DNSLayer],
proxy_mode="reverse:dns://example.com:53",
),
id="reverse proxy: dns",
),
pytest.param(
TestConf(
TConf(
before=[modes.ReverseProxy],
after=[modes.ReverseProxy, ServerQuicLayer, ClientQuicLayer, HttpLayer],
proxy_mode="reverse:http3://example.com",
),
id="reverse proxy: http3",
),
pytest.param(
TestConf(
TConf(
before=[modes.ReverseProxy],
after=[
modes.ReverseProxy,
Expand All @@ -481,15 +481,15 @@ class TestConf:

transparent_proxy_configs = [
pytest.param(
TestConf(
TConf(
before=[modes.TransparentProxy],
after=[modes.TransparentProxy, ServerTLSLayer, ClientTLSLayer],
data_client=client_hello_no_extensions,
),
id=f"transparent proxy: tls",
),
pytest.param(
TestConf(
TConf(
before=[modes.TransparentProxy],
after=[modes.TransparentProxy, ServerTLSLayer, ClientTLSLayer],
data_client=dtls_client_hello_with_extensions,
Expand All @@ -498,7 +498,7 @@ class TestConf:
id=f"transparent proxy: dtls",
),
pytest.param(
TestConf(
TConf(
before=[modes.TransparentProxy],
after=[modes.TransparentProxy, ServerQuicLayer, ClientQuicLayer],
data_client=quic_client_hello,
Expand All @@ -507,15 +507,15 @@ class TestConf:
id="transparent proxy: quic",
),
pytest.param(
TestConf(
TConf(
before=[modes.TransparentProxy],
after=[modes.TransparentProxy, TCPLayer],
data_server=b"220 service ready",
),
id="transparent proxy: raw tcp",
),
pytest.param(
http := TestConf(
http := TConf(
before=[modes.TransparentProxy],
after=[modes.TransparentProxy, HttpLayer],
data_client=b"GET / HTTP/1.1\r\n",
Expand All @@ -540,7 +540,7 @@ class TestConf:
id="transparent proxy: ignore_hosts",
),
pytest.param(
dns := TestConf(
dns := TConf(
before=[modes.TransparentProxy],
after=[modes.TransparentProxy, DNSLayer],
transport_protocol="udp",
Expand All @@ -549,7 +549,7 @@ class TestConf:
id="transparent proxy: dns",
),
pytest.param(
TestConf(
TConf(
before=[modes.TransparentProxy],
after=[modes.TransparentProxy, UDPLayer],
transport_protocol="udp",
Expand Down Expand Up @@ -577,7 +577,7 @@ class TestConf:
],
)
def test_next_layer(
test_conf: TestConf,
test_conf: TConf,
):
nl = NextLayer()
with taddons.context(nl) as tctx:
Expand Down
4 changes: 1 addition & 3 deletions test/mitmproxy/net/dns/test_domain_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ def test_pack():
name = f"www.{label}.com"
with pytest.raises(
ValueError,
match=re.escape(
"encoding with 'idna' codec failed (UnicodeError: label too long)"
),
match="label too long",
):
domain_names.pack(name)
assert domain_names.pack("www.example.org") == b"\x03www\x07example\x03org\x00"
8 changes: 4 additions & 4 deletions test/mitmproxy/proxy/layers/test_quic.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,20 +840,20 @@ def test_untrusted_cert(self, tctx: context.Context):
playbook
>> events.Wakeup(playbook.actual[9])
<< commands.Log(
"Server QUIC handshake failed. hostname 'wrong.host.mitmproxy.org' doesn't match 'example.mitmproxy.org'",
"Server QUIC handshake failed. Certificate does not match hostname 'wrong.host.mitmproxy.org'",
WARNING,
)
<< tls.TlsFailedServerHook(tls_hook_data)
>> tutils.reply()
<< commands.CloseConnection(tctx.server)
<< commands.SendData(
tctx.client,
b"open-connection failed: hostname 'wrong.host.mitmproxy.org' doesn't match 'example.mitmproxy.org'",
b"open-connection failed: Certificate does not match hostname 'wrong.host.mitmproxy.org'",
)
)
assert (
tls_hook_data().conn.error
== "hostname 'wrong.host.mitmproxy.org' doesn't match 'example.mitmproxy.org'"
== "Certificate does not match hostname 'wrong.host.mitmproxy.org'"
)
assert not tctx.server.tls_established

Expand Down Expand Up @@ -1133,7 +1133,7 @@ def test_mitmproxy_ca_is_untrusted(self, tctx: context.Context):
playbook
>> events.Wakeup(playbook.actual[7])
<< commands.Log(
"Client QUIC handshake failed. hostname 'wrong.host.mitmproxy.org' doesn't match 'example.mitmproxy.org'",
"Client QUIC handshake failed. Certificate does not match hostname 'wrong.host.mitmproxy.org'",
WARNING,
)
<< tls.TlsFailedClientHook(tls_hook_data)
Expand Down
10 changes: 7 additions & 3 deletions test/mitmproxy/proxy/test_mode_servers.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ async def test_last_exception_and_running(monkeypatch):
manager = MagicMock()
err = ValueError("something else")

async def _raise(*_):
def _raise(*_):
nonlocal err
raise err

async def _raise_async(*_):
nonlocal err
raise err

Expand All @@ -57,12 +61,12 @@ async def _raise(*_):
await inst1.start()
assert inst1.last_exception is None
assert inst1.is_running
monkeypatch.setattr(inst1._servers[0], "wait_closed", _raise)
monkeypatch.setattr(inst1._servers[0], "close", _raise)
with pytest.raises(type(err), match=str(err)):
await inst1.stop()
assert inst1.last_exception is err

monkeypatch.setattr(asyncio, "start_server", _raise)
monkeypatch.setattr(asyncio, "start_server", _raise_async)
inst2 = ServerInstance.make("[email protected]:0", manager)
assert inst2.last_exception is None
with pytest.raises(type(err), match=str(err)):
Expand Down

0 comments on commit c637032

Please sign in to comment.