mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-05-10 04:48:40 +00:00

* 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>
41 lines
1.2 KiB
Python
41 lines
1.2 KiB
Python
"""Test ingress API."""
|
|
from unittest.mock import patch
|
|
|
|
import pytest
|
|
|
|
# pylint: disable=redefined-outer-name
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_validate_session(api_client, coresys):
|
|
"""Test validating ingress session."""
|
|
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
|
|
|
|
with patch(
|
|
"aiohttp.web_request.BaseRequest.__getitem__",
|
|
return_value=coresys.homeassistant,
|
|
):
|
|
|
|
resp = await api_client.post("/ingress/session")
|
|
result = await resp.json()
|
|
|
|
assert "session" in result["data"]
|
|
session = result["data"]["session"]
|
|
assert session in coresys.ingress.sessions
|
|
|
|
valid_time = coresys.ingress.sessions[session]
|
|
|
|
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
|