From b446cab03b28d80bd62e1ad68ff87e5b3189829a Mon Sep 17 00:00:00 2001 From: Aaron Bach Date: Tue, 11 Oct 2022 13:14:07 -0600 Subject: [PATCH] Redact additional sensitive fields in ReCollect Waste diagnostics (#80119) * Redact additional sensitive fields in ReCollect Waste diagnostics * One call --- .../components/recollect_waste/diagnostics.py | 26 +++++++++++++++---- .../recollect_waste/test_diagnostics.py | 18 +++++++++++-- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/recollect_waste/diagnostics.py b/homeassistant/components/recollect_waste/diagnostics.py index fb19b1790f5..d410eb40085 100644 --- a/homeassistant/components/recollect_waste/diagnostics.py +++ b/homeassistant/components/recollect_waste/diagnostics.py @@ -4,11 +4,24 @@ from __future__ import annotations import dataclasses from typing import Any +from homeassistant.components.diagnostics import async_redact_data from homeassistant.config_entries import ConfigEntry +from homeassistant.const import CONF_UNIQUE_ID from homeassistant.core import HomeAssistant from homeassistant.helpers.update_coordinator import DataUpdateCoordinator -from .const import DOMAIN +from .const import CONF_PLACE_ID, DOMAIN + +CONF_AREA_NAME = "area_name" +CONF_TITLE = "title" + +TO_REDACT = { + CONF_AREA_NAME, + CONF_PLACE_ID, + # Config entry title and unique ID may contain sensitive data: + CONF_TITLE, + CONF_UNIQUE_ID, +} async def async_get_config_entry_diagnostics( @@ -17,7 +30,10 @@ async def async_get_config_entry_diagnostics( """Return diagnostics for a config entry.""" coordinator: DataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id] - return { - "entry": entry.as_dict(), - "data": [dataclasses.asdict(event) for event in coordinator.data], - } + return async_redact_data( + { + "entry": entry.as_dict(), + "data": [dataclasses.asdict(event) for event in coordinator.data], + }, + TO_REDACT, + ) diff --git a/tests/components/recollect_waste/test_diagnostics.py b/tests/components/recollect_waste/test_diagnostics.py index c9c9ba5a93f..93978135681 100644 --- a/tests/components/recollect_waste/test_diagnostics.py +++ b/tests/components/recollect_waste/test_diagnostics.py @@ -1,4 +1,6 @@ """Test ReCollect Waste diagnostics.""" +from homeassistant.components.diagnostics import REDACTED + from tests.components.diagnostics import get_diagnostics_for_config_entry @@ -7,7 +9,19 @@ async def test_entry_diagnostics( ): """Test config entry diagnostics.""" assert await get_diagnostics_for_config_entry(hass, hass_client, config_entry) == { - "entry": config_entry.as_dict(), + "entry": { + "entry_id": config_entry.entry_id, + "version": 2, + "domain": "recollect_waste", + "title": REDACTED, + "data": {"place_id": REDACTED, "service_id": "12345"}, + "options": {}, + "pref_disable_new_entities": False, + "pref_disable_polling": False, + "source": "user", + "unique_id": REDACTED, + "disabled_by": None, + }, "data": [ { "date": { @@ -17,7 +31,7 @@ async def test_entry_diagnostics( "pickup_types": [ {"name": "garbage", "friendly_name": "Trash Collection"} ], - "area_name": "The Sun", + "area_name": REDACTED, } ], }