🐛 修复主题静态资源错误回退

同步测试分支已验证的静态资源 404 回归修复,避免缺失或越界资源被 SPA 首页兜底为 200。
This commit is contained in:
Orion committed 2026-08-07 09:24:35 +08:00
1 parent 3c427b5408
commit 5483e3b494
2 files changed
+22 -1

No files matched your search

+20 -1
View File
@@ -1,10 +1,11 @@
import asyncio
import unittest
from types import SimpleNamespace
from fastapi import HTTPException
from core.settings import BASE_DIR, settings
from main import index, resolve_theme_file
from main import index, resolve_theme_file, theme_asset
class SettingsOverrideMixin:
@@ -43,6 +44,24 @@ class ThemeAssetTests(SettingsOverrideMixin, unittest.TestCase):
self.assertEqual(error.exception.status_code, 404)
def test_theme_asset_returns_404_for_missing_or_traversal_paths(self):
settings.themesSelect = "themes/2023"
for asset_path in ("missing.js", "../../core/settings.py"):
with self.subTest(asset_path=asset_path):
with self.assertRaises(HTTPException) as error:
asyncio.run(theme_asset(asset_path))
self.assertEqual(error.exception.status_code, 404)
response = asyncio.run(
index(
request=SimpleNamespace(
url=SimpleNamespace(path="/theme-assets/missing.js")
)
)
)
self.assertEqual(response.status_code, 404)
def test_index_rewrites_assets_to_theme_specific_urls(self):
settings.themesSelect = "themes/2023"