mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-11-08 18:39:33 +00:00
* Formally deprecate CodeNotary build config * Remove CodeNotary specific integrity checking The current code is specific to how CodeNotary was doing integrity checking. A future integrity checking mechanism likely will work differently (e.g. through EROFS based containers). Remove the current code to make way for a future implementation. * Drop CodeNotary integrity fixups * Drop unused tests * Fix pytest * Fix pytest * Remove CodeNotary related exceptions and handling Remove CodeNotary related exceptions and handling from the Docker interface. * Drop unnecessary comment * Remove Codenotary specific IssueType/SuggestionType * Drop Codenotary specific environment and secret reference * Remove unused constants * Introduce APIGone exception for removed APIs Introduce a new exception class APIGone to indicate that certain API features have been removed and are no longer available. Update the security integrity check endpoint to raise this new exception instead of a generic APIError, providing clearer communication to clients that the feature has been intentionally removed. * Drop content trust A cosign based signature verification will likely be named differently to avoid confusion with existing implementations. For now, remove the content trust option entirely. * Drop code sign test * Remove source_mods/content_trust evaluations * Remove content_trust reference in bootstrap.py * Fix security tests * Drop unused tests * Drop codenotary from schema Since we have "remove extra" in voluptuous, we can remove the codenotary field from the addon schema. * Remove content_trust from tests * Remove content_trust unsupported reason * Remove unnecessary comment * Remove unrelated pytest * Remove unrelated fixtures
117 lines
3.5 KiB
Python
117 lines
3.5 KiB
Python
"""Test check."""
|
|
|
|
# pylint: disable=import-error,protected-access
|
|
from unittest.mock import AsyncMock, patch
|
|
|
|
import pytest
|
|
|
|
from supervisor.const import CoreState
|
|
from supervisor.coresys import CoreSys
|
|
from supervisor.exceptions import ResolutionNotFound
|
|
from supervisor.resolution.const import ContextType, IssueType
|
|
from supervisor.resolution.data import Issue
|
|
from supervisor.resolution.validate import get_valid_modules
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def fixture_mock_dns_query():
|
|
"""Mock aiodns query."""
|
|
with (
|
|
patch(
|
|
"supervisor.resolution.checks.dns_server.DNSResolver.query",
|
|
new_callable=AsyncMock,
|
|
),
|
|
):
|
|
yield
|
|
|
|
|
|
async def test_check_setup(coresys: CoreSys):
|
|
"""Test check for setup."""
|
|
await coresys.core.set_state(CoreState.SETUP)
|
|
with patch(
|
|
"supervisor.resolution.checks.free_space.CheckFreeSpace.run_check",
|
|
return_value=False,
|
|
) as free_space:
|
|
await coresys.resolution.check.check_system()
|
|
free_space.assert_not_called()
|
|
|
|
|
|
async def test_check_running(coresys: CoreSys):
|
|
"""Test check for setup."""
|
|
await coresys.core.set_state(CoreState.RUNNING)
|
|
with patch(
|
|
"supervisor.resolution.checks.free_space.CheckFreeSpace.run_check",
|
|
return_value=False,
|
|
) as free_space:
|
|
await coresys.resolution.check.check_system()
|
|
free_space.assert_called_once()
|
|
|
|
|
|
async def test_if_check_make_issue(coresys: CoreSys):
|
|
"""Test check for setup."""
|
|
free_space = Issue(IssueType.FREE_SPACE, ContextType.SYSTEM)
|
|
await coresys.core.set_state(CoreState.RUNNING)
|
|
|
|
with patch("shutil.disk_usage", return_value=(1, 1, 1)):
|
|
await coresys.resolution.check.check_system()
|
|
|
|
assert free_space in coresys.resolution.issues
|
|
|
|
|
|
async def test_if_check_cleanup_issue(coresys: CoreSys):
|
|
"""Test check for setup."""
|
|
free_space = Issue(IssueType.FREE_SPACE, ContextType.SYSTEM)
|
|
await coresys.core.set_state(CoreState.RUNNING)
|
|
|
|
with patch("shutil.disk_usage", return_value=(1, 1, 1)):
|
|
await coresys.resolution.check.check_system()
|
|
|
|
assert free_space in coresys.resolution.issues
|
|
|
|
with patch("shutil.disk_usage", return_value=(42, 42, 3 * (1024.0**3))):
|
|
await coresys.resolution.check.check_system()
|
|
|
|
assert free_space not in coresys.resolution.issues
|
|
|
|
|
|
async def test_enable_disable_checks(coresys: CoreSys):
|
|
"""Test enable and disable check."""
|
|
await coresys.core.set_state(CoreState.RUNNING)
|
|
free_space = coresys.resolution.check.get("free_space")
|
|
|
|
# Ensure the check was enabled
|
|
assert free_space.enabled
|
|
|
|
free_space.enabled = False
|
|
assert not free_space.enabled
|
|
|
|
with patch(
|
|
"supervisor.resolution.checks.free_space.CheckFreeSpace.run_check",
|
|
return_value=False,
|
|
) as free_space:
|
|
await coresys.resolution.check.check_system()
|
|
free_space.assert_not_called()
|
|
|
|
free_space.enabled = True
|
|
assert free_space.enabled
|
|
|
|
|
|
async def test_get_checks(coresys: CoreSys):
|
|
"""Test get check with slug."""
|
|
|
|
with pytest.raises(ResolutionNotFound):
|
|
coresys.resolution.check.get("does_not_exsist")
|
|
|
|
assert coresys.resolution.check.get("free_space")
|
|
|
|
|
|
async def test_dynamic_check_loader(coresys: CoreSys):
|
|
"""Test dynamic check loader, this ensures that all checks have defined a setup function."""
|
|
|
|
def load_modules():
|
|
coresys.resolution.check.load_modules()
|
|
return get_valid_modules("checks")
|
|
|
|
for check in await coresys.run_in_executor(load_modules):
|
|
assert check in coresys.resolution.check._checks
|