From 28215d7edd550563235a541a4cbf80ed10176a7b Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Thu, 29 Nov 2018 22:26:19 +0100 Subject: [PATCH] Make auth backwards compat again (#18792) * Made auth not backwards compat * Fix tests --- homeassistant/auth/auth_store.py | 3 ++- tests/auth/test_auth_store.py | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/homeassistant/auth/auth_store.py b/homeassistant/auth/auth_store.py index cf82c40a4d3..bad1bdcf913 100644 --- a/homeassistant/auth/auth_store.py +++ b/homeassistant/auth/auth_store.py @@ -462,10 +462,11 @@ class AuthStore: for group in self._groups.values(): g_dict = { 'id': group.id, + # Name not read for sys groups. Kept here for backwards compat + 'name': group.name } # type: Dict[str, Any] if group.id not in (GROUP_ID_READ_ONLY, GROUP_ID_ADMIN): - g_dict['name'] = group.name g_dict['policy'] = group.policy groups.append(g_dict) diff --git a/tests/auth/test_auth_store.py b/tests/auth/test_auth_store.py index b76d68fbeac..7e9df869a04 100644 --- a/tests/auth/test_auth_store.py +++ b/tests/auth/test_auth_store.py @@ -199,13 +199,22 @@ async def test_loading_empty_data(hass, hass_storage): assert len(users) == 0 -async def test_system_groups_only_store_id(hass, hass_storage): - """Test that for system groups we only store the ID.""" +async def test_system_groups_store_id_and_name(hass, hass_storage): + """Test that for system groups we store the ID and name. + + Name is stored so that we remain backwards compat with < 0.82. + """ store = auth_store.AuthStore(hass) await store._async_load() data = store._data_to_save() assert len(data['users']) == 0 assert data['groups'] == [ - {'id': auth_store.GROUP_ID_ADMIN}, - {'id': auth_store.GROUP_ID_READ_ONLY}, + { + 'id': auth_store.GROUP_ID_ADMIN, + 'name': auth_store.GROUP_NAME_ADMIN, + }, + { + 'id': auth_store.GROUP_ID_READ_ONLY, + 'name': auth_store.GROUP_NAME_READ_ONLY, + }, ]