Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions homeassistant/components/hassio/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
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({
vol.Required(ATTR_USERNAME): cv.string,
vol.Required(ATTR_PASSWORD): cv.string,
})
vol.Required(ATTR_ADDON): cv.string,
}, extra=vol.ALLOW_EXTRA)


@callback
Expand Down
12 changes: 12 additions & 0 deletions homeassistant/components/hassio/const.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""Hass.io const variables."""

ATTR_DISCOVERY = 'discovery'
ATTR_ADDON = 'addon'
ATTR_NAME = 'name'
ATTR_SERVICE = 'service'
ATTR_CONFIG = 'config'
ATTR_UUID = 'uuid'
ATTR_USERNAME = 'username'
ATTR_PASSWORD = 'password'

X_HASSIO = 'X-HASSIO-KEY'
10 changes: 3 additions & 7 deletions homeassistant/components/hassio/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/hassio/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/hassio/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'^(?:'
Expand Down
34 changes: 31 additions & 3 deletions tests/components/hassio/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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")