Skip to content

Commit 60811a2

Browse files
committed
adds test for upstream port and no port on proxy
1 parent a8c1370 commit 60811a2

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

tests/test_process_links.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,48 @@ def test_transform_upstream_links_with_ports(
215215
assert transformed["links"][i]["href"] == expected
216216

217217

218+
@pytest.mark.parametrize(
219+
"upstream_url,root_path,input_links,expected_links",
220+
[
221+
# Different ports
222+
(
223+
"http://upstream-api:8080/",
224+
"",
225+
[
226+
{
227+
"rel": "self",
228+
"href": "http://upstream-api:8080/collections",
229+
},
230+
],
231+
[
232+
"http://proxy.example.com/collections",
233+
],
234+
),
235+
],
236+
)
237+
def test_transform_upstream_links_with_port_only_upstream(
238+
upstream_url, root_path, input_links, expected_links
239+
):
240+
"""Test transforming upstream links with different ports."""
241+
middleware = ProcessLinksMiddleware(
242+
app=None, upstream_url=upstream_url, root_path=root_path
243+
)
244+
request_scope = {
245+
"type": "http",
246+
"path": "/test",
247+
"headers": [
248+
(b"host", f"proxy.example.com".encode()),
249+
(b"content-type", b"application/json"),
250+
],
251+
}
252+
253+
data = {"links": input_links}
254+
transformed = middleware.transform_json(data, Request(request_scope))
255+
256+
for i, expected in enumerate(expected_links):
257+
assert transformed["links"][i]["href"] == expected
258+
259+
218260
def test_transform_json_different_host():
219261
"""Test that links with different hostnames are not transformed."""
220262
middleware = ProcessLinksMiddleware(

0 commit comments

Comments
 (0)