diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_net.py | 62 |
1 files changed, 31 insertions, 31 deletions
diff --git a/tests/test_net.py b/tests/test_net.py index 24785ee..472ae91 100644 --- a/tests/test_net.py +++ b/tests/test_net.py @@ -31,6 +31,37 @@ from webmentions_ssg.net import ( ) +class FakeStream(httpcore.NetworkStream): + """In-memory TCP/TLS stream so HTTP framing and SNI can be tested.""" + + def __init__(self, response: bytes) -> None: + self.response = response + self.writes = bytearray() + self.sni: str | None = None + + def read(self, max_bytes: int, timeout: float | None = None) -> bytes: + part, self.response = self.response[:max_bytes], self.response[max_bytes:] + return part + + def write(self, buffer: bytes, timeout: float | None = None) -> None: + self.writes.extend(buffer) + + def start_tls( + self, + ssl_context, + server_hostname: str | None = None, + timeout: float | None = None, + ) -> httpcore.NetworkStream: + self.sni = server_hostname + return self + + def get_extra_info(self, info: str): + return None + + def close(self) -> None: + pass + + @pytest.mark.parametrize("host", ["127.0.0.1", "169.254.169.254", "::1"]) def test_backend_rejects_private_ip_without_socket( monkeypatch: pytest.MonkeyPatch, host: str @@ -125,37 +156,6 @@ def test_read_limited_body_raises_specific_size_error(mode: str) -> None: read_limited_body(response, 10, label="Source") -class FakeStream(httpcore.NetworkStream): - """In-memory TCP/TLS stream so HTTP framing and SNI can be tested.""" - - def __init__(self, response: bytes) -> None: - self.response = response - self.writes = bytearray() - self.sni: str | None = None - - def read(self, max_bytes: int, timeout: float | None = None) -> bytes: - part, self.response = self.response[:max_bytes], self.response[max_bytes:] - return part - - def write(self, buffer: bytes, timeout: float | None = None) -> None: - self.writes.extend(buffer) - - def start_tls( - self, - ssl_context, - server_hostname: str | None = None, - timeout: float | None = None, - ) -> httpcore.NetworkStream: - self.sni = server_hostname - return self - - def get_extra_info(self, info: str): - return None - - def close(self) -> None: - pass - - @pytest.mark.parametrize("scheme", ["http", "https"]) def test_transport_keeps_original_http_host_and_tls_sni( monkeypatch: pytest.MonkeyPatch, scheme: str |
