from fastapi.testclient import TestClient

from app.main import app

client = TestClient(app)


def test_response_includes_security_headers():
    response = client.get("/api/v1/health")
    assert response.headers["x-content-type-options"] == "nosniff"
    assert response.headers["x-frame-options"] == "DENY"
    assert response.headers["referrer-policy"] == "strict-origin-when-cross-origin"
    assert "max-age=63072000" in response.headers["strict-transport-security"]


def test_cors_does_not_reflect_unlisted_origin_by_default():
    """cors_allowed_origins is empty by default (see app.core.config) —
    no browser origin should get itself reflected back."""
    response = client.get(
        "/api/v1/health", headers={"Origin": "https://evil.example.com"}
    )
    assert "access-control-allow-origin" not in response.headers
