From 8e9c9b41e14557bbdf80fa6045cc52dbb75c2372 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Wed, 30 Sep 2026 23:31:55 +0800 Subject: [PATCH] fix(api): allow slashes in rule group names --- app/api/endpoints/rule.py | 4 ++-- tests/test_api_authorization.py | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/api/endpoints/rule.py b/app/api/endpoints/rule.py index 6c0ad62d0..d7c06d4f7 100644 --- a/app/api/endpoints/rule.py +++ b/app/api/endpoints/rule.py @@ -246,7 +246,7 @@ async def reorder_rule_groups( @router.put( # type: ignore[misc] - "/groups/{name}", + "/groups/{name:path}", summary="更新过滤规则组", response_model=_SchemaResponse[_SchemaJsonObject], ) @@ -268,7 +268,7 @@ async def update_rule_group( @router.delete( # type: ignore[misc] - "/groups/{name}", + "/groups/{name:path}", summary="删除过滤规则组", response_model=_SchemaResponse[_SchemaJsonObject], ) diff --git a/tests/test_api_authorization.py b/tests/test_api_authorization.py index 2684fd271..7f481cd8d 100644 --- a/tests/test_api_authorization.py +++ b/tests/test_api_authorization.py @@ -107,6 +107,18 @@ def test_rule_query_and_mutation_endpoints_keep_separate_permissions(): assert _dependency_of(endpoint, "_") is get_current_active_superuser_async +def test_rule_group_mutation_routes_accept_slashes_in_group_names(): + """规则组名称允许包含斜杠时,更新和删除路由必须接收完整名称。""" + routes = { + (route.endpoint, frozenset(route.methods)): route.path + for route in rule_endpoint.router.routes + if hasattr(route, "endpoint") + } + + assert routes[(rule_endpoint.update_rule_group, frozenset({"PUT"}))] == "/groups/{name:path}" + assert routes[(rule_endpoint.delete_rule_group, frozenset({"DELETE"}))] == "/groups/{name:path}" + + def test_dashboard_endpoints_require_superuser(): """仪表板页面相关接口必须只允许管理员访问。""" assert _dependency_of(dashboard_endpoint.statistic, "_") is get_current_active_superuser