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:
Eliz 2025-05-05 18:11:41 +01:00 committed by GitHub
parent 36a08d04c5
commit c73383ded3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 48 additions and 0 deletions

View File

@ -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

View File

@ -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",
[

View File

@ -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."""