1
0
mirror of https://github.com/home-assistant/supervisor.git synced 2026-05-08 08:58:31 +01:00

Always validate Backup before restoring (#5632)

* Validate Backup always before restoring

Since #5519 we check the encryption password early in restore case.
This has the side effect that we check the file existance early too.
However, in the non-encryption case, the file is not checked early.

This PR changes the behavior to always validate the backup file before
restoring, ensuring both encryption and non-encryption cases are
handled consistently.

In particular, the last case of test_restore_immediate_errors actually
validates that behavior. That test should actually have failed so far.
But it seems that because we validate the backup shortly after freeze
anyways, the exception still got raised early enough.

A simply `await asyncio.sleep(10)` right after the freeze makes the
test case fail. With this change, the test works consistently.

* Address pylint

* Fix backup_manager tests

* Drop warning message
This commit is contained in:
Stefan Agner
2025-02-14 18:19:35 +01:00
committed by GitHub
parent 9b2dbd634d
commit 4c108eea64
6 changed files with 49 additions and 41 deletions
+2 -2
View File
@@ -344,7 +344,7 @@ async def test_fail_invalid_full_backup(
backup_instance = full_backup_mock.return_value
backup_instance.all_locations[None]["protected"] = True
backup_instance.validate_password = AsyncMock(return_value=False)
backup_instance.validate_backup.side_effect = BackupInvalidError()
with pytest.raises(BackupInvalidError):
await manager.do_restore_full(backup_instance)
@@ -373,7 +373,7 @@ async def test_fail_invalid_partial_backup(
backup_instance = partial_backup_mock.return_value
backup_instance.all_locations[None]["protected"] = True
backup_instance.validate_password = AsyncMock(return_value=False)
backup_instance.validate_backup.side_effect = BackupInvalidError()
with pytest.raises(BackupInvalidError):
await manager.do_restore_partial(backup_instance)