Compare commits

...

1 Commits

Author SHA1 Message Date
abmantis
c8d86ee454 Remove external url from config for local_only users 2026-01-29 20:07:22 +00:00
2 changed files with 21 additions and 3 deletions

View File

@@ -14,6 +14,7 @@ from homeassistant.auth.models import User
from homeassistant.auth.permissions.const import POLICY_READ
from homeassistant.auth.permissions.events import SUBSCRIBE_ALLOWLIST
from homeassistant.const import (
CONF_EXTERNAL_URL,
EVENT_STATE_CHANGED,
MATCH_ALL,
SIGNAL_BOOTSTRAP_INTEGRATIONS,
@@ -650,7 +651,12 @@ def handle_get_config(
hass: HomeAssistant, connection: ActiveConnection, msg: dict[str, Any]
) -> None:
"""Handle get config command."""
connection.send_result(msg["id"], hass.config.as_dict())
config = hass.config.as_dict()
if connection.user.local_only:
config.pop(CONF_EXTERNAL_URL)
connection.send_result(msg["id"], config)
@decorators.websocket_command(

View File

@@ -34,7 +34,7 @@ from homeassistant.components.websocket_api.commands import (
)
from homeassistant.components.websocket_api.const import FEATURE_COALESCE_MESSAGES, URL
from homeassistant.config_entries import ConfigEntryState
from homeassistant.const import SIGNAL_BOOTSTRAP_INTEGRATIONS
from homeassistant.const import CONF_EXTERNAL_URL, SIGNAL_BOOTSTRAP_INTEGRATIONS
from homeassistant.core import Context, HomeAssistant, State, SupportsResponse, callback
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
from homeassistant.helpers import (
@@ -1139,10 +1139,18 @@ async def test_subscribe_triggers(
assert hass.data[ALL_TRIGGER_DESCRIPTIONS_JSON_CACHE] is old_cache
@pytest.mark.parametrize(
("local_only_user", "forbidden_keys"), [(False, []), (True, [CONF_EXTERNAL_URL])]
)
async def test_get_config(
hass: HomeAssistant, websocket_client: MockHAClientWebSocket
hass: HomeAssistant,
websocket_client: MockHAClientWebSocket,
hass_admin_user: MockUser,
local_only_user: bool,
forbidden_keys: list[str],
) -> None:
"""Test get_config command."""
hass_admin_user.local_only = local_only_user
await websocket_client.send_json_auto_id({"type": "get_config"})
msg = await websocket_client.receive_json()
@@ -1163,6 +1171,10 @@ async def test_get_config(
result[key] = set(result[key])
config[key] = set(config[key])
for key in forbidden_keys:
assert key in config
config.pop(key)
assert result == config