Update HTTP defaults (#25702)

* Update HTTP defaults

* Fix tests
This commit is contained in:
Paulus Schoutsen 2019-08-04 23:24:54 -07:00
parent eceef82ffa
commit fee1568a85
4 changed files with 16 additions and 2 deletions

View file

@ -51,6 +51,8 @@ _LOGGER = logging.getLogger(__name__)
DEFAULT_SERVER_HOST = "0.0.0.0"
DEFAULT_DEVELOPMENT = "0"
# To be able to load custom cards.
DEFAULT_CORS = "https://cast.home-assistant.io"
NO_LOGIN_ATTEMPT_THRESHOLD = -1
@ -91,7 +93,7 @@ HTTP_SCHEMA = vol.Schema(
vol.Optional(CONF_SSL_CERTIFICATE): cv.isfile,
vol.Optional(CONF_SSL_PEER_CERTIFICATE): cv.isfile,
vol.Optional(CONF_SSL_KEY): cv.isfile,
vol.Optional(CONF_CORS_ORIGINS, default=[]): vol.All(
vol.Optional(CONF_CORS_ORIGINS, default=[DEFAULT_CORS]): vol.All(
cv.ensure_list, [cv.string]
),
vol.Inclusive(CONF_USE_X_FORWARDED_FOR, "proxy"): cv.boolean,

View file

@ -45,6 +45,9 @@ def setup_cors(app, origins):
path = path.canonical
if path.startswith("/api/hassio_ingress/"):
return
if path in cors_added:
return

View file

@ -232,3 +232,12 @@ async def test_ssl_profile_change_modern(hass):
await hass.async_block_till_done()
assert len(mock_context.mock_calls) == 1
async def test_cors_defaults(hass):
"""Test the CORS default settings."""
with patch("homeassistant.components.http.setup_cors") as mock_setup:
assert await async_setup_component(hass, "http", {})
assert len(mock_setup.mock_calls) == 1
assert mock_setup.mock_calls[0][1][1] == ["https://cast.home-assistant.io"]

View file

@ -103,7 +103,7 @@ def test_secrets(isfile_patch, loop):
assert res["components"].keys() == {"homeassistant", "http"}
assert res["components"]["http"] == {
"api_password": "abc123",
"cors_allowed_origins": [],
"cors_allowed_origins": ["https://cast.home-assistant.io"],
"ip_ban_enabled": True,
"login_attempts_threshold": -1,
"server_host": "0.0.0.0",