forked from mtusi2026/mtusi2026lab7
fix(test-client): preserve encoded response bytes across TLS transport
This commit is contained in:
@@ -18,6 +18,6 @@ class FreshTrustTransport(httpx.BaseTransport):
|
|||||||
return httpx.Response(
|
return httpx.Response(
|
||||||
response.status_code,
|
response.status_code,
|
||||||
headers=response.headers,
|
headers=response.headers,
|
||||||
content=response.read(),
|
stream=httpx.ByteStream(b"".join(response.iter_raw())),
|
||||||
request=request,
|
request=request,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
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"}
|
||||||
Reference in New Issue
Block a user