""" Input Validation Security Tests. This module tests input validation across the application to ensure all user inputs are properly sanitized and validated. """ import pytest from httpx import AsyncClient from src.server.fastapi_app import app @pytest.mark.security class TestInputValidation: """Security tests for input validation.""" @pytest.fixture async def client(self): """Create async HTTP client for testing.""" from httpx import ASGITransport from src.server.services.auth_service import auth_service # Ensure auth is configured if not auth_service.is_configured(): auth_service.setup_master_password("TestPass123!") async with AsyncClient( transport=ASGITransport(app=app), base_url="http://test" ) as ac: # Login to get token r = await ac.post( "/api/auth/login", json={"password": "TestPass123!"} ) if r.status_code == 200: token = r.json()["access_token"] ac.headers["Authorization"] = f"Bearer {token}" yield ac @pytest.mark.asyncio async def test_xss_in_anime_title(self, client): """Test XSS protection in anime title input.""" xss_payloads = [ "", "", "javascript:alert('XSS')", "", ] for payload in xss_payloads: response = await client.post( "/api/anime", json={"title": payload, "description": "Test"}, ) # Should either reject or sanitize if response.status_code == 200: # If accepted, should be sanitized data = response.json() title = data.get("data", {}).get("title", "") assert "