forked from mtusi2026/mtusi2026lab7
32 lines
946 B
Python
32 lines
946 B
Python
import gzip
|
|
from contextlib import contextmanager
|
|
from types import SimpleNamespace
|
|
|
|
import httpx
|
|
|
|
from scripts.tls_client import FreshTrustTransport
|
|
|
|
|
|
def test_compressed_response_is_decoded_once(monkeypatch):
|
|
payload = gzip.compress(b'{"status":"ok"}')
|
|
|
|
@contextmanager
|
|
def transport(**kwargs):
|
|
yield SimpleNamespace(
|
|
handle_request=lambda request: httpx.Response(
|
|
200,
|
|
headers={"Content-Encoding": "gzip"},
|
|
stream=httpx.ByteStream(payload),
|
|
request=request,
|
|
)
|
|
)
|
|
|
|
monkeypatch.setattr(httpx, "HTTPTransport", transport)
|
|
monkeypatch.setattr(
|
|
"scripts.tls_client.ssl.create_default_context",
|
|
lambda **kwargs: SimpleNamespace(),
|
|
)
|
|
with httpx.Client(transport=FreshTrustTransport()) as client:
|
|
response = client.get("https://synthetic.invalid/")
|
|
assert response.json() == {"status": "ok"}
|