1
0
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:
Joakim Sørensen
2021-03-12 11:32:56 +01:00
committed by GitHub
parent a52713611c
commit 73849b7468
20 changed files with 276 additions and 74 deletions

View File

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