import time import uuid from contextlib import contextmanager import httpx import pytest import urllib3 from fastapi import HTTPException from minio.error import S3Error from sqlalchemy import func, inspect, select from app.core.config import get_settings from app.services.html_filter import filter_html _PUBLIC_KEYS = { "siteName", "logoUrl", "bannerUrls", "icpText", "policeText", "friendLinks", "linkCirea", "linkHousing", } def test_object_key_keeps_safe_extension(monkeypatch): monkeypatch.setenv("MINIO_BASE_URL", "http://127.0.0.1:9000/gsfdc-public/") get_settings.cache_clear() try: from app.services.storage import make_object_key, public_object_url, safe_filename assert safe_filename("../../logo.PNG") == "logo.PNG" key = make_object_key("../../logo.PNG") assert ".." not in key assert key.endswith(".png") url = public_object_url(key) assert url == "http://127.0.0.1:9000/gsfdc-public/" + key assert "//" not in url.replace("://", "") finally: get_settings.cache_clear() def test_html_whitelist_removes_active_content(): html = ( '
正文敏感词
' '链接' "" "" '
'
'
'
)
cleaned = filter_html(html, ["2026/10/19/abc.png"], "http://127.0.0.1:9000/gsfdc-public")
lowered = cleaned.lower()
assert "'
response = ready_client.post(
"/api/admin/content/preview-filter",
json={"html": html},
headers=headers,
)
assert response.status_code == 200, response.text
body = response.json()
assert word in body["hits"]
assert body["html"].count(word) == 1
assert "