Fix HTTP config serialization (#31319)

This commit is contained in:
Paulus Schoutsen 2020-01-30 09:47:16 -08:00 committed by GitHub
parent 0a1e397119
commit 33361f8580
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 6 deletions

View File

@ -166,7 +166,16 @@ async def async_setup(hass, config):
# If we are set up successful, we store the HTTP settings for safe mode.
store = storage.Store(hass, STORAGE_VERSION, STORAGE_KEY)
await store.async_save(conf)
if CONF_TRUSTED_PROXIES in conf:
conf_to_save = dict(conf)
conf_to_save[CONF_TRUSTED_PROXIES] = [
str(ip.network_address) for ip in conf_to_save[CONF_TRUSTED_PROXIES]
]
else:
conf_to_save = conf
await store.async_save(conf_to_save)
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_START, start_server)

View File

@ -1,4 +1,5 @@
"""The tests for the Home Assistant HTTP component."""
from ipaddress import ip_network
import logging
import unittest
from unittest.mock import patch
@ -244,12 +245,16 @@ async def test_cors_defaults(hass):
async def test_storing_config(hass, aiohttp_client, aiohttp_unused_port):
"""Test that we store last working config."""
config = {http.CONF_SERVER_PORT: aiohttp_unused_port()}
config = {
http.CONF_SERVER_PORT: aiohttp_unused_port(),
"use_x_forwarded_for": True,
"trusted_proxies": ["192.168.1.100"],
}
await async_setup_component(hass, http.DOMAIN, {http.DOMAIN: config})
assert await async_setup_component(hass, http.DOMAIN, {http.DOMAIN: config})
await hass.async_start()
restored = await hass.components.http.async_get_last_config()
restored["trusted_proxies"][0] = ip_network(restored["trusted_proxies"][0])
assert await hass.components.http.async_get_last_config() == http.HTTP_SCHEMA(
config
)
assert restored == http.HTTP_SCHEMA(config)