From 033da9a94c300b432b88840c9102862f5df08a9c Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Thu, 11 Oct 2018 10:06:54 +0200 Subject: [PATCH 01/10] Update discovery.py --- homeassistant/components/hassio/discovery.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/hassio/discovery.py b/homeassistant/components/hassio/discovery.py index 3c5242607c165..4c7c5a6597f55 100644 --- a/homeassistant/components/hassio/discovery.py +++ b/homeassistant/components/hassio/discovery.py @@ -10,16 +10,12 @@ from homeassistant.components.http import HomeAssistantView from .handler import HassioAPIError +from .const import ( + ATTR_DISCOVERY, ATTR_ADDON, ATTR_NAME, ATTR_SERVICE, ATTR_CONFIG, + ATTR_UUID) _LOGGER = logging.getLogger(__name__) -ATTR_DISCOVERY = 'discovery' -ATTR_ADDON = 'addon' -ATTR_NAME = 'name' -ATTR_SERVICE = 'service' -ATTR_CONFIG = 'config' -ATTR_UUID = 'uuid' - @callback def async_setup_discovery(hass, hassio, config): From 47f235b130d4c525fc45da1c2616668c0c3c65b1 Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Thu, 11 Oct 2018 10:07:21 +0200 Subject: [PATCH 02/10] Create const.py --- homeassistant/components/hassio/const.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 homeassistant/components/hassio/const.py diff --git a/homeassistant/components/hassio/const.py b/homeassistant/components/hassio/const.py new file mode 100644 index 0000000000000..7ba7dc91102de --- /dev/null +++ b/homeassistant/components/hassio/const.py @@ -0,0 +1,8 @@ +"""Hass.io const variables.""" + +ATTR_DISCOVERY = 'discovery' +ATTR_ADDON = 'addon' +ATTR_NAME = 'name' +ATTR_SERVICE = 'service' +ATTR_CONFIG = 'config' +ATTR_UUID = 'uuid' From 8d13b576e7f2a959be39a3682ea165dbb04bb892 Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Thu, 11 Oct 2018 10:08:04 +0200 Subject: [PATCH 03/10] Update auth.py --- homeassistant/components/hassio/auth.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/hassio/auth.py b/homeassistant/components/hassio/auth.py index 951110271d48e..5e59cc29798b5 100644 --- a/homeassistant/components/hassio/auth.py +++ b/homeassistant/components/hassio/auth.py @@ -14,10 +14,9 @@ from homeassistant.components.http.const import KEY_REAL_IP from homeassistant.components.http.data_validator import RequestDataValidator -_LOGGER = logging.getLogger(__name__) +from .const import ATTR_USERNAME, ATTR_PASSWORD, ATTR_ADDON -ATTR_USERNAME = 'username' -ATTR_PASSWORD = 'password' +_LOGGER = logging.getLogger(__name__) SCHEMA_API_AUTH = vol.Schema({ From 720fc6191fcc71387447df84c5086a670c9b81c9 Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Thu, 11 Oct 2018 10:08:20 +0200 Subject: [PATCH 04/10] Update const.py --- homeassistant/components/hassio/const.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/homeassistant/components/hassio/const.py b/homeassistant/components/hassio/const.py index 7ba7dc91102de..0e6f9215f9682 100644 --- a/homeassistant/components/hassio/const.py +++ b/homeassistant/components/hassio/const.py @@ -6,3 +6,5 @@ ATTR_SERVICE = 'service' ATTR_CONFIG = 'config' ATTR_UUID = 'uuid' +ATTR_USERNAME = 'username' +ATTR_PASSWORD = 'password' From 2627641972f27b24b713e224311c59b826d5bd69 Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Thu, 11 Oct 2018 10:08:55 +0200 Subject: [PATCH 05/10] Update const.py --- homeassistant/components/hassio/const.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/homeassistant/components/hassio/const.py b/homeassistant/components/hassio/const.py index 0e6f9215f9682..c539169ebe345 100644 --- a/homeassistant/components/hassio/const.py +++ b/homeassistant/components/hassio/const.py @@ -8,3 +8,5 @@ ATTR_UUID = 'uuid' ATTR_USERNAME = 'username' ATTR_PASSWORD = 'password' + +X_HASSIO = 'X-HASSIO-KEY' From 3b2c28f85822245ec85d07299b8be8481deff6ec Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Thu, 11 Oct 2018 10:09:31 +0200 Subject: [PATCH 06/10] Update http.py --- homeassistant/components/hassio/http.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/hassio/http.py b/homeassistant/components/hassio/http.py index abd1c16ba8b3c..c3bd18fa9bbe8 100644 --- a/homeassistant/components/hassio/http.py +++ b/homeassistant/components/hassio/http.py @@ -18,9 +18,10 @@ from homeassistant.const import CONTENT_TYPE_TEXT_PLAIN from homeassistant.components.http import KEY_AUTHENTICATED, HomeAssistantView +from .const import X_HASSIO + _LOGGER = logging.getLogger(__name__) -X_HASSIO = 'X-HASSIO-KEY' NO_TIMEOUT = re.compile( r'^(?:' From 927e3ef0da73f1f65adef2c5be462a42ecc44a1b Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Thu, 11 Oct 2018 10:09:52 +0200 Subject: [PATCH 07/10] Update handler.py --- homeassistant/components/hassio/handler.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/hassio/handler.py b/homeassistant/components/hassio/handler.py index 7c450b49bcc43..91019776eeb80 100644 --- a/homeassistant/components/hassio/handler.py +++ b/homeassistant/components/hassio/handler.py @@ -16,9 +16,9 @@ CONF_SSL_CERTIFICATE) from homeassistant.const import CONF_TIME_ZONE, SERVER_PORT -_LOGGER = logging.getLogger(__name__) +from .const import X_HASSIO -X_HASSIO = 'X-HASSIO-KEY' +_LOGGER = logging.getLogger(__name__) class HassioAPIError(RuntimeError): From 412485cc6133d7c252c235de80a3d2b23bfeb46b Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Thu, 11 Oct 2018 10:11:13 +0200 Subject: [PATCH 08/10] Update auth.py --- homeassistant/components/hassio/auth.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/hassio/auth.py b/homeassistant/components/hassio/auth.py index 5e59cc29798b5..bc4dec72ab656 100644 --- a/homeassistant/components/hassio/auth.py +++ b/homeassistant/components/hassio/auth.py @@ -22,7 +22,8 @@ SCHEMA_API_AUTH = vol.Schema({ vol.Required(ATTR_USERNAME): cv.string, vol.Required(ATTR_PASSWORD): cv.string, -}) + vol.Required(ATTR_ADDON): cv.slug, +}, extra=vol.ALLOW_EXTRA) @callback From 10ebbbf16ec48657c7fac86405337117128c6c5e Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Thu, 11 Oct 2018 10:14:01 +0200 Subject: [PATCH 09/10] Update auth.py --- homeassistant/components/hassio/auth.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/hassio/auth.py b/homeassistant/components/hassio/auth.py index bc4dec72ab656..4be3ba9956ce1 100644 --- a/homeassistant/components/hassio/auth.py +++ b/homeassistant/components/hassio/auth.py @@ -22,7 +22,7 @@ SCHEMA_API_AUTH = vol.Schema({ vol.Required(ATTR_USERNAME): cv.string, vol.Required(ATTR_PASSWORD): cv.string, - vol.Required(ATTR_ADDON): cv.slug, + vol.Required(ATTR_ADDON): cv.string, }, extra=vol.ALLOW_EXTRA) From 16a6716770d68ebb7729377b36db1e0a8c46b22b Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Thu, 11 Oct 2018 10:16:10 +0200 Subject: [PATCH 10/10] Update test_auth.py --- tests/components/hassio/test_auth.py | 34 +++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/tests/components/hassio/test_auth.py b/tests/components/hassio/test_auth.py index b3a6ae223f996..fdf3230dedcd9 100644 --- a/tests/components/hassio/test_auth.py +++ b/tests/components/hassio/test_auth.py @@ -19,7 +19,8 @@ async def test_login_success(hass, hassio_client): '/api/hassio_auth', json={ "username": "test", - "password": "123456" + "password": "123456", + "addon": "samba", }, headers={ HTTP_HEADER_HA_AUTH: API_PASSWORD @@ -42,7 +43,8 @@ async def test_login_error(hass, hassio_client): '/api/hassio_auth', json={ "username": "test", - "password": "123456" + "password": "123456", + "addon": "samba", }, headers={ HTTP_HEADER_HA_AUTH: API_PASSWORD @@ -83,7 +85,8 @@ async def test_login_no_username(hass, hassio_client): resp = await hassio_client.post( '/api/hassio_auth', json={ - "password": "123456" + "password": "123456", + "addon": "samba", }, headers={ HTTP_HEADER_HA_AUTH: API_PASSWORD @@ -93,3 +96,28 @@ async def test_login_no_username(hass, hassio_client): # Check we got right response assert resp.status == 400 assert not mock_login.called + + +async def test_login_success_extra(hass, hassio_client): + """Test auth with extra data.""" + await register_auth_provider(hass, {'type': 'homeassistant'}) + + with patch('homeassistant.auth.providers.homeassistant.' + 'HassAuthProvider.async_validate_login', + Mock(return_value=mock_coro())) as mock_login: + resp = await hassio_client.post( + '/api/hassio_auth', + json={ + "username": "test", + "password": "123456", + "addon": "samba", + "path": "/share", + }, + headers={ + HTTP_HEADER_HA_AUTH: API_PASSWORD + } + ) + + # Check we got right response + assert resp.status == 200 + mock_login.assert_called_with("test", "123456")