mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-15 13:16:29 +00:00
Fix addon_pwned enabled setter (#2952)
* Fix addon_pwned enabled setter * whatever * adjust
This commit is contained in:
parent
ce57d384ca
commit
4f9e646b4c
@ -1,5 +1,6 @@
|
|||||||
"""Helpers to check core security."""
|
"""Helpers to check core security."""
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
import logging
|
||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
|
|
||||||
from ...const import AddonState, CoreState
|
from ...const import AddonState, CoreState
|
||||||
@ -10,6 +11,8 @@ from ...jobs.decorator import Job
|
|||||||
from ..const import ContextType, IssueType, SuggestionType
|
from ..const import ContextType, IssueType, SuggestionType
|
||||||
from .base import CheckBase
|
from .base import CheckBase
|
||||||
|
|
||||||
|
_LOGGER: logging.Logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def setup(coresys: CoreSys) -> CheckBase:
|
def setup(coresys: CoreSys) -> CheckBase:
|
||||||
"""Check setup function."""
|
"""Check setup function."""
|
||||||
@ -19,13 +22,6 @@ def setup(coresys: CoreSys) -> CheckBase:
|
|||||||
class CheckAddonPwned(CheckBase):
|
class CheckAddonPwned(CheckBase):
|
||||||
"""CheckAddonPwned class for check."""
|
"""CheckAddonPwned class for check."""
|
||||||
|
|
||||||
@property
|
|
||||||
def enabled(self) -> bool:
|
|
||||||
"""Return True if the check is enabled."""
|
|
||||||
if not self.sys_security.pwned:
|
|
||||||
return False
|
|
||||||
return super().enabled
|
|
||||||
|
|
||||||
@Job(
|
@Job(
|
||||||
conditions=[JobCondition.INTERNET_SYSTEM],
|
conditions=[JobCondition.INTERNET_SYSTEM],
|
||||||
limit=JobExecutionLimit.THROTTLE,
|
limit=JobExecutionLimit.THROTTLE,
|
||||||
@ -33,6 +29,9 @@ class CheckAddonPwned(CheckBase):
|
|||||||
)
|
)
|
||||||
async def run_check(self) -> None:
|
async def run_check(self) -> None:
|
||||||
"""Run check if not affected by issue."""
|
"""Run check if not affected by issue."""
|
||||||
|
if not self.sys_security.pwned:
|
||||||
|
_LOGGER.warning("Skipping %s, pwned is globally disabled", self.slug)
|
||||||
|
return
|
||||||
await self.sys_homeassistant.secrets.reload()
|
await self.sys_homeassistant.secrets.reload()
|
||||||
|
|
||||||
for addon in self.sys_addons.installed:
|
for addon in self.sys_addons.installed:
|
||||||
|
@ -77,6 +77,22 @@ async def test_approve(coresys: CoreSys):
|
|||||||
assert not await addon_pwned.approve_check(reference=addon.slug)
|
assert not await addon_pwned.approve_check(reference=addon.slug)
|
||||||
|
|
||||||
|
|
||||||
|
async def test_with_global_disable(coresys: CoreSys, caplog):
|
||||||
|
"""Test when pwned is globally disabled."""
|
||||||
|
coresys.security.pwned = False
|
||||||
|
addon_pwned = CheckAddonPwned(coresys)
|
||||||
|
coresys.core.state = CoreState.RUNNING
|
||||||
|
|
||||||
|
addon = TestAddon()
|
||||||
|
coresys.addons.local[addon.slug] = addon
|
||||||
|
|
||||||
|
assert len(coresys.resolution.issues) == 0
|
||||||
|
coresys.security.verify_secret = AsyncMock(side_effect=PwnedSecret)
|
||||||
|
await addon_pwned.run_check.__wrapped__(addon_pwned)
|
||||||
|
assert not coresys.security.verify_secret.called
|
||||||
|
assert "Skipping addon_pwned, pwned is globally disabled" in caplog.text
|
||||||
|
|
||||||
|
|
||||||
async def test_did_run(coresys: CoreSys):
|
async def test_did_run(coresys: CoreSys):
|
||||||
"""Test that the check ran as expected."""
|
"""Test that the check ran as expected."""
|
||||||
addon_pwned = CheckAddonPwned(coresys)
|
addon_pwned = CheckAddonPwned(coresys)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user