Skip to content
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
4 changes: 3 additions & 1 deletion homeassistant/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,12 @@ async def async_from_config_dict(config: Dict[str, Any],

core_config = config.get(core.DOMAIN, {})
has_api_password = bool((config.get('http') or {}).get('api_password'))
has_trusted_networks = bool((config.get('http') or {})
.get('trusted_networks'))

try:
await conf_util.async_process_ha_core_config(
hass, core_config, has_api_password)
hass, core_config, has_api_password, has_trusted_networks)
except vol.Invalid as ex:
conf_util.async_log_exception(ex, 'homeassistant', core_config, hass)
return None
Expand Down
5 changes: 4 additions & 1 deletion homeassistant/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,8 @@ def _format_config_error(ex: vol.Invalid, domain: str, config: Dict) -> str:

async def async_process_ha_core_config(
hass: HomeAssistant, config: Dict,
has_api_password: bool = False) -> None:
has_api_password: bool = False,
has_trusted_networks: bool = False) -> None:
"""Process the [homeassistant] section from the configuration.

This method is a coroutine.
Expand All @@ -423,6 +424,8 @@ async def async_process_ha_core_config(
]
if has_api_password:
auth_conf.append({'type': 'legacy_api_password'})
if has_trusted_networks:
auth_conf.append({'type': 'trusted_networks'})

setattr(hass, 'auth', await auth.auth_manager_from_config(
hass,
Expand Down
21 changes: 21 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,27 @@ async def test_auth_provider_config_default_api_password(hass):
assert hass.auth.active is True


async def test_auth_provider_config_default_trusted_networks(hass):
"""Test loading default auth provider config with trusted networks."""
core_config = {
'latitude': 60,
'longitude': 50,
'elevation': 25,
'name': 'Huis',
CONF_UNIT_SYSTEM: CONF_UNIT_SYSTEM_IMPERIAL,
'time_zone': 'GMT',
}
if hasattr(hass, 'auth'):
del hass.auth
await config_util.async_process_ha_core_config(hass, core_config,
has_trusted_networks=True)

assert len(hass.auth.auth_providers) == 2
assert hass.auth.auth_providers[0].type == 'homeassistant'
assert hass.auth.auth_providers[1].type == 'trusted_networks'
assert hass.auth.active is True


async def test_disallowed_auth_provider_config(hass):
"""Test loading insecure example auth provider is disallowed."""
core_config = {
Expand Down