feat(A1/A3): 三个客户端零调用前缀立即无条件收紧

实测桌面端 Python 侧调用面:/api/image-video、/api/task-file-jobs、/api/ziniao 为 0 次调用
(只有带 JWT 的网页端在用),因此从 user-tool-guard-enabled 开关名单移入无条件守卫名单,
不必等客户端铺开即完成收紧;其余 14 个前缀的客户端调用面与令牌携带情况已逐一实测,
仍在开关后面(老客户端不带身份,提前打开会 401)。

新增 2 个守卫测试:开关关闭时这三组前缀对匿名同样 401、带用户令牌仍放行。
This commit is contained in:
2026-09-14 10:46:05 +08:00
parent 36b82f884f
commit 8c95f053f5
2 changed files with 42 additions and 6 deletions
@@ -321,6 +321,39 @@ class AdminApiGuardFilterTest {
assertThat(chain.getRequest()).isNotNull();
}
@Test
void webOnlyPrefixesAreGuardedEvenWhenSwitchOff() throws Exception {
// 2026-09-14:image-video / task-file-jobs / ziniao 在桌面端 Python 侧零调用(实测),
// 因此不挂开关、无条件收紧——开关关闭时匿名也必须 401
for (String uri : new String[]{"/api/image-video/secrets", "/api/task-file-jobs/list", "/api/ziniao/staff"}) {
AdminAuthSupport authSupport = mock(AdminAuthSupport.class);
when(authSupport.requireUserOrInternal(any())).thenThrow(new BusinessException(401, "未登录"));
AdminApiGuardFilter filter = newFilter(authSupport, true, "", false);
MockHttpServletRequest request = new MockHttpServletRequest("GET", uri);
MockHttpServletResponse response = new MockHttpServletResponse();
MockFilterChain chain = new MockFilterChain();
filter.doFilter(request, response, chain);
assertThat(chain.getRequest()).as(uri + " 应被无条件守卫拦截").isNull();
assertThat(response.getContentAsString()).contains("401");
}
}
@Test
void webOnlyPrefixesStillLetWebUserTokenThrough() throws Exception {
AdminAuthSupport authSupport = mock(AdminAuthSupport.class);
when(authSupport.requireUserOrInternal(any())).thenReturn(new AdminUserEntity());
AdminApiGuardFilter filter = newFilter(authSupport, true, "", false);
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/api/image-video/secrets");
MockHttpServletResponse response = new MockHttpServletResponse();
MockFilterChain chain = new MockFilterChain();
filter.doFilter(request, response, chain);
assertThat(chain.getRequest()).isNotNull();
}
@Test
void enabledUserToolGuardCoversZiniaoPrefixAsSecondLayer() throws Exception {
AdminAuthSupport authSupport = mock(AdminAuthSupport.class);