1
mirror of https://github.com/home-assistant/core synced 2024-07-24 16:42:06 +02:00

Fix trusted_users group schema (#92847)

* Fix trusted_users group schema

* Add tests for CONFIG_SCHEMA
This commit is contained in:
Patrick Li 2023-05-24 06:11:25 +12:00 committed by GitHub
parent fa366e59e0
commit 46103f56c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 1 deletions

View File

@ -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}),
)
],
)

View File

@ -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")