Skip to content

Commit

Permalink
Update HTTP defaults (#25702)
Browse files Browse the repository at this point in the history
* Update HTTP defaults

* Fix tests
  • Loading branch information
balloob authored and pvizeli committed Aug 5, 2019
1 parent 6b51178 commit 57f84cb
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
4 changes: 3 additions & 1 deletion homeassistant/components/http/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@

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


Expand Down Expand Up @@ -91,7 +93,7 @@ def api_password_deprecated(value):
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,
Expand Down
3 changes: 3 additions & 0 deletions homeassistant/components/http/cors.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ def _allow_cors(route, config=None):

path = path.canonical

if path.startswith("/api/hassio_ingress/"):
return

if path in cors_added:
return

Expand Down
9 changes: 9 additions & 0 deletions tests/components/http/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
2 changes: 1 addition & 1 deletion tests/scripts/test_check_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 57f84cb

Please sign in to comment.