Replace api_password in Camera.Push (#16339)

* Use access_token and user provided token instead of api_password

* address comments by @awarecan

* new tests

* add extra checks and test

* lint

* add comment
This commit is contained in:
Diogo Gomes authored and Paulus Schoutsen committed 2018-09-11 11:30:20 +02:00
1 parent 6b08e6e769
commit 20f6cb7cc7
2 files changed
+87 -12

No files matched your search

+60 -7
View File
@@ -6,7 +6,7 @@ from datetime import timedelta
from homeassistant import core as ha
from homeassistant.setup import async_setup_component
from homeassistant.util import dt as dt_util
from tests.components.auth import async_setup_auth
from homeassistant.components.http.auth import setup_auth
async def test_bad_posting(aioclient_mock, hass, aiohttp_client):
@@ -15,19 +15,69 @@ async def test_bad_posting(aioclient_mock, hass, aiohttp_client):
'camera': {
'platform': 'push',
'name': 'config_test',
'token': '12345678'
}})
client = await async_setup_auth(hass, aiohttp_client)
client = await aiohttp_client(hass.http.app)
# missing file
resp = await client.post('/api/camera_push/camera.config_test')
assert resp.status == 400
files = {'image': io.BytesIO(b'fake')}
# wrong entity
files = {'image': io.BytesIO(b'fake')}
resp = await client.post('/api/camera_push/camera.wrong', data=files)
assert resp.status == 400
assert resp.status == 404
async def test_cases_with_no_auth(aioclient_mock, hass, aiohttp_client):
"""Test cases where aiohttp_client is not auth."""
await async_setup_component(hass, 'camera', {
'camera': {
'platform': 'push',
'name': 'config_test',
'token': '12345678'
}})
setup_auth(hass.http.app, [], True, api_password=None)
client = await aiohttp_client(hass.http.app)
# wrong token
files = {'image': io.BytesIO(b'fake')}
resp = await client.post('/api/camera_push/camera.config_test?token=1234',
data=files)
assert resp.status == 401
# right token
files = {'image': io.BytesIO(b'fake')}
resp = await client.post(
'/api/camera_push/camera.config_test?token=12345678',
data=files)
assert resp.status == 200
async def test_no_auth_no_token(aioclient_mock, hass, aiohttp_client):
"""Test cases where aiohttp_client is not auth."""
await async_setup_component(hass, 'camera', {
'camera': {
'platform': 'push',
'name': 'config_test',
}})
setup_auth(hass.http.app, [], True, api_password=None)
client = await aiohttp_client(hass.http.app)
# no token
files = {'image': io.BytesIO(b'fake')}
resp = await client.post('/api/camera_push/camera.config_test',
data=files)
assert resp.status == 401
# fake token
files = {'image': io.BytesIO(b'fake')}
resp = await client.post(
'/api/camera_push/camera.config_test?token=12345678',
data=files)
assert resp.status == 401
async def test_posting_url(hass, aiohttp_client):
@@ -36,6 +86,7 @@ async def test_posting_url(hass, aiohttp_client):
'camera': {
'platform': 'push',
'name': 'config_test',
'token': '12345678'
}})
client = await aiohttp_client(hass.http.app)
@@ -46,7 +97,9 @@ async def test_posting_url(hass, aiohttp_client):
assert camera_state.state == 'idle'
# post image
resp = await client.post('/api/camera_push/camera.config_test', data=files)
resp = await client.post(
'/api/camera_push/camera.config_test?token=12345678',
data=files)
assert resp.status == 200
# state recording