mirror of
https://github.com/home-assistant/core.git
synced 2026-09-26 17:31:15 -04:00
Do not log the Start.ca API key (#182279)
This commit is contained in:
@@ -152,7 +152,7 @@ async def async_setup_platform(
|
||||
ts_data = StartcaData(websession, apikey, bandwidthcap)
|
||||
ret = await ts_data.async_update()
|
||||
if ret is False:
|
||||
_LOGGER.error("Invalid Start.ca API key: %s", apikey)
|
||||
_LOGGER.error("Invalid Start.ca API key")
|
||||
return
|
||||
|
||||
name = config[CONF_NAME]
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
from http import HTTPStatus
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.startca.sensor import StartcaData
|
||||
from homeassistant.const import ATTR_UNIT_OF_MEASUREMENT, PERCENTAGE, UnitOfInformation
|
||||
from homeassistant.core import HomeAssistant
|
||||
@@ -227,3 +229,27 @@ async def test_bad_json_decode(
|
||||
|
||||
result = await scd.async_update()
|
||||
assert result is False
|
||||
|
||||
|
||||
async def test_invalid_api_key(
|
||||
hass: HomeAssistant,
|
||||
aioclient_mock: AiohttpClientMocker,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test that setup stops when Start.ca rejects the key."""
|
||||
config = {
|
||||
"platform": "startca",
|
||||
"api_key": "NOTAKEY",
|
||||
"total_bandwidth": 400,
|
||||
"monitored_variables": ["usage"],
|
||||
}
|
||||
aioclient_mock.get(
|
||||
"https://www.start.ca/support/usage/api?key=NOTAKEY",
|
||||
status=HTTPStatus.NOT_FOUND,
|
||||
)
|
||||
|
||||
await async_setup_component(hass, "sensor", {"sensor": config})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.states.get("sensor.start_ca_usage") is None
|
||||
assert "Invalid Start.ca API key" in caplog.text
|
||||
|
||||
Reference in New Issue
Block a user