mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 17:27:10 +00:00
Fix missing head forwarding in ingress (#144231)
* Add support for connect, head and trace in ingress * added tests * update the testutil * fix * fix empty space * removed connect * remove trace
This commit is contained in:
parent
36a08d04c5
commit
c73383ded3
@ -109,6 +109,7 @@ class HassIOIngress(HomeAssistantView):
|
||||
delete = _handle
|
||||
patch = _handle
|
||||
options = _handle
|
||||
head = _handle
|
||||
|
||||
async def _handle_websocket(
|
||||
self, request: web.Request, token: str, path: str
|
||||
|
@ -269,6 +269,49 @@ async def test_ingress_request_options(
|
||||
assert aioclient_mock.mock_calls[-1][3][X_FORWARDED_PROTO]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"build_type",
|
||||
[
|
||||
("a3_vl", "test/beer/ping?index=1"),
|
||||
("core", "index.html"),
|
||||
("local", "panel/config"),
|
||||
("jk_921", "editor.php?idx=3&ping=5"),
|
||||
("fsadjf10312", ""),
|
||||
],
|
||||
)
|
||||
async def test_ingress_request_head(
|
||||
hassio_noauth_client, build_type, aioclient_mock: AiohttpClientMocker
|
||||
) -> None:
|
||||
"""Test no auth needed for ."""
|
||||
aioclient_mock.head(
|
||||
f"http://127.0.0.1/ingress/{build_type[0]}/{build_type[1]}",
|
||||
text="test",
|
||||
)
|
||||
|
||||
resp = await hassio_noauth_client.head(
|
||||
f"/api/hassio_ingress/{build_type[0]}/{build_type[1]}",
|
||||
headers={"X-Test-Header": "beer"},
|
||||
)
|
||||
|
||||
# Check we got right response
|
||||
assert resp.status == HTTPStatus.OK
|
||||
body = await resp.text()
|
||||
assert body == "" # head does not return a body
|
||||
|
||||
# Check we forwarded command
|
||||
assert len(aioclient_mock.mock_calls) == 1
|
||||
assert X_AUTH_TOKEN not in aioclient_mock.mock_calls[-1][3]
|
||||
assert aioclient_mock.mock_calls[-1][3]["X-Hass-Source"] == "core.ingress"
|
||||
assert (
|
||||
aioclient_mock.mock_calls[-1][3]["X-Ingress-Path"]
|
||||
== f"/api/hassio_ingress/{build_type[0]}"
|
||||
)
|
||||
assert aioclient_mock.mock_calls[-1][3]["X-Test-Header"] == "beer"
|
||||
assert aioclient_mock.mock_calls[-1][3][X_FORWARDED_FOR]
|
||||
assert aioclient_mock.mock_calls[-1][3][X_FORWARDED_HOST]
|
||||
assert aioclient_mock.mock_calls[-1][3][X_FORWARDED_PROTO]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"build_type",
|
||||
[
|
||||
|
@ -110,6 +110,10 @@ class AiohttpClientMocker:
|
||||
"""Register a mock patch request."""
|
||||
self.request("patch", *args, **kwargs)
|
||||
|
||||
def head(self, *args, **kwargs):
|
||||
"""Register a mock head request."""
|
||||
self.request("head", *args, **kwargs)
|
||||
|
||||
@property
|
||||
def call_count(self):
|
||||
"""Return the number of requests made."""
|
||||
|
Loading…
x
Reference in New Issue
Block a user