fix(jd-collect): groups 端点会话身份直取——requireOwnershipUserId(httpRequest,null) 对管理角色豁免原样返 null ⇒ 作用域空、管理员账号客户端分类下拉全空(2026-11-20 用户实录,普通号不受影响);改 requireSessionOwnerUserId(JdPublishController 同款既有方法),判据测试改端点级断言+反向绊线(退回即红)。jdcat 窗完成件随联验恢复窗提交发版;DesktopHomePage.vue 属该窗在飞工作未动
This commit is contained in:
+7
-2
@@ -88,8 +88,13 @@ public class JdCollectController {
|
||||
+ "(自己所属组的组长带的组)的分类,别组的一律不下发——这正是「不同组不能看到跨组的分类」。"
|
||||
+ "只读不写——分类的增删改仍只在后管(本组管理员)。")
|
||||
public ApiResponse<List<JdProductGroupVo>> groups(HttpServletRequest httpRequest) {
|
||||
// 登录用户即可读:解析不出会话身份就 401(fail-closed,与建单同口径)。
|
||||
Long userId = adminAuthSupport.requireOwnershipUserId(httpRequest, null);
|
||||
// 会话身份直取(管理员也不例外):requireOwnershipUserId 走 bindOwnershipUserId,对管理角色
|
||||
// 豁免时「原样返回请求值」——传 null 就拿回 null,resolveByUserId(null) 落空作用域,
|
||||
// 平台超管/公司超管/管理员三类账号的客户端分类下拉全空(2026-11-20 用户实录:后管
|
||||
// 京东数据库有分类、客户端「无数据」;普通号走 identity.getId() 不受影响,
|
||||
// 2026-11-16「普通账户都能看到」口径验证时没暴露)。登录用户即可读,
|
||||
// 解析不出会话身份仍 401(fail-closed)。
|
||||
Long userId = adminAuthSupport.requireSessionOwnerUserId(httpRequest, null);
|
||||
JdCategoryScopeService.JdCategoryScope scope = jdCategoryScopeService.resolveByUserId(userId);
|
||||
return ApiResponse.success(jdProductGroupService.listForGroups(scope.visibleGroupIds()));
|
||||
}
|
||||
|
||||
+23
-7
@@ -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());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user