Files
detections/e2e/tests/test_tiling.py
T
Oleksandr Bezdieniezhnykh 097811a67b [AZ-178] Fix Critical/High security findings: auth, CVEs, non-root containers, per-job SSE
- Pin all deps; h11==0.16.0 (CVE-2025-43859), python-multipart>=1.3.1 (CVE-2026-28356), PyJWT==2.12.1
- Add HMAC JWT verification (require_auth FastAPI dependency, JWT_SECRET-gated)
- Fix TokenManager._refresh() to use ADMIN_API_URL instead of ANNOTATIONS_URL
- Rename POST /detect → POST /detect/image (image-only, rejects video files)
- Replace global SSE stream with per-job SSE: GET /detect/{media_id} with event replay buffer
- Apply require_auth to all 4 protected endpoints
- Fix on_annotation/on_status closure to use mutable current_id for correct post-upload event routing
- Add non-root appuser to Dockerfile and Dockerfile.gpu
- Add JWT_SECRET to e2e/docker-compose.test.yml and run-tests.sh
- Update all e2e tests and unit tests for new endpoints and HMAC token signing
- 64/64 tests pass

Made-with: Cursor
2026-04-02 06:32:12 +03:00

60 lines
1.8 KiB
Python

import json
import pytest
_TILING_TIMEOUT = 120
_GSD = {"altitude": 400, "focal_length": 24, "sensor_width": 23.5}
_DUP_THRESHOLD = 0.01
def _assert_coords_normalized(detections):
for d in detections:
for k in ("centerX", "centerY", "width", "height"):
v = d[k]
assert 0.0 <= v <= 1.0
def _assert_no_same_label_near_duplicate_centers(detections):
by_label = {}
for d in detections:
label = d["label"]
cx, cy = d["centerX"], d["centerY"]
prev = by_label.setdefault(label, [])
for pcx, pcy in prev:
assert not (
abs(cx - pcx) < _DUP_THRESHOLD and abs(cy - pcy) < _DUP_THRESHOLD
), f"near-duplicate centers for label {label!r}: ({pcx},{pcy}) vs ({cx},{cy})"
prev.append((cx, cy))
@pytest.mark.slow
def test_ft_p_04_gsd_based_tiling_ac1(http_client, image_large, warm_engine, auth_headers):
config = json.dumps(_GSD)
r = http_client.post(
"/detect/image",
files={"file": ("img.jpg", image_large, "image/jpeg")},
data={"config": config},
headers=auth_headers,
timeout=_TILING_TIMEOUT,
)
assert r.status_code == 200
body = r.json()
assert isinstance(body, list)
_assert_coords_normalized(body)
@pytest.mark.slow
def test_ft_p_16_tile_boundary_deduplication_ac2(http_client, image_large, warm_engine, auth_headers):
config = json.dumps({**_GSD, "big_image_tile_overlap_percent": 20})
r = http_client.post(
"/detect/image",
files={"file": ("img.jpg", image_large, "image/jpeg")},
data={"config": config},
headers=auth_headers,
timeout=_TILING_TIMEOUT,
)
assert r.status_code == 200
body = r.json()
assert isinstance(body, list)
_assert_no_same_label_near_duplicate_centers(body)