fix(server): reject inverted period_start/period_end in CameraRecord
A misbehaving or clock-broken device could submit period_end <= period_start, polluting the camera_records table with zero-length or inverted windows that corrupt downstream hourly analytics. Add a Pydantic model_validator so the request is rejected at the API boundary instead of silently persisting bad ranges. Found via adversarial review (run 2026-05-01-191359, both reviewers). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -98,3 +98,15 @@ def test_negative_counts_rejected():
|
||||
with pytest.raises(ValidationError):
|
||||
CameraRecord(period_start=1712000000, period_end=1712003600,
|
||||
entries=-1, exits=0)
|
||||
|
||||
|
||||
def test_inverted_period_rejected():
|
||||
"""Pydantic should reject period_end <= period_start."""
|
||||
from pydantic import ValidationError
|
||||
from server.camera_endpoint import CameraRecord
|
||||
with pytest.raises(ValidationError):
|
||||
CameraRecord(period_start=1712003600, period_end=1712003600,
|
||||
entries=0, exits=0)
|
||||
with pytest.raises(ValidationError):
|
||||
CameraRecord(period_start=1712003600, period_end=1712000000,
|
||||
entries=0, exits=0)
|
||||
|
||||
Reference in New Issue
Block a user