1
0
mirror of https://github.com/home-assistant/supervisor.git synced 2025-12-24 12:29:08 +00:00

Force / Enforce security if service is not available (#2744)

* Force / Enforce security if service is not available

* add options

* Add tests

* force security on test

* force security add-on validation

* Adjust style like codenotary

* Different exception type for backend error

* Adjust messages

* add comments

* ditch, not needed

* Address comment

* fix build
This commit is contained in:
Pascal Vizeli
2021-03-24 14:36:23 +01:00
committed by GitHub
parent b9af4aec6b
commit 82f76f60bd
15 changed files with 136 additions and 56 deletions

View File

@@ -4,6 +4,7 @@ from unittest.mock import AsyncMock, patch
from supervisor.const import AddonState, CoreState
from supervisor.coresys import CoreSys
from supervisor.exceptions import PwnedSecret
from supervisor.resolution.checks.addon_pwned import CheckAddonPwned
from supervisor.resolution.const import IssueType, SuggestionType
@@ -36,7 +37,7 @@ async def test_check(coresys: CoreSys):
with patch(
"supervisor.resolution.checks.addon_pwned.check_pwned_password",
AsyncMock(return_value=True),
AsyncMock(side_effect=PwnedSecret()),
) as mock:
await addon_pwned.run_check.__wrapped__(addon_pwned)
assert not mock.called
@@ -44,7 +45,7 @@ async def test_check(coresys: CoreSys):
addon.pwned.add("123456")
with patch(
"supervisor.resolution.checks.addon_pwned.check_pwned_password",
AsyncMock(return_value=False),
AsyncMock(return_value=None),
) as mock:
await addon_pwned.run_check.__wrapped__(addon_pwned)
assert mock.called
@@ -53,7 +54,7 @@ async def test_check(coresys: CoreSys):
with patch(
"supervisor.resolution.checks.addon_pwned.check_pwned_password",
AsyncMock(return_value=True),
AsyncMock(side_effect=PwnedSecret()),
) as mock:
await addon_pwned.run_check.__wrapped__(addon_pwned)
assert mock.called
@@ -76,20 +77,20 @@ async def test_approve(coresys: CoreSys):
with patch(
"supervisor.resolution.checks.addon_pwned.check_pwned_password",
AsyncMock(return_value=True),
AsyncMock(side_effect=PwnedSecret()),
):
assert await addon_pwned.approve_check(reference=addon.slug)
with patch(
"supervisor.resolution.checks.addon_pwned.check_pwned_password",
AsyncMock(return_value=False),
AsyncMock(return_value=None),
):
assert not await addon_pwned.approve_check(reference=addon.slug)
addon.is_installed = False
with patch(
"supervisor.resolution.checks.addon_pwned.check_pwned_password",
AsyncMock(return_value=True),
AsyncMock(side_effect=PwnedSecret()),
):
assert not await addon_pwned.approve_check(reference=addon.slug)