39 lines
1.6 KiB
Python
39 lines
1.6 KiB
Python
"""Diagnostics download must not leak secrets or network identity."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
|
|
from homeassistant.core import HomeAssistant
|
|
from pytest_homeassistant_custom_component.components.diagnostics import (
|
|
get_diagnostics_for_config_entry,
|
|
)
|
|
from pytest_homeassistant_custom_component.typing import ClientSessionGenerator
|
|
|
|
from custom_components.ninlight.shared import DATA_SHARED, async_scan_catalog
|
|
from tests_unit.images import build_image
|
|
from tests_unit.samples import HOST_RGB, MAC_RGB, TOKEN
|
|
|
|
|
|
async def test_diagnostics_redacts_secrets(
|
|
hass: HomeAssistant, hass_client: ClientSessionGenerator, init_integration
|
|
) -> None:
|
|
diagnostics = await get_diagnostics_for_config_entry(hass, hass_client, init_integration)
|
|
text = json.dumps(diagnostics)
|
|
for secret in (TOKEN, MAC_RGB, "ninIOT", HOST_RGB):
|
|
assert secret not in text, secret
|
|
assert diagnostics["info"]["device_type"] == "gu10_rgb"
|
|
assert diagnostics["state"]["brightness"] == 37
|
|
|
|
|
|
async def test_diagnostics_lists_matching_firmware(
|
|
hass: HomeAssistant, hass_client: ClientSessionGenerator, init_integration, firmware_dir
|
|
) -> None:
|
|
(firmware_dir / "rgb.img").write_bytes(build_image("gu10_rgb", "0.3.8-47-g71a57"))
|
|
(firmware_dir / "cw.img").write_bytes(build_image("gu10_cw", "0.3.8-47-g71a57"))
|
|
await async_scan_catalog(hass, hass.data[DATA_SHARED])
|
|
diagnostics = await get_diagnostics_for_config_entry(hass, hass_client, init_integration)
|
|
assert diagnostics["firmware_images"] == [
|
|
{"file": "rgb.img", "device_type": "gu10_rgb", "version": "0.3.8-47-g71a57"}
|
|
]
|