|
13 | 13 | from aiohttp.client import ClientSession |
14 | 14 |
|
15 | 15 | from backup.file import File |
| 16 | +from backup.logger import getHistory |
16 | 17 | from backup.util import AsyncHttpGetter, GlobalInfo, DataCache, UpgradeFlags |
17 | 18 | from backup.ui import UiServer, Restarter |
18 | | -from backup.config import Config, Setting, CreateOptions |
| 19 | +from backup.config import Config, Setting, CreateOptions, Version |
19 | 20 | from backup.const import (ERROR_CREDS_EXPIRED, ERROR_EXISTING_FOLDER, |
| 21 | + ERROR_GOOGLE_CRED_PROCESS, |
20 | 22 | ERROR_MULTIPLE_DELETES, ERROR_NO_BACKUP, |
21 | 23 | SOURCE_GOOGLE_DRIVE, SOURCE_HA) |
22 | 24 | from backup.creds import Creds |
|
29 | 31 | from .helpers import compareStreams |
30 | 32 | from yarl import URL |
31 | 33 | from dev.ports import Ports |
| 34 | +from dev.request_interceptor import RequestInterceptor |
32 | 35 | from dev.simulated_supervisor import SimulatedSupervisor |
33 | 36 | from dev.simulationserver import SimulationServer |
34 | 37 | from dev.simulated_google import SimulatedGoogle |
@@ -1200,3 +1203,32 @@ async def test_oob_warning(reader: ReaderHelper, ui_server: UiServer, config: Co |
1200 | 1203 | @pytest.mark.asyncio |
1201 | 1204 | async def test_url_sanitize(ui_server: UiServer): |
1202 | 1205 | assert ui_server._sanitize(URL("http://localhost/test?client_id=im_a_secret&client_secret=im_a_secret&ignore=shown")) == URL("http://localhost/test?client_id=redacted&client_secret=redacted&ignore=shown") |
| 1206 | + assert ui_server._sanitize(URL("http://localhost/token?creds=im_a_serialized_refresh_token&host=shown")) == URL("http://localhost/token?creds=redacted&host=shown") |
| 1207 | + |
| 1208 | + |
| 1209 | +@pytest.mark.asyncio |
| 1210 | +async def test_manualauth_error_redacts_credentials(reader: ReaderHelper, interceptor: RequestInterceptor): |
| 1211 | + """Credentials passed to manualauth must never reach the logs when a request fails (issue #1001)""" |
| 1212 | + interceptor.setError("/device/code", status=401) |
| 1213 | + await reader.assertError("manualauth?client_id=super_secret_id&client_secret=super_secret_value", error_type=ERROR_GOOGLE_CRED_PROCESS) |
| 1214 | + logs = "\n".join(line for _, line in getHistory(0, False)) |
| 1215 | + assert "Error serving" in logs |
| 1216 | + assert "super_secret_id" not in logs |
| 1217 | + assert "super_secret_value" not in logs |
| 1218 | + assert "client_secret=redacted" in logs |
| 1219 | + |
| 1220 | + |
| 1221 | +@pytest.mark.asyncio |
| 1222 | +async def test_restore_link_current_ha(reader: ReaderHelper): |
| 1223 | + """Home Assistant 2025.1 and later hosts backups at Settings > System > Backups (issue #1151)""" |
| 1224 | + status = await reader.getjson("getstatus") |
| 1225 | + assert status['restore_backup_path'] == "config/backup/backups" |
| 1226 | + |
| 1227 | + |
| 1228 | +@pytest.mark.asyncio |
| 1229 | +async def test_restore_link_old_ha(reader: ReaderHelper, supervisor: SimulatedSupervisor, ha: HaSource): |
| 1230 | + """Home Assistant older than 2025.1 uses the old hassio/backups panel""" |
| 1231 | + supervisor._core_version = Version(2024, 12) |
| 1232 | + await ha.refresh() |
| 1233 | + status = await reader.getjson("getstatus") |
| 1234 | + assert status['restore_backup_path'] == "hassio/backups" |
0 commit comments