Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update name legacy api password #16455

Merged
merged 1 commit into from
Sep 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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