mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-12-24 20:35:55 +00:00
Check management (#2703)
* Check management * Add test * Don't allow disable core_security * options and decorator * streamline config handling * streamline v2 * fix logging * Add tests * Fix test * cleanup v1 * fix api * Add more test * Expose option also for cli * address comments from Paulus * Address second comment * Update supervisor/resolution/checks/base.py Co-authored-by: Paulus Schoutsen <balloob@gmail.com> * fix lint * Fix black Co-authored-by: Pascal Vizeli <pvizeli@syshack.ch> Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
@@ -6,40 +6,35 @@ import pytest
|
||||
# pylint: disable=redefined-outer-name
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def stub_auth():
|
||||
"""Bypass auth check."""
|
||||
with patch("supervisor.api.ingress.APIIngress._check_ha_access") as mock_auth:
|
||||
yield mock_auth
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_validate_session(stub_auth, api_client, coresys):
|
||||
async def test_validate_session(api_client, coresys):
|
||||
"""Test validating ingress session."""
|
||||
coresys.core.sys_homeassistant.supervisor_token = "ABCD"
|
||||
resp = await api_client.post(
|
||||
"/ingress/validate_session",
|
||||
json={"session": "non-existing"},
|
||||
)
|
||||
assert resp.status == 401
|
||||
assert len(stub_auth.mock_calls) == 1
|
||||
with patch("aiohttp.web_request.BaseRequest.__getitem__", return_value=None):
|
||||
resp = await api_client.post(
|
||||
"/ingress/validate_session",
|
||||
json={"session": "non-existing"},
|
||||
)
|
||||
assert resp.status == 401
|
||||
|
||||
resp = await api_client.post("/ingress/session")
|
||||
result = await resp.json()
|
||||
assert len(stub_auth.mock_calls) == 2
|
||||
with patch(
|
||||
"aiohttp.web_request.BaseRequest.__getitem__",
|
||||
return_value=coresys.homeassistant,
|
||||
):
|
||||
|
||||
assert "session" in result["data"]
|
||||
session = result["data"]["session"]
|
||||
assert session in coresys.ingress.sessions
|
||||
resp = await api_client.post("/ingress/session")
|
||||
result = await resp.json()
|
||||
|
||||
valid_time = coresys.ingress.sessions[session]
|
||||
assert "session" in result["data"]
|
||||
session = result["data"]["session"]
|
||||
assert session in coresys.ingress.sessions
|
||||
|
||||
resp = await api_client.post(
|
||||
"/ingress/validate_session",
|
||||
json={"session": session},
|
||||
)
|
||||
assert resp.status == 200
|
||||
assert len(stub_auth.mock_calls) == 3
|
||||
assert await resp.json() == {"result": "ok", "data": {}}
|
||||
valid_time = coresys.ingress.sessions[session]
|
||||
|
||||
assert coresys.ingress.sessions[session] > valid_time
|
||||
resp = await api_client.post(
|
||||
"/ingress/validate_session",
|
||||
json={"session": session},
|
||||
)
|
||||
assert resp.status == 200
|
||||
assert await resp.json() == {"result": "ok", "data": {}}
|
||||
|
||||
assert coresys.ingress.sessions[session] > valid_time
|
||||
|
||||
Reference in New Issue
Block a user