blitztext-app-linux/linux/tests/test_wakeword_security.py
google-labs-jules[bot] 7415a560dc 🛡️ Sentinel: Bound wyoming payload_length to prevent DoS
Co-authored-by: mARTin-B78 <91568406+mARTin-B78@users.noreply.github.com>
2026-06-08 19:34:25 +00:00

24 lines
875 B
Python

import json
import pytest
from blitztext.wakeword_bench import _drain_detections
def test_drain_detections_payload_length_validation():
# Test massive payload length
msg = {"type": "info", "payload_length": 1048577}
buf = json.dumps(msg).encode("utf-8") + b"\n"
with pytest.raises(ValueError, match="Unreasonably large payload_length"):
_drain_detections(buf)
# Test negative payload length
msg = {"type": "info", "payload_length": -1}
buf = json.dumps(msg).encode("utf-8") + b"\n"
with pytest.raises(ValueError, match="Negative payload_length"):
_drain_detections(buf)
# Test invalid type for payload length
msg = {"type": "info", "payload_length": "invalid"}
buf = json.dumps(msg).encode("utf-8") + b"\n"
with pytest.raises(ValueError, match="Invalid payload_length type"):
_drain_detections(buf)