mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-11-09 19:09:41 +00:00
Fix pytest
This commit is contained in:
@@ -41,11 +41,10 @@ async def test_api_security_options_pwned(api_client, coresys: CoreSys):
|
|||||||
async def test_api_integrity_check(
|
async def test_api_integrity_check(
|
||||||
api_client, coresys: CoreSys, supervisor_internet: AsyncMock
|
api_client, coresys: CoreSys, supervisor_internet: AsyncMock
|
||||||
):
|
):
|
||||||
"""Test security integrity check."""
|
"""Test security integrity check - now deprecated."""
|
||||||
coresys.security.content_trust = False
|
|
||||||
|
|
||||||
resp = await api_client.post("/security/integrity")
|
resp = await api_client.post("/security/integrity")
|
||||||
result = await resp.json()
|
result = await resp.json()
|
||||||
|
|
||||||
assert result["data"]["core"] == "untested"
|
# CodeNotary integrity check has been removed
|
||||||
assert result["data"]["supervisor"] == "untested"
|
assert "error" in result["data"]
|
||||||
|
assert "deprecated" in result["data"]["error"].lower()
|
||||||
|
|||||||
@@ -32,15 +32,6 @@ from supervisor.jobs import JobSchedulerOptions, SupervisorJob
|
|||||||
from tests.common import load_json_fixture
|
from tests.common import load_json_fixture
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
|
||||||
def mock_verify_content(coresys: CoreSys):
|
|
||||||
"""Mock verify_content utility during tests."""
|
|
||||||
with patch.object(
|
|
||||||
coresys.security, "verify_content", return_value=None
|
|
||||||
) as verify_content:
|
|
||||||
yield verify_content
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"cpu_arch, platform",
|
"cpu_arch, platform",
|
||||||
[
|
[
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ from supervisor.exceptions import (
|
|||||||
AudioJobError,
|
AudioJobError,
|
||||||
CliError,
|
CliError,
|
||||||
CliJobError,
|
CliJobError,
|
||||||
CodeNotaryUntrusted,
|
|
||||||
CoreDNSError,
|
CoreDNSError,
|
||||||
CoreDNSJobError,
|
CoreDNSJobError,
|
||||||
DockerError,
|
DockerError,
|
||||||
@@ -337,14 +336,12 @@ async def test_repair_failed(
|
|||||||
patch.object(
|
patch.object(
|
||||||
DockerInterface, "arch", new=PropertyMock(return_value=CpuArch.AMD64)
|
DockerInterface, "arch", new=PropertyMock(return_value=CpuArch.AMD64)
|
||||||
),
|
),
|
||||||
patch(
|
patch.object(DockerInterface, "install", side_effect=DockerError),
|
||||||
"supervisor.security.module.cas_validate", side_effect=CodeNotaryUntrusted
|
|
||||||
),
|
|
||||||
):
|
):
|
||||||
await plugin.repair()
|
await plugin.repair()
|
||||||
|
|
||||||
capture_exception.assert_called_once()
|
capture_exception.assert_called_once()
|
||||||
assert check_exception_chain(capture_exception.call_args[0][0], CodeNotaryUntrusted)
|
assert check_exception_chain(capture_exception.call_args[0][0], DockerError)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
|
|||||||
@@ -1,40 +1,22 @@
|
|||||||
"""Test evaluation base."""
|
"""Test evaluation base."""
|
||||||
|
|
||||||
# pylint: disable=import-error,protected-access
|
# pylint: disable=import-error,protected-access
|
||||||
import errno
|
from unittest.mock import patch
|
||||||
import os
|
|
||||||
from pathlib import Path
|
|
||||||
from unittest.mock import AsyncMock, patch
|
|
||||||
|
|
||||||
from supervisor.const import CoreState
|
from supervisor.const import CoreState
|
||||||
from supervisor.coresys import CoreSys
|
from supervisor.coresys import CoreSys
|
||||||
from supervisor.exceptions import CodeNotaryError, CodeNotaryUntrusted
|
|
||||||
from supervisor.resolution.const import ContextType, IssueType
|
|
||||||
from supervisor.resolution.data import Issue
|
|
||||||
from supervisor.resolution.evaluations.source_mods import EvaluateSourceMods
|
from supervisor.resolution.evaluations.source_mods import EvaluateSourceMods
|
||||||
|
|
||||||
|
|
||||||
async def test_evaluation(coresys: CoreSys):
|
async def test_evaluation(coresys: CoreSys):
|
||||||
"""Test evaluation."""
|
"""Test evaluation - CodeNotary removed."""
|
||||||
with patch(
|
sourcemods = EvaluateSourceMods(coresys)
|
||||||
"supervisor.resolution.evaluations.source_mods._SUPERVISOR_SOURCE",
|
await coresys.core.set_state(CoreState.RUNNING)
|
||||||
Path(f"{os.getcwd()}/supervisor"),
|
|
||||||
):
|
|
||||||
sourcemods = EvaluateSourceMods(coresys)
|
|
||||||
await coresys.core.set_state(CoreState.RUNNING)
|
|
||||||
|
|
||||||
assert sourcemods.reason not in coresys.resolution.unsupported
|
# CodeNotary checking removed, evaluation always returns False now
|
||||||
coresys.security.verify_own_content = AsyncMock(side_effect=CodeNotaryUntrusted)
|
assert sourcemods.reason not in coresys.resolution.unsupported
|
||||||
await sourcemods()
|
await sourcemods()
|
||||||
assert sourcemods.reason in coresys.resolution.unsupported
|
assert sourcemods.reason not in coresys.resolution.unsupported
|
||||||
|
|
||||||
coresys.security.verify_own_content = AsyncMock(side_effect=CodeNotaryError)
|
|
||||||
await sourcemods()
|
|
||||||
assert sourcemods.reason not in coresys.resolution.unsupported
|
|
||||||
|
|
||||||
coresys.security.verify_own_content = AsyncMock()
|
|
||||||
await sourcemods()
|
|
||||||
assert sourcemods.reason not in coresys.resolution.unsupported
|
|
||||||
|
|
||||||
|
|
||||||
async def test_did_run(coresys: CoreSys):
|
async def test_did_run(coresys: CoreSys):
|
||||||
@@ -63,27 +45,11 @@ async def test_did_run(coresys: CoreSys):
|
|||||||
|
|
||||||
|
|
||||||
async def test_evaluation_error(coresys: CoreSys):
|
async def test_evaluation_error(coresys: CoreSys):
|
||||||
"""Test error reading file during evaluation."""
|
"""Test error reading file during evaluation - CodeNotary removed."""
|
||||||
sourcemods = EvaluateSourceMods(coresys)
|
sourcemods = EvaluateSourceMods(coresys)
|
||||||
await coresys.core.set_state(CoreState.RUNNING)
|
await coresys.core.set_state(CoreState.RUNNING)
|
||||||
corrupt_fs = Issue(IssueType.CORRUPT_FILESYSTEM, ContextType.SYSTEM)
|
|
||||||
|
|
||||||
|
# CodeNotary checking removed, evaluation always returns False now
|
||||||
|
assert sourcemods.reason not in coresys.resolution.unsupported
|
||||||
|
await sourcemods()
|
||||||
assert sourcemods.reason not in coresys.resolution.unsupported
|
assert sourcemods.reason not in coresys.resolution.unsupported
|
||||||
assert corrupt_fs not in coresys.resolution.issues
|
|
||||||
|
|
||||||
with patch(
|
|
||||||
"supervisor.utils.codenotary.dirhash",
|
|
||||||
side_effect=(err := OSError()),
|
|
||||||
):
|
|
||||||
err.errno = errno.EBUSY
|
|
||||||
await sourcemods()
|
|
||||||
assert sourcemods.reason not in coresys.resolution.unsupported
|
|
||||||
assert corrupt_fs in coresys.resolution.issues
|
|
||||||
assert coresys.core.healthy is True
|
|
||||||
|
|
||||||
coresys.resolution.dismiss_issue(corrupt_fs)
|
|
||||||
err.errno = errno.EBADMSG
|
|
||||||
await sourcemods()
|
|
||||||
assert sourcemods.reason not in coresys.resolution.unsupported
|
|
||||||
assert corrupt_fs in coresys.resolution.issues
|
|
||||||
assert coresys.core.healthy is False
|
|
||||||
|
|||||||
@@ -86,10 +86,10 @@ async def test_os_update_path(
|
|||||||
"""Test OS upgrade path across major versions."""
|
"""Test OS upgrade path across major versions."""
|
||||||
coresys.os._board = "rpi4" # pylint: disable=protected-access
|
coresys.os._board = "rpi4" # pylint: disable=protected-access
|
||||||
coresys.os._version = AwesomeVersion(version) # pylint: disable=protected-access
|
coresys.os._version = AwesomeVersion(version) # pylint: disable=protected-access
|
||||||
with patch.object(type(coresys.security), "verify_own_content"):
|
# CodeNotary verification removed
|
||||||
await coresys.updater.fetch_data()
|
await coresys.updater.fetch_data()
|
||||||
|
|
||||||
assert coresys.updater.version_hassos == AwesomeVersion(expected)
|
assert coresys.updater.version_hassos == AwesomeVersion(expected)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("no_job_throttle")
|
@pytest.mark.usefixtures("no_job_throttle")
|
||||||
@@ -105,7 +105,6 @@ async def test_delayed_fetch_for_connectivity(
|
|||||||
load_binary_fixture("version_stable.json")
|
load_binary_fixture("version_stable.json")
|
||||||
)
|
)
|
||||||
coresys.websession.head = AsyncMock()
|
coresys.websession.head = AsyncMock()
|
||||||
coresys.security.verify_own_content = AsyncMock()
|
|
||||||
|
|
||||||
# Network connectivity change causes a series of async tasks to eventually do a version fetch
|
# Network connectivity change causes a series of async tasks to eventually do a version fetch
|
||||||
# Rather then use some kind of sleep loop, set up listener for start of fetch data job
|
# Rather then use some kind of sleep loop, set up listener for start of fetch data job
|
||||||
|
|||||||
Reference in New Issue
Block a user