From 46103f56c4d1c601b30832c18ffb84f62d56bda9 Mon Sep 17 00:00:00 2001 From: Patrick Li Date: Wed, 24 May 2023 06:11:25 +1200 Subject: [PATCH] Fix trusted_users group schema (#92847) * Fix trusted_users group schema * Add tests for CONFIG_SCHEMA --- .../auth/providers/trusted_networks.py | 2 +- tests/auth/providers/test_trusted_networks.py | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/homeassistant/auth/providers/trusted_networks.py b/homeassistant/auth/providers/trusted_networks.py index a6c4c19b02fc..04db5fc287b7 100644 --- a/homeassistant/auth/providers/trusted_networks.py +++ b/homeassistant/auth/providers/trusted_networks.py @@ -46,7 +46,7 @@ CONFIG_SCHEMA = AUTH_PROVIDER_SCHEMA.extend( [ vol.Or( cv.uuid4_hex, - vol.Schema({vol.Required(CONF_GROUP): cv.uuid4_hex}), + vol.Schema({vol.Required(CONF_GROUP): str}), ) ], ) diff --git a/tests/auth/providers/test_trusted_networks.py b/tests/auth/providers/test_trusted_networks.py index 53d1f0a9fa76..a098eea28e07 100644 --- a/tests/auth/providers/test_trusted_networks.py +++ b/tests/auth/providers/test_trusted_networks.py @@ -116,6 +116,32 @@ def manager_bypass_login(hass, store, provider_bypass_login): ) +async def test_config_schema(): + """Test CONFIG_SCHEMA.""" + # Valid configuration + tn_auth.CONFIG_SCHEMA( + { + "type": "trusted_networks", + "trusted_networks": ["192.168.0.1"], + "trusted_users": { + "192.168.0.1": [ + "a1ab982744b64757bf80515589258924", + {"group": "system-group"}, + ] + }, + } + ) + # Wrong user id format + with pytest.raises(vol.Invalid): + tn_auth.CONFIG_SCHEMA( + { + "type": "trusted_networks", + "trusted_networks": ["192.168.0.1"], + "trusted_users": {"192.168.0.1": ["abcde"]}, + } + ) + + async def test_trusted_networks_credentials(manager, provider) -> None: """Test trusted_networks credentials related functions.""" owner = await manager.async_create_user("test-owner")