fix(jd-collect): groups 端点会话身份直取——requireOwnershipUserId(httpRequest,null) 对管理角色豁免原样返 null ⇒ 作用域空、管理员账号客户端分类下拉全空(2026-11-20 用户实录,普通号不受影响);改 requireSessionOwnerUserId(JdPublishController 同款既有方法),判据测试改端点级断言+反向绊线(退回即红)。jdcat 窗完成件随联验恢复窗提交发版;DesktopHomePage.vue 属该窗在飞工作未动

This commit is contained in:
2026-11-20 02:05:28 +08:00
parent d69780cbc1
commit e903bc1845
2 changed files with 30 additions and 9 deletions
@@ -22,6 +22,7 @@ import java.nio.file.Path;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.isNull;
@@ -53,13 +54,28 @@ class JdCollectGroupsEndpointTest {
String source = Files.readString(CONTROLLER);
assertTrue(source.contains("@GetMapping(\"/groups\")"),
"用户侧分类列表必须是 GET /groups(categories 同形)");
assertTrue(source.contains("jdCategoryScopeService.resolveByUserId(userId)"),
String groupsBody = groupsMethodBody(source);
assertTrue(groupsBody.contains("adminAuthSupport.requireSessionOwnerUserId(httpRequest, null)"),
"groups 必须用 requireSessionOwnerUserId 直取会话 id——requireOwnershipUserId(httpRequest, null)"
+ " 对管理角色(super_admin/company_super_admin/admin)豁免时原样返回请求值 null,"
+ "resolveByUserId(null) 落空作用域,管理员账号的客户端分类下拉全空"
+ "(2026-11-20 用户实录:后管京东数据库有分类、客户端「无数据」)");
assertFalse(groupsBody.contains("requireOwnershipUserId(httpRequest, null)"),
"groups 不得退回 requireOwnershipUserId(httpRequest, null)(管理角色豁免 ⇒ null ⇒ 空作用域);"
+ "categories 端点不消费返回值、不受此判据约束");
assertTrue(groupsBody.contains("jdCategoryScopeService.resolveByUserId(userId)"),
"可见组必须由 JdCategoryScopeService 按登录用户解析(端点不自己判角色)");
assertTrue(source.contains("jdProductGroupService.listForGroups(scope.visibleGroupIds())"),
assertTrue(groupsBody.contains("jdProductGroupService.listForGroups(scope.visibleGroupIds())"),
"必须按可见组取分类(listForGroups),不得退回 list() 全量下发"
+ "——否则普通号仍能看到别组的分类");
assertTrue(source.contains("adminAuthSupport.requireOwnershipUserId(httpRequest, null)"),
"登录用户即可读但必须 fail-closed:解析不出会话身份就 401(与 categories 同口径)");
}
/** 截取 @GetMapping("/groups") 方法体到下一个映射注解(判据只看本端点,不误伤 categories)。 */
private static String groupsMethodBody(String source) {
int start = source.indexOf("@GetMapping(\"/groups\")");
assertTrue(start >= 0, "groups 端点必须存在");
int end = source.indexOf("@GetMapping", start + 1);
return end > start ? source.substring(start, end) : source.substring(start);
}
@Test
@@ -85,7 +101,7 @@ class JdCollectGroupsEndpointTest {
vo.setName("ASSS");
vo.setOwnerGroupId(GROUP_ID);
vo.setProductCount(20L);
when(authSupport.requireOwnershipUserId(same(request), isNull())).thenReturn(USER_ID);
when(authSupport.requireSessionOwnerUserId(same(request), isNull())).thenReturn(USER_ID);
when(scopeService.resolveByUserId(USER_ID)).thenReturn(scope(GROUP_ID));
when(groupService.listForGroups(List.of(GROUP_ID))).thenReturn(List.of(vo));
@@ -99,7 +115,7 @@ class JdCollectGroupsEndpointTest {
assertEquals(GROUP_ID, response.getData().get(0).getOwnerGroupId());
assertEquals(20L, response.getData().get(0).getProductCount());
// 鉴权闸先行:解析不出会话身份就 401,读不到任何数据。
verify(authSupport).requireOwnershipUserId(same(request), isNull());
verify(authSupport).requireSessionOwnerUserId(same(request), isNull());
verify(scopeService).resolveByUserId(USER_ID);
verify(groupService).listForGroups(List.of(GROUP_ID));
}
@@ -121,7 +137,7 @@ class JdCollectGroupsEndpointTest {
mock(TaskProgressOwnershipSupport.class),
authSupport);
HttpServletRequest request = mock(HttpServletRequest.class);
when(authSupport.requireOwnershipUserId(same(request), isNull())).thenReturn(USER_ID);
when(authSupport.requireSessionOwnerUserId(same(request), isNull())).thenReturn(USER_ID);
when(scopeService.resolveByUserId(USER_ID)).thenReturn(JdCategoryScopeService.JdCategoryScope.empty());
when(groupService.listForGroups(List.of())).thenReturn(List.of());