2019-04-01 12:16:16 +00:00
|
|
|
"""The tests for the hassio component."""
|
|
|
|
|
|
|
|
from aiohttp.hdrs import X_FORWARDED_FOR, X_FORWARDED_HOST, X_FORWARDED_PROTO
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
2019-07-31 19:25:30 +00:00
|
|
|
"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_get(hassio_client, build_type, aioclient_mock):
|
2019-04-01 12:16:16 +00:00
|
|
|
"""Test no auth needed for ."""
|
2019-07-31 19:25:30 +00:00
|
|
|
aioclient_mock.get(
|
|
|
|
"http://127.0.0.1/ingress/{}/{}".format(build_type[0], build_type[1]),
|
|
|
|
text="test",
|
|
|
|
)
|
2019-04-01 12:16:16 +00:00
|
|
|
|
|
|
|
resp = await hassio_client.get(
|
2019-07-31 19:25:30 +00:00
|
|
|
"/api/hassio_ingress/{}/{}".format(build_type[0], build_type[1]),
|
|
|
|
headers={"X-Test-Header": "beer"},
|
2019-04-01 12:16:16 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# 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"
|
2019-07-31 19:25:30 +00:00
|
|
|
assert aioclient_mock.mock_calls[-1][3][
|
|
|
|
"X-Ingress-Path"
|
|
|
|
] == "/api/hassio_ingress/{}".format(build_type[0])
|
2019-04-01 12:16:16 +00:00
|
|
|
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(
|
2019-07-31 19:25:30 +00:00
|
|
|
"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_post(hassio_client, build_type, aioclient_mock):
|
2019-04-01 12:16:16 +00:00
|
|
|
"""Test no auth needed for ."""
|
2019-07-31 19:25:30 +00:00
|
|
|
aioclient_mock.post(
|
|
|
|
"http://127.0.0.1/ingress/{}/{}".format(build_type[0], build_type[1]),
|
|
|
|
text="test",
|
|
|
|
)
|
2019-04-01 12:16:16 +00:00
|
|
|
|
|
|
|
resp = await hassio_client.post(
|
2019-07-31 19:25:30 +00:00
|
|
|
"/api/hassio_ingress/{}/{}".format(build_type[0], build_type[1]),
|
|
|
|
headers={"X-Test-Header": "beer"},
|
2019-04-01 12:16:16 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# 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"
|
2019-07-31 19:25:30 +00:00
|
|
|
assert aioclient_mock.mock_calls[-1][3][
|
|
|
|
"X-Ingress-Path"
|
|
|
|
] == "/api/hassio_ingress/{}".format(build_type[0])
|
2019-04-01 12:16:16 +00:00
|
|
|
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(
|
2019-07-31 19:25:30 +00:00
|
|
|
"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_put(hassio_client, build_type, aioclient_mock):
|
2019-04-01 12:16:16 +00:00
|
|
|
"""Test no auth needed for ."""
|
2019-07-31 19:25:30 +00:00
|
|
|
aioclient_mock.put(
|
|
|
|
"http://127.0.0.1/ingress/{}/{}".format(build_type[0], build_type[1]),
|
|
|
|
text="test",
|
|
|
|
)
|
2019-04-01 12:16:16 +00:00
|
|
|
|
|
|
|
resp = await hassio_client.put(
|
2019-07-31 19:25:30 +00:00
|
|
|
"/api/hassio_ingress/{}/{}".format(build_type[0], build_type[1]),
|
|
|
|
headers={"X-Test-Header": "beer"},
|
2019-04-01 12:16:16 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# 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"
|
2019-07-31 19:25:30 +00:00
|
|
|
assert aioclient_mock.mock_calls[-1][3][
|
|
|
|
"X-Ingress-Path"
|
|
|
|
] == "/api/hassio_ingress/{}".format(build_type[0])
|
2019-04-01 12:16:16 +00:00
|
|
|
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(
|
2019-07-31 19:25:30 +00:00
|
|
|
"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_delete(hassio_client, build_type, aioclient_mock):
|
2019-04-01 12:16:16 +00:00
|
|
|
"""Test no auth needed for ."""
|
2019-07-31 19:25:30 +00:00
|
|
|
aioclient_mock.delete(
|
|
|
|
"http://127.0.0.1/ingress/{}/{}".format(build_type[0], build_type[1]),
|
|
|
|
text="test",
|
|
|
|
)
|
2019-04-01 12:16:16 +00:00
|
|
|
|
|
|
|
resp = await hassio_client.delete(
|
2019-07-31 19:25:30 +00:00
|
|
|
"/api/hassio_ingress/{}/{}".format(build_type[0], build_type[1]),
|
|
|
|
headers={"X-Test-Header": "beer"},
|
2019-04-01 12:16:16 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# 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"
|
2019-07-31 19:25:30 +00:00
|
|
|
assert aioclient_mock.mock_calls[-1][3][
|
|
|
|
"X-Ingress-Path"
|
|
|
|
] == "/api/hassio_ingress/{}".format(build_type[0])
|
2019-04-01 12:16:16 +00:00
|
|
|
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]
|
|
|
|
|
|
|
|
|
2019-04-15 22:27:13 +00:00
|
|
|
@pytest.mark.parametrize(
|
2019-07-31 19:25:30 +00:00
|
|
|
"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):
|
2019-04-15 22:27:13 +00:00
|
|
|
"""Test no auth needed for ."""
|
2019-07-31 19:25:30 +00:00
|
|
|
aioclient_mock.patch(
|
|
|
|
"http://127.0.0.1/ingress/{}/{}".format(build_type[0], build_type[1]),
|
|
|
|
text="test",
|
|
|
|
)
|
2019-04-15 22:27:13 +00:00
|
|
|
|
|
|
|
resp = await hassio_client.patch(
|
2019-07-31 19:25:30 +00:00
|
|
|
"/api/hassio_ingress/{}/{}".format(build_type[0], build_type[1]),
|
|
|
|
headers={"X-Test-Header": "beer"},
|
2019-04-15 22:27:13 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# 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"
|
2019-07-31 19:25:30 +00:00
|
|
|
assert aioclient_mock.mock_calls[-1][3][
|
|
|
|
"X-Ingress-Path"
|
|
|
|
] == "/api/hassio_ingress/{}".format(build_type[0])
|
2019-04-15 22:27:13 +00:00
|
|
|
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(
|
2019-07-31 19:25:30 +00:00
|
|
|
"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):
|
2019-04-15 22:27:13 +00:00
|
|
|
"""Test no auth needed for ."""
|
2019-07-31 19:25:30 +00:00
|
|
|
aioclient_mock.options(
|
|
|
|
"http://127.0.0.1/ingress/{}/{}".format(build_type[0], build_type[1]),
|
|
|
|
text="test",
|
|
|
|
)
|
2019-04-15 22:27:13 +00:00
|
|
|
|
|
|
|
resp = await hassio_client.options(
|
2019-07-31 19:25:30 +00:00
|
|
|
"/api/hassio_ingress/{}/{}".format(build_type[0], build_type[1]),
|
|
|
|
headers={"X-Test-Header": "beer"},
|
2019-04-15 22:27:13 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# 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"
|
2019-07-31 19:25:30 +00:00
|
|
|
assert aioclient_mock.mock_calls[-1][3][
|
|
|
|
"X-Ingress-Path"
|
|
|
|
] == "/api/hassio_ingress/{}".format(build_type[0])
|
2019-04-15 22:27:13 +00:00
|
|
|
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]
|
|
|
|
|
|
|
|
|
2019-04-01 12:16:16 +00:00
|
|
|
@pytest.mark.parametrize(
|
2019-07-31 19:25:30 +00:00
|
|
|
"build_type",
|
|
|
|
[
|
|
|
|
("a3_vl", "test/beer/ws"),
|
|
|
|
("core", "ws.php"),
|
|
|
|
("local", "panel/config/stream"),
|
|
|
|
("jk_921", "hulk"),
|
|
|
|
("demo", "ws/connection?id=9&token=SJAKWS283"),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
async def test_ingress_websocket(hassio_client, build_type, aioclient_mock):
|
2019-04-01 12:16:16 +00:00
|
|
|
"""Test no auth needed for ."""
|
2019-07-31 19:25:30 +00:00
|
|
|
aioclient_mock.get(
|
|
|
|
"http://127.0.0.1/ingress/{}/{}".format(build_type[0], build_type[1])
|
|
|
|
)
|
2019-04-01 12:16:16 +00:00
|
|
|
|
|
|
|
# Ignore error because we can setup a full IO infrastructure
|
2019-04-15 22:27:13 +00:00
|
|
|
await hassio_client.ws_connect(
|
2019-07-31 19:25:30 +00:00
|
|
|
"/api/hassio_ingress/{}/{}".format(build_type[0], build_type[1]),
|
|
|
|
headers={"X-Test-Header": "beer"},
|
2019-04-15 22:27:13 +00:00
|
|
|
)
|
2019-04-01 12:16:16 +00:00
|
|
|
|
|
|
|
# Check we forwarded command
|
|
|
|
assert len(aioclient_mock.mock_calls) == 1
|
|
|
|
assert aioclient_mock.mock_calls[-1][3]["X-Hassio-Key"] == "123456"
|
2019-07-31 19:25:30 +00:00
|
|
|
assert aioclient_mock.mock_calls[-1][3][
|
|
|
|
"X-Ingress-Path"
|
|
|
|
] == "/api/hassio_ingress/{}".format(build_type[0])
|
2019-04-01 12:16:16 +00:00
|
|
|
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]
|