From e58ce7ab6e05dd24955f20b2de7fead4afd0c6e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Tue, 1 Mar 2022 21:37:51 +0100 Subject: [PATCH] Fix returned value from backup/info WS command (#67439) --- homeassistant/components/backup/manager.py | 3 ++- homeassistant/components/backup/websocket.py | 2 +- tests/components/backup/test_websocket.py | 11 ++++++++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/backup/manager.py b/homeassistant/components/backup/manager.py index 80498450453..bc037287c09 100644 --- a/homeassistant/components/backup/manager.py +++ b/homeassistant/components/backup/manager.py @@ -5,6 +5,7 @@ from dataclasses import asdict, dataclass import hashlib import json from pathlib import Path +import tarfile from tarfile import TarError from tempfile import TemporaryDirectory @@ -51,7 +52,7 @@ class BackupManager: def _read_backups() -> None: for backup_path in self.backup_dir.glob("*.tar"): try: - with SecureTarFile(backup_path, "r", gzip=False) as backup_file: + with tarfile.open(backup_path, "r:") as backup_file: if data_file := backup_file.extractfile("./backup.json"): data = json.loads(data_file.read()) backup = Backup( diff --git a/homeassistant/components/backup/websocket.py b/homeassistant/components/backup/websocket.py index 5e2d5a99d31..5c12a764941 100644 --- a/homeassistant/components/backup/websocket.py +++ b/homeassistant/components/backup/websocket.py @@ -30,7 +30,7 @@ async def handle_info( connection.send_result( msg["id"], { - "backups": list(backups), + "backups": list(backups.values()), "backing_up": manager.backing_up, }, ) diff --git a/tests/components/backup/test_websocket.py b/tests/components/backup/test_websocket.py index dbdeb33c927..4179eb026c5 100644 --- a/tests/components/backup/test_websocket.py +++ b/tests/components/backup/test_websocket.py @@ -20,12 +20,17 @@ async def test_info( client = await hass_ws_client(hass) await hass.async_block_till_done() - await client.send_json({"id": 1, "type": "backup/info"}) - msg = await client.receive_json() + with patch( + "homeassistant.components.backup.websocket.BackupManager.get_backups", + return_value={TEST_BACKUP.slug: TEST_BACKUP}, + ): + + await client.send_json({"id": 1, "type": "backup/info"}) + msg = await client.receive_json() assert msg["id"] == 1 assert msg["success"] - assert msg["result"] == {"backing_up": False, "backups": []} + assert msg["result"] == {"backing_up": False, "backups": [TEST_BACKUP.as_dict()]} async def test_remove(