-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_proxy.py
40 lines (30 loc) · 1.35 KB
/
test_proxy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""Test authentication cases for the proxy app."""
from fastapi.testclient import TestClient
from utils import AppFactory, get_upstream_request
app_factory = AppFactory(
oidc_discovery_url="https://example-stac-api.com/.well-known/openid-configuration",
default_public=True,
public_endpoints={},
private_endpoints={},
)
async def test_proxied_headers_no_encoding(source_api_server, mock_upstream):
"""Clients that don't accept encoding should not receive it."""
test_app = app_factory(upstream_url=source_api_server)
client = TestClient(test_app)
req = client.build_request(method="GET", url="/", headers={})
for h in req.headers:
if h in ["accept-encoding"]:
del req.headers[h]
client.send(req)
proxied_request = await get_upstream_request(mock_upstream)
assert "accept-encoding" not in proxied_request.headers
async def test_proxied_headers_with_encoding(source_api_server, mock_upstream):
"""Clients that do accept encoding should receive it."""
test_app = app_factory(upstream_url=source_api_server)
client = TestClient(test_app)
req = client.build_request(
method="GET", url="/", headers={"accept-encoding": "gzip"}
)
client.send(req)
proxied_request = await get_upstream_request(mock_upstream)
assert proxied_request.headers.get("accept-encoding") == "gzip"