1
0
mirror of https://github.com/home-assistant/supervisor.git synced 2026-05-08 17:08:36 +01:00
Files
supervisor/tests/test_security.py
T
Pascal Vizeli a2f43d8c7b Add add-on support for CAS (#3450)
* Add add-on support for CAS

* add tests

* Update tests/test_security.py

Co-authored-by: Mike Degatano <michael.degatano@gmail.com>

* address comments

* Address rating comments

Co-authored-by: Mike Degatano <michael.degatano@gmail.com>
2022-02-17 10:21:30 +01:00

56 lines
2.0 KiB
Python

"""Testing handling with Security."""
from unittest.mock import AsyncMock, patch
import pytest
from supervisor.coresys import CoreSys
from supervisor.exceptions import CodeNotaryError
async def test_content_trust(coresys: CoreSys):
"""Test Content-Trust."""
with patch("supervisor.security.cas_validate", AsyncMock()) as cas_validate:
await coresys.security.verify_content("test@mail.com", "ffffffffffffff")
assert cas_validate.called
cas_validate.assert_called_once_with("test@mail.com", "ffffffffffffff")
with patch("supervisor.security.cas_validate", AsyncMock()) as cas_validate:
await coresys.security.verify_own_content("ffffffffffffff")
assert cas_validate.called
cas_validate.assert_called_once_with(
"notary@home-assistant.io", "ffffffffffffff"
)
async def test_disabled_content_trust(coresys: CoreSys):
"""Test Content-Trust."""
coresys.security.content_trust = False
with patch("supervisor.security.cas_validate", AsyncMock()) as cas_validate:
await coresys.security.verify_content("test@mail.com", "ffffffffffffff")
assert not cas_validate.called
with patch("supervisor.security.cas_validate", AsyncMock()) as cas_validate:
await coresys.security.verify_own_content("ffffffffffffff")
assert not cas_validate.called
async def test_force_content_trust(coresys: CoreSys):
"""Force Content-Trust tests."""
with patch(
"supervisor.security.cas_validate", AsyncMock(side_effect=CodeNotaryError)
) as cas_validate:
await coresys.security.verify_content("test@mail.com", "ffffffffffffff")
assert cas_validate.called
cas_validate.assert_called_once_with("test@mail.com", "ffffffffffffff")
coresys.security.force = True
with patch(
"supervisor.security.cas_validate", AsyncMock(side_effect=CodeNotaryError)
) as cas_validate:
with pytest.raises(CodeNotaryError):
await coresys.security.verify_content("test@mail.com", "ffffffffffffff")