Skip to content

Commit

Permalink
Load totp auth module by default
Browse files Browse the repository at this point in the history
  • Loading branch information
awarecan committed Aug 25, 2018
1 parent 06e015f commit b98f65d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 5 additions & 1 deletion homeassistant/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,10 +424,14 @@ async def async_process_ha_core_config(
if has_api_password:
auth_conf.append({'type': 'legacy_api_password'})

mfa_conf = config.get(CONF_AUTH_MFA_MODULES, [
{'type': 'totp', 'id': 'totp', 'name': 'Authenticator app'}
])

setattr(hass, 'auth', await auth.auth_manager_from_config(
hass,
auth_conf,
config.get(CONF_AUTH_MFA_MODULES, [])))
mfa_conf))

hac = hass.config

Expand Down
11 changes: 10 additions & 1 deletion tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
CONF_LATITUDE, CONF_LONGITUDE, CONF_UNIT_SYSTEM, CONF_NAME,
CONF_TIME_ZONE, CONF_ELEVATION, CONF_CUSTOMIZE, __version__,
CONF_UNIT_SYSTEM_METRIC, CONF_UNIT_SYSTEM_IMPERIAL, CONF_TEMPERATURE_UNIT,
CONF_AUTH_PROVIDERS)
CONF_AUTH_PROVIDERS, CONF_AUTH_MFA_MODULES)
from homeassistant.util import location as location_util, dt as dt_util
from homeassistant.util.yaml import SECRET_YAML
from homeassistant.util.async_ import run_coroutine_threadsafe
Expand Down Expand Up @@ -805,6 +805,10 @@ async def test_auth_provider_config(hass):
CONF_AUTH_PROVIDERS: [
{'type': 'homeassistant'},
{'type': 'legacy_api_password'},
],
CONF_AUTH_MFA_MODULES: [
{'type': 'totp'},
{'type': 'totp', 'id': 'second'},
]
}
if hasattr(hass, 'auth'):
Expand All @@ -815,6 +819,9 @@ async def test_auth_provider_config(hass):
assert hass.auth.auth_providers[0].type == 'homeassistant'
assert hass.auth.auth_providers[1].type == 'legacy_api_password'
assert hass.auth.active is True
assert len(hass.auth.auth_mfa_modules) == 2
assert hass.auth.auth_mfa_modules[0].id == 'totp'
assert hass.auth.auth_mfa_modules[1].id == 'second'


async def test_auth_provider_config_default(hass):
Expand All @@ -834,6 +841,8 @@ async def test_auth_provider_config_default(hass):
assert len(hass.auth.auth_providers) == 1
assert hass.auth.auth_providers[0].type == 'homeassistant'
assert hass.auth.active is True
assert len(hass.auth.auth_mfa_modules) == 1
assert hass.auth.auth_mfa_modules[0].id == 'totp'


async def test_auth_provider_config_default_api_password(hass):
Expand Down

0 comments on commit b98f65d

Please sign in to comment.