Update alert notification (#2457)

This commit is contained in:
Joakim Sørensen 2021-01-23 21:06:55 +01:00 committed by GitHub
parent dccfffd979
commit 480eebc6cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 7 deletions

View File

@ -13,7 +13,7 @@ from .base import CheckBase
class SecurityReference(str, Enum): class SecurityReference(str, Enum):
"""Version references.""" """Version references."""
CUSTOM_COMPONENTS_BELOW_2021_1_3 = "custom_components_below_2021_1_3" CUSTOM_COMPONENTS_BELOW_2021_1_5 = "custom_components_below_2021_1_5"
class CheckCoreSecurity(CheckBase): class CheckCoreSecurity(CheckBase):
@ -22,14 +22,14 @@ class CheckCoreSecurity(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."""
try: try:
if self.sys_homeassistant.version < AwesomeVersion("2021.1.3"): if self.sys_homeassistant.version < AwesomeVersion("2021.1.5"):
if Path( if Path(
self.sys_config.path_homeassistant, "custom_components" self.sys_config.path_homeassistant, "custom_components"
).exists(): ).exists():
self.sys_resolution.create_issue( self.sys_resolution.create_issue(
IssueType.SECURITY, IssueType.SECURITY,
ContextType.CORE, ContextType.CORE,
reference=SecurityReference.CUSTOM_COMPONENTS_BELOW_2021_1_3, reference=SecurityReference.CUSTOM_COMPONENTS_BELOW_2021_1_5,
suggestions=[SuggestionType.EXECUTE_UPDATE], suggestions=[SuggestionType.EXECUTE_UPDATE],
) )
except AwesomeVersionException: except AwesomeVersionException:
@ -38,7 +38,7 @@ class CheckCoreSecurity(CheckBase):
async def approve_check(self) -> bool: async def approve_check(self) -> bool:
"""Approve check if it is affected by issue.""" """Approve check if it is affected by issue."""
try: try:
if self.sys_homeassistant.version >= AwesomeVersion("2021.1.3"): if self.sys_homeassistant.version >= AwesomeVersion("2021.1.5"):
return False return False
except AwesomeVersionException: except AwesomeVersionException:
return True return True

View File

@ -43,13 +43,13 @@ class ResolutionNotify(CoreSysAttributes):
if issue.type == IssueType.SECURITY and issue.context == ContextType.CORE: if issue.type == IssueType.SECURITY and issue.context == ContextType.CORE:
if ( if (
issue.reference issue.reference
== SecurityReference.CUSTOM_COMPONENTS_BELOW_2021_1_3 == SecurityReference.CUSTOM_COMPONENTS_BELOW_2021_1_5
): ):
messages.append( messages.append(
{ {
"title": "Security notification", "title": "Security notification",
"message": "The Supervisor detected that this version of Home Assistant could be insecure in combination with custom integrations. [Update as soon as possible.](/hassio/dashboard)\n\nFor more information see the [Security bulletin](https://www.home-assistant.io/blog/2021/01/14/security-bulletin/).", "message": "The Supervisor detected that this version of Home Assistant could be insecure in combination with custom integrations. [Update as soon as possible.](/hassio/dashboard)\n\nFor more information see the [Security alert](https://www.home-assistant.io/latest-security-alert).",
"notification_id": "supervisor_update_home_assistant_2021_1_3", "notification_id": "supervisor_update_home_assistant_2021_1_5",
} }
) )

View File

@ -31,6 +31,10 @@ async def test_check(coresys: CoreSys, tmp_path):
await core_security.run_check() await core_security.run_check()
assert len(coresys.resolution.issues) == 0 assert len(coresys.resolution.issues) == 0
coresys.homeassistant._data["version"] = AwesomeVersion("2021.1.5")
await core_security.run_check()
assert len(coresys.resolution.issues) == 0
coresys.homeassistant._data["version"] = AwesomeVersion("2021.1.2") coresys.homeassistant._data["version"] = AwesomeVersion("2021.1.2")
await core_security.run_check() await core_security.run_check()
assert len(coresys.resolution.issues) == 0 assert len(coresys.resolution.issues) == 0