import pytest from unittest.mock import patch, MagicMock from fastapi.testclient import TestClient from main import app # Create a test client client = TestClient(app) def test_health_check(): """Test the health check endpoint.""" response = client.get("/health") assert response.status_code == 200 assert "status" in response.json() assert response.json()["status"] == "healthy" def test_favicon(): """Test the favicon endpoint.""" response = client.get("/favicon.ico") # The favicon endpoint serves the actual favicon file, so we expect a 200 # If the file doesn't exist, it would return a 404, but in our case it should exist assert response.status_code == 200 def test_get_client_config(): """Test the client configuration endpoint.""" response = client.get("/config") assert response.status_code == 200 data = response.json() assert "client_id" in data assert "issuer" in data # Just check that we get a client_id, not necessarily the test value assert isinstance(data["client_id"], str) assert len(data["client_id"]) > 0 def test_root_serves_csp_with_nonce(): """Test that GET / returns a CSP header with a nonce and the inline script carries it.""" response = client.get("/") assert response.status_code == 200 csp = response.headers.get("content-security-policy", "") assert "nonce-" in csp assert "script-src" in csp assert "cdn.jsdelivr.net" not in csp assert "connect-src" in csp assert "login.infomaniak.com" in csp assert "api.coingecko.com" in csp assert "object-src 'none'" in csp body = response.text assert "