mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 08:47:57 +00:00
Fix HTTP config serialization (#31319)
This commit is contained in:
parent
0a1e397119
commit
33361f8580
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user