Skip to content

Commit

Permalink
Update name legacy api password (#16455)
Browse files Browse the repository at this point in the history
  • Loading branch information
balloob committed Sep 8, 2018
1 parent 9944c60 commit e7b8d2e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
18 changes: 8 additions & 10 deletions homeassistant/auth/providers/legacy_api_password.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
CONFIG_SCHEMA = AUTH_PROVIDER_SCHEMA.extend({
}, extra=vol.PREVENT_EXTRA)

LEGACY_USER = 'homeassistant'
LEGACY_USER_NAME = 'Legacy API password user'


class InvalidAuthError(HomeAssistantError):
Expand Down Expand Up @@ -52,23 +52,21 @@ def async_validate_login(self, password: str) -> None:

async def async_get_or_create_credentials(
self, flow_result: Dict[str, str]) -> Credentials:
"""Return LEGACY_USER always."""
for credential in await self.async_credentials():
if credential.data['username'] == LEGACY_USER:
return credential
"""Return credentials for this login."""
credentials = await self.async_credentials()
if credentials:
return credentials[0]

return self.async_create_credentials({
'username': LEGACY_USER
})
return self.async_create_credentials({})

async def async_user_meta_for_credentials(
self, credentials: Credentials) -> UserMeta:
"""
Set name as LEGACY_USER always.
Return info for the user.
Will be used to populate info when creating a new user.
"""
return UserMeta(name=LEGACY_USER, is_active=True)
return UserMeta(name=LEGACY_USER_NAME, is_active=True)


class LegacyLoginFlow(LoginFlow):
Expand Down
4 changes: 1 addition & 3 deletions tests/auth/providers/test_legacy_api_password.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@ def manager(hass, store, provider):
async def test_create_new_credential(manager, provider):
"""Test that we create a new credential."""
credentials = await provider.async_get_or_create_credentials({})
assert credentials.data["username"] is legacy_api_password.LEGACY_USER
assert credentials.is_new is True

user = await manager.async_get_or_create_user(credentials)
assert user.name == legacy_api_password.LEGACY_USER
assert user.name == legacy_api_password.LEGACY_USER_NAME
assert user.is_active


Expand All @@ -46,7 +45,6 @@ async def test_only_one_credentials(manager, provider):
credentials = await provider.async_get_or_create_credentials({})
await manager.async_get_or_create_user(credentials)
credentials2 = await provider.async_get_or_create_credentials({})
assert credentials2.data["username"] == legacy_api_password.LEGACY_USER
assert credentials2.id == credentials.id
assert credentials2.is_new is False

Expand Down

0 comments on commit e7b8d2e

Please sign in to comment.