feat: implement setup redirect middleware and fix test suite

- Created SetupRedirectMiddleware to redirect unconfigured apps to /setup
- Enhanced /api/auth/setup endpoint to save anime_directory to config
- Updated SetupRequest model to accept optional anime_directory parameter
- Modified setup.html to send anime_directory in setup API call
- Added @pytest.mark.requires_clean_auth marker for tests needing unconfigured state
- Modified conftest.py to conditionally setup auth based on test marker
- Fixed all test failures (846/846 tests now passing)
- Updated instructions.md to mark setup tasks as complete

This implementation ensures users are guided through initial setup
before accessing the application, while maintaining test isolation
and preventing auth state leakage between tests.
This commit is contained in:
2025-10-24 19:55:26 +02:00
parent 260b98e548
commit 731fd56768
13 changed files with 438 additions and 66 deletions

View File

@@ -15,21 +15,40 @@ def pytest_configure(config):
"markers",
"security: mark test as a security test"
)
config.addinivalue_line(
"markers",
"requires_clean_auth: test requires auth to NOT be configured initially"
)
@pytest.fixture(autouse=True)
def reset_auth_and_rate_limits():
def reset_auth_and_rate_limits(request):
"""Reset authentication state and rate limits before each test.
This ensures:
1. Auth service state doesn't leak between tests
2. Rate limit window is reset for test client IP
3. Auth is configured with a default test password UNLESS the test
is marked with @pytest.mark.requires_clean_auth
Applied to all tests automatically via autouse=True.
"""
# Reset auth service state
auth_service._hash = None # noqa: SLF001
auth_service._failed.clear() # noqa: SLF001
# Check if test requires clean (unconfigured) auth state
requires_clean_auth = request.node.get_closest_marker("requires_clean_auth")
# Configure auth with a default test password so middleware allows requests
# This prevents the SetupRedirectMiddleware from blocking all test requests
# Skip this if the test explicitly needs clean auth state
if not requires_clean_auth:
try:
auth_service.setup_master_password("TestPass123!")
except Exception:
# If setup fails (e.g., already set), that's okay
pass
# Reset rate limiter - clear rate limit dict if middleware exists
# This prevents tests from hitting rate limits on auth endpoints
try: