fix(sfm): one guard in front of every /device route -- UM serials 501 off the serial-aware routes, held lines 409 serial-less requests
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
This commit is contained in:
1 parent
6dd34f8fd7
commit
82b91835fb
4 files changed
+109
-1
No files matched your search
@@ -90,3 +90,48 @@ def test_without_a_serial_the_legacy_path_runs_unchanged(monkeypatch):
|
||||
monkeypatch.setattr(srv, "get_cache", lambda: Cache())
|
||||
out = srv.device_info(force=False, serial=None, **TCP)
|
||||
assert out == {"serial": "BE18193", "firmware_version": "S338.17", "_cached": True}
|
||||
|
||||
|
||||
# ── the /device/* guard ───────────────────────────────────────────────────────
|
||||
|
||||
from sfm.device_access.models import UnitAddress # noqa: E402
|
||||
|
||||
ADDR = UnitAddress(host="10.0.0.5", tcp_port=9034, port=None, baud=None)
|
||||
Q_TCP = {"host": "10.0.0.5", "tcp_port": "9034"}
|
||||
|
||||
|
||||
@pytest.mark.parametrize("path", ["/device/events/erase", "/device/monitor/stop", "/device/config"])
|
||||
def test_guard_refuses_a_um_serial_on_unsupported_routes_with_501(path):
|
||||
out = srv._device_guard(path, {"serial": "um20147", **Q_TCP})
|
||||
assert out is not None and out[0] == 501 and path in out[1]
|
||||
|
||||
|
||||
def test_guard_lets_a_series3_serial_through_on_legacy_routes():
|
||||
assert srv._device_guard("/device/events/erase", {"serial": "BE18193", **Q_TCP}) is None
|
||||
|
||||
|
||||
@pytest.mark.parametrize("path", ["/device/info", "/device/connect",
|
||||
"/device/monitor/status", "/device/settings",
|
||||
"/device/hangup"])
|
||||
def test_guard_allows_um_serial_on_serial_aware_routes_and_hangup(path):
|
||||
assert srv._device_guard(path, {"serial": "UM20147", **Q_TCP}) is None
|
||||
|
||||
|
||||
def test_guard_refuses_serialless_requests_at_a_held_address_with_409(da):
|
||||
da.status(ADDR, "UM20147")
|
||||
out = srv._device_guard("/device/monitor/stop", dict(Q_TCP))
|
||||
assert out is not None and out[0] == 409
|
||||
assert "UM20147" in out[1] and "tcp:10.0.0.5:9034" in out[1] and "hangup" in out[1]
|
||||
|
||||
|
||||
def test_guard_allows_serialless_requests_at_an_unheld_address(da):
|
||||
assert srv._device_guard("/device/monitor/stop", dict(Q_TCP)) is None
|
||||
assert srv._device_guard("/device/monitor/stop", {"host": "10.9.9.9"}) is None
|
||||
|
||||
|
||||
def test_guard_ignores_non_device_paths(da):
|
||||
assert srv._device_guard("/db/events", {"serial": "UM20147", **Q_TCP}) is None
|
||||
|
||||
|
||||
def test_guard_allows_an_unbuildable_address_through(da):
|
||||
assert srv._device_guard("/device/monitor/stop", {}) is None
|
||||
Reference in new issue
Block a user