From 1f6331c69d5873fa308611236bc92a1ed8d2835e Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Tue, 10 Jul 2018 20:33:03 +0200 Subject: [PATCH] Fix credentials lookup (#15409) --- homeassistant/auth.py | 5 +---- tests/test_auth.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/homeassistant/auth.py b/homeassistant/auth.py index ae191f24c61..c84f5e83ef0 100644 --- a/homeassistant/auth.py +++ b/homeassistant/auth.py @@ -311,10 +311,7 @@ class AuthManager: if not credentials.is_new: for user in await self._store.async_get_users(): for creds in user.credentials: - if (creds.auth_provider_type == - credentials.auth_provider_type - and creds.auth_provider_id == - credentials.auth_provider_id): + if creds.id == credentials.id: return user raise ValueError('Unable to find the user.') diff --git a/tests/test_auth.py b/tests/test_auth.py index 3119c3d8d71..a53c5aaec99 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -94,6 +94,21 @@ async def test_login_as_existing_user(mock_hass): }]) ensure_auth_manager_loaded(manager) + # Add a fake user that we're not going to log in with + user = MockUser( + id='mock-user2', + is_owner=False, + is_active=False, + name='Not user', + ).add_to_auth_manager(manager) + user.credentials.append(auth.Credentials( + id='mock-id2', + auth_provider_type='insecure_example', + auth_provider_id=None, + data={'username': 'other-user'}, + is_new=False, + )) + # Add fake user with credentials for example auth provider. user = MockUser( id='mock-user',