This commit is contained in:
J. Nick Koston
2024-04-14 22:24:29 -05:00
parent 9511f98dc9
commit 550637a125
2 changed files with 23 additions and 1 deletions

View File

@@ -221,7 +221,12 @@ class ActiveConnection:
handler, schema = handler_schema handler, schema = handler_schema
try: try:
handler(self.hass, self, msg if schema is False else schema(msg)) if schema is False:
if len(msg) > 2:
raise vol.Invalid("Message has unexpected keys")
handler(self.hass, self, msg)
else:
handler(self.hass, self, schema(msg))
except Exception as err: # pylint: disable=broad-except except Exception as err: # pylint: disable=broad-except
self.async_handle_exception(msg, err) self.async_handle_exception(msg, err)

View File

@@ -122,6 +122,23 @@ async def test_async_response_request_context(
assert msg["error"]["code"] == "invalid_format" assert msg["error"]["code"] == "invalid_format"
assert msg["error"]["message"] == "Message incorrectly formatted." assert msg["error"]["message"] == "Message incorrectly formatted."
await websocket_client.send_json(
{
"id": 10,
"type": "test-get-request",
"not_valid": "dog",
}
)
msg = await websocket_client.receive_json()
assert msg["id"] == 10
assert not msg["success"]
assert msg["error"]["code"] == "invalid_format"
assert msg["error"]["message"] == (
"Message has unexpected keys. "
"Got {'id': 10, 'type': 'test-get-request', 'not_valid': 'dog'}"
)
async def test_supervisor_only(hass: HomeAssistant, websocket_client) -> None: async def test_supervisor_only(hass: HomeAssistant, websocket_client) -> None:
"""Test that only the Supervisor can make requests.""" """Test that only the Supervisor can make requests."""