mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-06-24 02:46:30 +00:00

* Revert "Disable CAS until it work (#3504)" This reverts commit 435241bccf3f3c678161b50cfefd4b036f1daba9. * Revert exception that are not forwarded * enable for add-ons * Apply suggestions from code review Co-authored-by: Mike Degatano <michael.degatano@gmail.com> * fix black Co-authored-by: Mike Degatano <michael.degatano@gmail.com>
45 lines
1.5 KiB
Python
45 lines
1.5 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")
|
|
|
|
|
|
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
|
|
|
|
|
|
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")
|