feat(v1): add secure configuration baseline
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
import json
|
||||
|
||||
import pytest
|
||||
|
||||
from v1.config import ConfigError, load_config
|
||||
|
||||
|
||||
def _write_config(path, source):
|
||||
path.write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"source": source,
|
||||
"model": {
|
||||
"path": "models/best.pt",
|
||||
"sha256": "a" * 64,
|
||||
"confidence_threshold": 0.25,
|
||||
},
|
||||
"event": {
|
||||
"keypoint_confidence_threshold": 0.4,
|
||||
"suspect_window_seconds": 0.5,
|
||||
"confirm_window_seconds": 1.8,
|
||||
"recovery_window_seconds": 2.0,
|
||||
"cooldown_seconds": 10.0,
|
||||
},
|
||||
"artifacts": {"event_dir": "artifacts/events"},
|
||||
},
|
||||
ensure_ascii=False,
|
||||
),
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
|
||||
def test_load_config_resolves_source_from_environment_variable(tmp_path, monkeypatch):
|
||||
config_file = tmp_path / "config.json"
|
||||
_write_config(
|
||||
config_file,
|
||||
{"id": "lobby-camera-01", "rtsp_url_env": "SILVER_POSE_RTSP_URL"},
|
||||
)
|
||||
monkeypatch.setenv("SILVER_POSE_RTSP_URL", "rtsp://demo.invalid/live")
|
||||
|
||||
config = load_config(config_file)
|
||||
|
||||
assert config.source_id == "lobby-camera-01"
|
||||
assert config.source_url == "rtsp://demo.invalid/live"
|
||||
assert config.event.confirm_window_seconds == 1.8
|
||||
|
||||
|
||||
def test_load_config_rejects_embedded_source_address(tmp_path):
|
||||
config_file = tmp_path / "config.json"
|
||||
_write_config(
|
||||
config_file,
|
||||
{"id": "lobby-camera-01", "url": "rtsp://demo.invalid/live"},
|
||||
)
|
||||
|
||||
with pytest.raises(ConfigError, match="rtsp_url_env"):
|
||||
load_config(config_file)
|
||||
Reference in New Issue
Block a user