mirror of
https://github.com/ruvnet/RuView
synced 2026-06-29 13:33:19 +00:00
81cc241b9e
The Rust port at v2/ has been the primary codebase since the rename in #427. The Python implementation at v1/ is no longer the active target; the only load-bearing path is the deterministic proof bundle at v1/data/proof/ (per ADR-011 / ADR-028 witness verification). Move the whole Python tree into archive/v1/ and document the policy in archive/README.md: no new features, bug fixes only when they affect a still-load-bearing path (currently just the proof), CI continues to verify the proof on every push and PR. Path references updated in 26 files via path-pattern sed (only matches v1/<known-child> patterns, never bare v1 or API URLs like /api/v1/). Two double-prefix typos (archive/archive/v1/) caught and hand-fixed in verify-pipeline.yml and ADR-011. Validated: - Python proof verify.py imports cleanly at archive/v1/data/proof/ (numpy/scipy still required; CI installs requirements-lock.txt from archive/v1/ now) - cargo test --workspace --no-default-features → 1,539 passed, 0 failed, 8 ignored (unaffected by Python tree relocation) - ESP32-S3 on COM7 untouched (no firmware paths changed) After-merge: contributors should re-run any local `python v1/...` commands as `python archive/v1/...` (CLAUDE.md and CHANGELOG already updated).
63 lines
2.8 KiB
Python
63 lines
2.8 KiB
Python
"""Tests for rate limiting middleware."""
|
|
|
|
import pytest
|
|
from unittest.mock import MagicMock, AsyncMock, patch
|
|
|
|
|
|
class TestRateLimitMiddleware:
|
|
def test_init(self, mock_settings):
|
|
with patch("src.api.middleware.rate_limit.get_settings", return_value=mock_settings):
|
|
from src.api.middleware.rate_limit import RateLimitMiddleware
|
|
app = MagicMock()
|
|
mw = RateLimitMiddleware(app)
|
|
assert "anonymous" in mw.rate_limits
|
|
assert "authenticated" in mw.rate_limits
|
|
assert "admin" in mw.rate_limits
|
|
|
|
def test_exempt_paths(self, mock_settings):
|
|
with patch("src.api.middleware.rate_limit.get_settings", return_value=mock_settings):
|
|
from src.api.middleware.rate_limit import RateLimitMiddleware
|
|
app = MagicMock()
|
|
mw = RateLimitMiddleware(app)
|
|
assert "/health" in mw.exempt_paths
|
|
assert "/metrics" in mw.exempt_paths
|
|
|
|
def test_is_exempt(self, mock_settings):
|
|
with patch("src.api.middleware.rate_limit.get_settings", return_value=mock_settings):
|
|
from src.api.middleware.rate_limit import RateLimitMiddleware
|
|
app = MagicMock()
|
|
mw = RateLimitMiddleware(app)
|
|
assert mw._is_exempt_path("/health") is True
|
|
assert mw._is_exempt_path("/api/v1/pose/current") is False
|
|
|
|
def test_path_specific_limits(self, mock_settings):
|
|
with patch("src.api.middleware.rate_limit.get_settings", return_value=mock_settings):
|
|
from src.api.middleware.rate_limit import RateLimitMiddleware
|
|
app = MagicMock()
|
|
mw = RateLimitMiddleware(app)
|
|
assert "/api/v1/pose/current" in mw.path_limits
|
|
assert mw.path_limits["/api/v1/pose/current"]["requests"] == 60
|
|
|
|
def test_trusted_proxies_not_blocked(self, mock_settings):
|
|
with patch("src.api.middleware.rate_limit.get_settings", return_value=mock_settings):
|
|
from src.api.middleware.rate_limit import RateLimitMiddleware
|
|
app = MagicMock()
|
|
mw = RateLimitMiddleware(app)
|
|
assert not mw._is_client_blocked("new-client-id")
|
|
|
|
|
|
class TestRateLimitConfig:
|
|
def test_anonymous_limit(self, mock_settings):
|
|
with patch("src.api.middleware.rate_limit.get_settings", return_value=mock_settings):
|
|
from src.api.middleware.rate_limit import RateLimitMiddleware
|
|
app = MagicMock()
|
|
mw = RateLimitMiddleware(app)
|
|
assert mw.rate_limits["anonymous"]["burst"] == 10
|
|
|
|
def test_admin_limit(self, mock_settings):
|
|
with patch("src.api.middleware.rate_limit.get_settings", return_value=mock_settings):
|
|
from src.api.middleware.rate_limit import RateLimitMiddleware
|
|
app = MagicMock()
|
|
mw = RateLimitMiddleware(app)
|
|
assert mw.rate_limits["admin"]["requests"] == 10000
|