test(unraid): complete contract coverage and retain WS samples
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import hmac
|
||||
import math
|
||||
import queue
|
||||
import threading
|
||||
@@ -10,6 +11,10 @@ from typing import Any
|
||||
import numpy as np
|
||||
|
||||
|
||||
def valid_bearer(header: str | None, token: str) -> bool:
|
||||
return bool(header and header.startswith("Bearer ") and hmac.compare_digest(header[7:], token))
|
||||
|
||||
|
||||
def finite01(value: float) -> float:
|
||||
value = float(value)
|
||||
return min(1.0, max(0.0, value)) if math.isfinite(value) else 0.0
|
||||
@@ -88,4 +93,3 @@ class Frame:
|
||||
pixels: np.ndarray
|
||||
received_ns: int
|
||||
decode_ms: float
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ from pynvml import (nvmlDeviceGetHandleByIndex, nvmlDeviceGetMemoryInfo,
|
||||
nvmlDeviceGetName, nvmlDeviceGetTemperature, nvmlInit,
|
||||
NVML_TEMPERATURE_GPU)
|
||||
|
||||
from .core import BroadcastHub, LatestQueue
|
||||
from .core import BroadcastHub, LatestQueue, valid_bearer
|
||||
from .models import Models
|
||||
from .ndi import NDIReceiver
|
||||
from .offline_benchmark import run_offline_benchmark
|
||||
@@ -65,7 +65,7 @@ app = FastAPI(docs_url=None, redoc_url=None, openapi_url=None)
|
||||
|
||||
|
||||
def authorized(authorization: str | None = Header(default=None)) -> None:
|
||||
if not authorization or not authorization.startswith("Bearer ") or not __import__("hmac").compare_digest(authorization[7:], token):
|
||||
if not valid_bearer(authorization, token):
|
||||
raise HTTPException(status_code=401, detail="unauthorized")
|
||||
|
||||
|
||||
@@ -135,7 +135,7 @@ def metrics():
|
||||
@app.websocket("/v1/poses")
|
||||
async def poses(ws: WebSocket):
|
||||
auth = ws.headers.get("authorization", "")
|
||||
if not auth.startswith("Bearer ") or not __import__("hmac").compare_digest(auth[7:], token):
|
||||
if not valid_bearer(auth, token):
|
||||
await ws.close(code=4401); return
|
||||
await ws.accept(); q = hub.add()
|
||||
try:
|
||||
|
||||
@@ -41,6 +41,7 @@ summary = {
|
||||
"coordinate_space_all": all(m["frame"]["coordinate_space"] == "ndi_buffer_unmodified" for m in messages),
|
||||
"horizontal_flip_all_false": all(not m["frame"]["horizontal_flip_applied"] for m in messages),
|
||||
"source_to_sent_ms": [round(m["timing"]["source_to_sent_ms"], 3) for m in messages],
|
||||
"sample_messages": messages[:2],
|
||||
},
|
||||
}
|
||||
print(json.dumps(summary, ensure_ascii=False, indent=2))
|
||||
|
||||
Reference in New Issue
Block a user