Fix ingress bug with Firefox (#23121)
* Fix ingress bug with Firefox * Fix mock * Fix tests * Fix test lint
This commit is contained in:
1 parent
60c787c2e6
commit
7a78d65633
4 files changed
+81
-10
No files matched your search
@@ -1,7 +1,6 @@
|
||||
"""The tests for the hassio component."""
|
||||
|
||||
from aiohttp.hdrs import X_FORWARDED_FOR, X_FORWARDED_HOST, X_FORWARDED_PROTO
|
||||
from aiohttp.client_exceptions import WSServerHandshakeError
|
||||
import pytest
|
||||
|
||||
|
||||
@@ -137,6 +136,72 @@ async def test_ingress_request_delete(
|
||||
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_patch(
|
||||
hassio_client, build_type, aioclient_mock):
|
||||
"""Test no auth needed for ."""
|
||||
aioclient_mock.patch("http://127.0.0.1/ingress/{}/{}".format(
|
||||
build_type[0], build_type[1]), text="test")
|
||||
|
||||
resp = await hassio_client.patch(
|
||||
'/api/hassio_ingress/{}/{}'.format(build_type[0], build_type[1]),
|
||||
headers={"X-Test-Header": "beer"}
|
||||
)
|
||||
|
||||
# Check we got right response
|
||||
assert resp.status == 200
|
||||
body = await resp.text()
|
||||
assert body == "test"
|
||||
|
||||
# Check we forwarded command
|
||||
assert len(aioclient_mock.mock_calls) == 1
|
||||
assert aioclient_mock.mock_calls[-1][3]["X-Hassio-Key"] == "123456"
|
||||
assert aioclient_mock.mock_calls[-1][3]["X-Ingress-Path"] == \
|
||||
"/api/hassio_ingress/{}".format(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', [
|
||||
("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_options(
|
||||
hassio_client, build_type, aioclient_mock):
|
||||
"""Test no auth needed for ."""
|
||||
aioclient_mock.options("http://127.0.0.1/ingress/{}/{}".format(
|
||||
build_type[0], build_type[1]), text="test")
|
||||
|
||||
resp = await hassio_client.options(
|
||||
'/api/hassio_ingress/{}/{}'.format(build_type[0], build_type[1]),
|
||||
headers={"X-Test-Header": "beer"}
|
||||
)
|
||||
|
||||
# Check we got right response
|
||||
assert resp.status == 200
|
||||
body = await resp.text()
|
||||
assert body == "test"
|
||||
|
||||
# Check we forwarded command
|
||||
assert len(aioclient_mock.mock_calls) == 1
|
||||
assert aioclient_mock.mock_calls[-1][3]["X-Hassio-Key"] == "123456"
|
||||
assert aioclient_mock.mock_calls[-1][3]["X-Ingress-Path"] == \
|
||||
"/api/hassio_ingress/{}".format(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', [
|
||||
("a3_vl", "test/beer/ws"), ("core", "ws.php"),
|
||||
@@ -150,11 +215,10 @@ async def test_ingress_websocket(
|
||||
build_type[0], build_type[1]))
|
||||
|
||||
# Ignore error because we can setup a full IO infrastructure
|
||||
with pytest.raises(WSServerHandshakeError):
|
||||
await hassio_client.ws_connect(
|
||||
'/api/hassio_ingress/{}/{}'.format(build_type[0], build_type[1]),
|
||||
headers={"X-Test-Header": "beer"}
|
||||
)
|
||||
await hassio_client.ws_connect(
|
||||
'/api/hassio_ingress/{}/{}'.format(build_type[0], build_type[1]),
|
||||
headers={"X-Test-Header": "beer"}
|
||||
)
|
||||
|
||||
# Check we forwarded command
|
||||
assert len(aioclient_mock.mock_calls) == 1
|
||||
|
||||
Reference in new issue
Block a user