mirror of
https://github.com/mitmproxy/mitmproxy.git
synced 2024-11-23 05:09:57 +00:00
69f455b962
Some checks failed
autofix.ci / autofix (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / filename-matching (push) Has been cancelled
CI / mypy (push) Has been cancelled
CI / individual-coverage (push) Has been cancelled
CI / test (macos-latest, 3.13) (push) Has been cancelled
CI / test (ubuntu-latest, 3.10) (push) Has been cancelled
CI / test (ubuntu-latest, 3.11) (push) Has been cancelled
CI / test (ubuntu-latest, 3.12) (push) Has been cancelled
CI / test (ubuntu-latest, 3.13) (push) Has been cancelled
CI / test (windows-latest, 3.13) (push) Has been cancelled
CI / test-old-dependencies (push) Has been cancelled
CI / build (macos-13, macos-x86_64) (push) Has been cancelled
CI / build (macos-14, macos-arm64) (push) Has been cancelled
CI / build (ubuntu-20.04, linux) (push) Has been cancelled
CI / build (windows-2019, windows) (push) Has been cancelled
CI / build-wheel (push) Has been cancelled
CI / build-windows-installer (push) Has been cancelled
CI / test-web-ui (push) Has been cancelled
CI / docs (push) Has been cancelled
CI / test-docker (push) Has been cancelled
CI / check (push) Has been cancelled
CI / deploy-docker (push) Has been cancelled
CI / deploy (push) Has been cancelled
* simplify stream handling callback * add `tun` proxy mode from mitmproxy_rs * tun mode: tests++ * [autofix.ci] apply automated fixes * bump mitmproxy_rs * fix bugs * ci: use macOS 13 for builds as 12 is being phased out * test debugging * bump mitmproxy_rs * bump python version in ci, 3.13 is stable now * nits * is unshare to blame? * how about this? * coverage++ * [autofix.ci] apply automated fixes * debüg * debüüg * debüüüg * bump mitmproxy_rs --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
76 lines
1.8 KiB
Python
76 lines
1.8 KiB
Python
from __future__ import annotations
|
|
|
|
import asyncio
|
|
import os
|
|
import platform
|
|
import socket
|
|
import sys
|
|
|
|
import pytest
|
|
|
|
from mitmproxy.utils import data
|
|
|
|
skip_windows = pytest.mark.skipif(os.name == "nt", reason="Skipping due to Windows")
|
|
|
|
skip_not_windows = pytest.mark.skipif(
|
|
os.name != "nt", reason="Skipping due to not Windows"
|
|
)
|
|
|
|
skip_not_linux = pytest.mark.skipif(
|
|
platform.system() != "Linux", reason="Skipping due to not Linux"
|
|
)
|
|
|
|
try:
|
|
s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
|
|
s.bind(("::1", 0))
|
|
s.close()
|
|
except OSError:
|
|
no_ipv6 = True
|
|
else:
|
|
no_ipv6 = False
|
|
|
|
skip_no_ipv6 = pytest.mark.skipif(no_ipv6, reason="Host has no IPv6 support")
|
|
|
|
|
|
class EagerTaskCreationEventLoopPolicy(asyncio.DefaultEventLoopPolicy):
|
|
def new_event_loop(self):
|
|
loop = super().new_event_loop()
|
|
if sys.version_info >= (3, 12):
|
|
loop.set_task_factory(asyncio.eager_task_factory)
|
|
return loop
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def event_loop_policy(request):
|
|
return EagerTaskCreationEventLoopPolicy()
|
|
|
|
|
|
@pytest.fixture()
|
|
def tdata():
|
|
return data.Data(__name__)
|
|
|
|
|
|
class AsyncLogCaptureFixture:
|
|
def __init__(self, caplog: pytest.LogCaptureFixture):
|
|
self.caplog = caplog
|
|
|
|
def set_level(self, level: int | str, logger: str | None = None) -> None:
|
|
self.caplog.set_level(level, logger)
|
|
|
|
async def await_log(self, text, timeout=2):
|
|
await asyncio.sleep(0)
|
|
for i in range(int(timeout / 0.01)):
|
|
if text in self.caplog.text:
|
|
return True
|
|
else:
|
|
await asyncio.sleep(0.01)
|
|
raise AssertionError(f"Did not find {text!r} in log:\n{self.caplog.text}")
|
|
|
|
def clear(self) -> None:
|
|
self.caplog.clear()
|
|
|
|
|
|
@pytest.fixture
|
|
def caplog_async(caplog):
|
|
return AsyncLogCaptureFixture(caplog)
|