mirror of
https://github.com/home-assistant/supervisor.git
synced 2026-02-15 07:27:13 +00:00
Validate device option type before path conversion in addon options (#6542)
Add a type check for device options in AddonOptions._single_validate to ensure the value is a string before passing it to Path(). When a non-string value (e.g. a dict) is provided for a device option, this now raises a proper vol.Invalid error instead of an unhandled TypeError. Fixes SUPERVISOR-175H Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -169,6 +169,10 @@ class AddonOptions(CoreSysAttributes):
|
||||
elif typ.startswith(_LIST):
|
||||
return vol.In(match.group("list").split("|"))(str(value))
|
||||
elif typ.startswith(_DEVICE):
|
||||
if not isinstance(value, str):
|
||||
raise vol.Invalid(
|
||||
f"Expected a string for option '{key}' in {self._name} ({self._slug})"
|
||||
)
|
||||
try:
|
||||
device = self.sys_hardware.get_by_path(Path(value))
|
||||
except HardwareNotFound:
|
||||
|
||||
@@ -273,6 +273,25 @@ def test_simple_device_schema(coresys):
|
||||
)({"name": "Pascal", "password": "1234", "input": "/dev/video1"})
|
||||
|
||||
|
||||
def test_device_schema_wrong_type(coresys):
|
||||
"""Test device option rejects non-string values."""
|
||||
with pytest.raises(vol.error.Invalid):
|
||||
AddonOptions(
|
||||
coresys,
|
||||
{"name": "str", "input": "device(subsystem=tty)"},
|
||||
MOCK_ADDON_NAME,
|
||||
MOCK_ADDON_SLUG,
|
||||
)({"name": "Pascal", "input": {"baudrate": 115200, "flow_control": True}})
|
||||
|
||||
with pytest.raises(vol.error.Invalid):
|
||||
AddonOptions(
|
||||
coresys,
|
||||
{"name": "str", "input": "device"},
|
||||
MOCK_ADDON_NAME,
|
||||
MOCK_ADDON_SLUG,
|
||||
)({"name": "Pascal", "input": 12345})
|
||||
|
||||
|
||||
def test_simple_schema_password(coresys):
|
||||
"""Test with simple schema password pwned."""
|
||||
validate = AddonOptions(
|
||||
|
||||
Reference in New Issue
Block a user