fix(鉴权): 到期级联改标量聚合,后台入口按菜单授权放开
三件事同源于 10-06「非默认公司账号进不了数富后台」这条事故链,四种死法在界面上长得一样。 1) AccountExpiryService 读本公司公司超管的 expires_at 时把单列投影成实体列表再遍历—— MyBatis 对所选列全为 NULL 的行交出的是 null 元素,而"没设到期"是绝大多数公司的常态, 于是只要有一个永不过期的公司超管,该公司所有账号的登录与每个鉴权请求全部 500。 改成 mapper 侧一条 MIN(expires_at) 标量聚合;AuthChainQueryShapeTest 扫鉴权链路的 "单列投影"形状——这个判据落在 mock 边界外,单测挡不住,只能做源码扫描。 2) 后台入口放开:requireConsoleOperator = 管理员角色链 或 本公司树里 >=1 条后台菜单授权 (探针是带 company_id 条件的标量 COUNT,与下发口径一致,否则进得来而菜单树是空的)。 逐页另设 requireConsolePageAccess 锚住本页 key,勾父分组覆盖后代的既有语义照旧。 管理类 10 支控制器继续 requireAdmin,并且出口 2 不再把这些页下发给普通账号—— 下发出去就是一排点了必 403 的死链。内部令牌通道绕过到期与会话校验,不随入口放宽。 护栏 ConsoleWideningGuardrailTest 双向钉:管理页不得被授权打开、入口落点恰好那 13 支。 3) 前端:后端失败一律 HTTP 200 + success=false,登录页从未解包,所以"什么都不提示"。 补 login-feedback 归一文案(技术串不外露、兜底不再伪装成用户名或密码错误), 并修 isLoginLocation 拿路由内路径比 location.pathname——生产实际是 /admin-vue/login, 那条"已在登录页就别整页重刷"的守卫一次都没生效过。 验证:后端 mvn -o -B test 3924 例 0 红(457 支类);前端 node --test 1738 例 0 红; vue-tsc --noEmit rc=0;入口探针 SQL 已在生产库只读三档空跑(本公司 1 / 错公司 0 / 无授权 0)。
This commit is contained in:
+1
-1
@@ -45,7 +45,7 @@ class AdminConsoleCurrentUserCompanyTest {
|
||||
operator.setUsername("op");
|
||||
operator.setRole("admin");
|
||||
|
||||
when(adminAuthSupport.requireAdminOrInternal(request)).thenReturn(operator);
|
||||
when(adminAuthSupport.requireConsoleOperatorOrInternal(request)).thenReturn(operator);
|
||||
when(adminAuthSupport.currentRole(operator)).thenReturn("admin");
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -31,7 +31,7 @@ class AdminNotificationControllerTest {
|
||||
|
||||
@Test
|
||||
void listAndSummaryUseOperatorIdAndAdminAudience() {
|
||||
when(adminAuthSupport.requireAdmin(request)).thenReturn(admin(24L));
|
||||
when(adminAuthSupport.requireConsoleOperator(request)).thenReturn(admin(24L));
|
||||
|
||||
controller.summary(request);
|
||||
controller.page(request, 1L, 20L, false, "余额", NotificationService.CATEGORY_CONFIG_ERROR,
|
||||
@@ -52,7 +52,7 @@ class AdminNotificationControllerTest {
|
||||
|
||||
@Test
|
||||
void readMarkingStaysWithinOwnAdminAudienceRows() {
|
||||
when(adminAuthSupport.requireAdmin(request)).thenReturn(admin(1L));
|
||||
when(adminAuthSupport.requireConsoleOperator(request)).thenReturn(admin(1L));
|
||||
|
||||
controller.markRead(request, 18L);
|
||||
controller.markAllRead(request);
|
||||
|
||||
+308
@@ -0,0 +1,308 @@
|
||||
package com.nanri.aiimage.modules.permission.service;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatCode;
|
||||
import static org.assertj.core.api.Assertions.catchThrowableOfType;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.baomidou.mybatisplus.core.MybatisConfiguration;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
|
||||
import com.nanri.aiimage.common.exception.BusinessException;
|
||||
import com.nanri.aiimage.common.mapper.AdminUserMapper;
|
||||
import com.nanri.aiimage.common.model.entity.AdminUserEntity;
|
||||
import com.nanri.aiimage.modules.permission.mapper.PermissionMenuMapper;
|
||||
import com.nanri.aiimage.modules.permission.mapper.UserColumnPermissionMapper;
|
||||
import com.nanri.aiimage.modules.permission.model.entity.PermissionMenuEntity;
|
||||
import com.nanri.aiimage.modules.permission.model.entity.UserColumnPermissionEntity;
|
||||
import com.nanri.aiimage.modules.permission.model.vo.PermissionMenuItemVo;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import org.apache.ibatis.builder.MapperBuilderAssistant;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* 后台页面门(2026-10-06)与入口放开后的菜单下发。
|
||||
*
|
||||
* <p>入口放开不等于整站放开:现网 44 个普通账号带着「店铺管理」授权,若逐页门只看入口,
|
||||
* 它们顺手就能读同公司的密钥页、烧同公司的扣次数额度。
|
||||
* {@link PermissionMenuService#requireConsolePageAccess} 就是那一页自己的门。</p>
|
||||
*
|
||||
* <p>另一半在下发侧:管理/平台页({@code ADMIN_ONLY_MENU_KEYS})的后端出口仍是 requireAdmin,
|
||||
* 对普通账号继续下发这些菜单,等于给刚放进来的人画一排点了必 403 的死链。</p>
|
||||
*/
|
||||
class PermissionMenuServiceConsolePageTest {
|
||||
|
||||
private static final Long GROUP_ID = 200L;
|
||||
private static final Long SHOP_PAGE_ID = 201L;
|
||||
private static final Long USER_PAGE_ID = 202L;
|
||||
private static final Long SECRET_PAGE_ID = 203L;
|
||||
private static final Long TASK_CENTER_ID = 302L;
|
||||
private static final Long SHOP_DATA_MENU_ID = 300L;
|
||||
private static final Long SHOP_DATA_CHECK_ID = 303L;
|
||||
private static final Long SHOP_DATA_KEY_ID = 301L;
|
||||
|
||||
private PermissionMenuMapper menuMapper;
|
||||
private UserColumnPermissionMapper permissionMapper;
|
||||
private AdminUserMapper userMapper;
|
||||
private PermissionMenuService service;
|
||||
|
||||
/**
|
||||
* wrapper 的 lambda 条件要有 TableInfo 才解析得出列名({@code getSqlSegment()} 同理)。
|
||||
* 纯单测没有 Spring/MyBatis 启动过程,不初始化就会抛 {@code can not find lambda cache}。
|
||||
*/
|
||||
@BeforeAll
|
||||
static void initMybatisPlusTableInfo() {
|
||||
MapperBuilderAssistant assistant = new MapperBuilderAssistant(new MybatisConfiguration(), "");
|
||||
TableInfoHelper.initTableInfo(assistant, AdminUserEntity.class);
|
||||
TableInfoHelper.initTableInfo(assistant, PermissionMenuEntity.class);
|
||||
TableInfoHelper.initTableInfo(assistant, UserColumnPermissionEntity.class);
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
menuMapper = mock(PermissionMenuMapper.class);
|
||||
permissionMapper = mock(UserColumnPermissionMapper.class);
|
||||
userMapper = mock(AdminUserMapper.class);
|
||||
service = new PermissionMenuService(menuMapper, permissionMapper, userMapper);
|
||||
when(menuMapper.selectList(any())).thenReturn(catalog());
|
||||
when(menuMapper.selectById(any())).thenAnswer(invocation ->
|
||||
catalog().stream().filter(item -> item.getId().equals(invocation.getArgument(0)))
|
||||
.findFirst().orElse(null));
|
||||
// 与真库同形:requireDataPermission 走 selectOne,条件里带着本公司 + 那个 column_key。
|
||||
// wrapper 的参数是**惰性**绑定的:不求值 getSqlSegment() 时 paramNameValuePairs 是空 map,
|
||||
// 照空 map 过滤会让"命中"与"没命中"两支断言同时通过(夹具自己变成恒真)。
|
||||
when(menuMapper.selectOne(any())).thenAnswer(invocation -> {
|
||||
Collection<Object> params = params(invocation.getArgument(0));
|
||||
return catalog().stream()
|
||||
.filter(item -> params.contains(item.getColumnKey()) && params.contains(item.getCompanyId()))
|
||||
.findFirst().orElse(null);
|
||||
});
|
||||
when(userMapper.selectById(any())).thenAnswer(invocation -> user((Long) invocation.getArgument(0)));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- 逐页门
|
||||
|
||||
@Test
|
||||
void adminRolePassesEveryPageDoorWithoutLookingAtGrants() {
|
||||
assertThatCode(() -> service.requireConsolePageAccess(user(8L, "admin"), "无权访问店铺管理", "admin_shop_manage"))
|
||||
.doesNotThrowAnyException();
|
||||
|
||||
verify(menuMapper, never()).selectList(any());
|
||||
verify(permissionMapper, never()).selectByUserId(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void companySuperAdminAndSuperAdminPassPageDoorWithoutGrants() {
|
||||
assertThatCode(() -> service.requireConsolePageAccess(
|
||||
user(9L, "company_super_admin"), "无权访问店铺管理", "admin_shop_manage"))
|
||||
.doesNotThrowAnyException();
|
||||
assertThatCode(() -> service.requireConsolePageAccess(
|
||||
user(1L, "super_admin"), "无权访问店铺管理", "admin_shop_manage"))
|
||||
.doesNotThrowAnyException();
|
||||
}
|
||||
|
||||
@Test
|
||||
void normalAccountHoldingThisPagesGrantPasses() {
|
||||
grants(7L, SHOP_PAGE_ID);
|
||||
|
||||
assertThatCode(() -> service.requireConsolePageAccess(
|
||||
user(7L, "normal"), "无权访问店铺管理", "admin_shop_manage")).doesNotThrowAnyException();
|
||||
}
|
||||
|
||||
/** 相反的一半:勾了别的页换不来这一页——否则"入口放开"就变成"整站放开"。 */
|
||||
@Test
|
||||
void normalAccountHoldingAnotherPageGrantIsDeniedThisPage() {
|
||||
grants(7L, SECRET_PAGE_ID);
|
||||
|
||||
BusinessException ex = catchThrowableOfType(() -> service.requireConsolePageAccess(
|
||||
user(7L, "normal"), "无权访问店铺管理", "admin_shop_manage"), BusinessException.class);
|
||||
|
||||
assertThat(ex.getCode()).isEqualTo(403);
|
||||
assertThat(ex.getMessage()).isEqualTo("无权访问店铺管理");
|
||||
}
|
||||
|
||||
/** 勾父分组覆盖后代是授权页的既有语义,这一页的门必须照认。 */
|
||||
@Test
|
||||
void parentGroupGrantCoversTheChildPageDoor() {
|
||||
grants(7L, GROUP_ID);
|
||||
|
||||
assertThatCode(() -> service.requireConsolePageAccess(
|
||||
user(7L, "normal"), "无权访问店铺管理", "admin_shop_manage")).doesNotThrowAnyException();
|
||||
}
|
||||
|
||||
@Test
|
||||
void normalAccountWithoutAnyGrantIsDenied() {
|
||||
grants(7L);
|
||||
|
||||
BusinessException ex = catchThrowableOfType(() -> service.requireConsolePageAccess(
|
||||
user(7L, "normal"), "无权访问店铺管理", "admin_shop_manage"), BusinessException.class);
|
||||
|
||||
assertThat(ex.getCode()).isEqualTo(403);
|
||||
}
|
||||
|
||||
/** 多个键是"任一命中",不是"全部命中"。 */
|
||||
@Test
|
||||
void anyOfSeveralKeysOpensTheDoor() {
|
||||
grants(7L, SECRET_PAGE_ID);
|
||||
|
||||
assertThatCode(() -> service.requireConsolePageAccess(
|
||||
user(7L, "normal"), "无权", "admin_shop_manage", "admin_user_secrets"))
|
||||
.doesNotThrowAnyException();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- 下发侧剪枝
|
||||
|
||||
@Test
|
||||
void managementMenusAreNotPushedDownToNormalAccounts() {
|
||||
grants(7L, USER_PAGE_ID, SECRET_PAGE_ID, SHOP_PAGE_ID);
|
||||
|
||||
List<PermissionMenuItemVo> items = service.getUserColumnPermissions(null, 7L, "admin", false);
|
||||
|
||||
assertThat(items).extracting(PermissionMenuItemVo::getColumnKey)
|
||||
.as("店铺管理是数据页:普通账号被授了就照下发")
|
||||
.contains("admin_shop_manage");
|
||||
assertThat(items).extracting(PermissionMenuItemVo::getColumnKey)
|
||||
.as("用户管理/密钥管理的后端出口仍是 requireAdmin,下发出去就是死链")
|
||||
.doesNotContain("admin_users", "admin_user_secrets");
|
||||
}
|
||||
|
||||
/** 相反的一半:管理员角色照旧拿到管理页——放开普通账号不能顺手把管理员的菜单弄红。 */
|
||||
@Test
|
||||
void managementMenusStayVisibleForAdminRoles() {
|
||||
when(userMapper.selectById(8L)).thenReturn(user(8L, "admin"));
|
||||
grants(8L, USER_PAGE_ID, SECRET_PAGE_ID, SHOP_PAGE_ID);
|
||||
|
||||
List<PermissionMenuItemVo> items = service.getUserColumnPermissions(
|
||||
user(8L, "admin"), 8L, "admin", false);
|
||||
|
||||
assertThat(items).extracting(PermissionMenuItemVo::getColumnKey)
|
||||
.contains("admin_users", "admin_user_secrets", "admin_shop_manage");
|
||||
}
|
||||
|
||||
@Test
|
||||
void superAdminStillGetsTheWholeTree() {
|
||||
when(userMapper.selectById(1L)).thenReturn(user(1L, "super_admin"));
|
||||
|
||||
List<PermissionMenuItemVo> items = service.getUserColumnPermissions(null, 1L, "admin", false);
|
||||
|
||||
assertThat(items).extracting(PermissionMenuItemVo::getColumnKey)
|
||||
.contains("admin_users", "admin_user_secrets", "admin_shop_manage");
|
||||
}
|
||||
|
||||
// ----------------------------------------------------- 店铺数据/客户端任务的授权门
|
||||
|
||||
/** 这两道门此前第一句就判角色,普通账号即便被勾了菜单也永远走不到下面的授权命中(死代码)。 */
|
||||
@Test
|
||||
void shopDataDoorAdmitsNormalAccountHoldingTheGrants() {
|
||||
grants(7L, SHOP_DATA_MENU_ID, SHOP_DATA_KEY_ID);
|
||||
|
||||
assertThatCode(() -> service.requireShopDataCrawlTaskAccess(user(7L, "normal")))
|
||||
.doesNotThrowAnyException();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shopDataDoorStillDeniesNormalAccountWithoutTheGrants() {
|
||||
grants(7L, SHOP_PAGE_ID);
|
||||
|
||||
BusinessException ex = catchThrowableOfType(
|
||||
() -> service.requireShopDataCrawlTaskAccess(user(7L, "normal")), BusinessException.class);
|
||||
|
||||
assertThat(ex.getCode()).isEqualTo(403);
|
||||
assertThat(ex.getMessage()).isEqualTo("无权查看店铺数据任务");
|
||||
}
|
||||
|
||||
@Test
|
||||
void clientTaskDoorAdmitsNormalAccountHoldingThatMenu() {
|
||||
grants(7L, TASK_CENTER_ID);
|
||||
|
||||
assertThatCode(() -> service.requireClientTaskCenterAccess(user(7L, "normal")))
|
||||
.doesNotThrowAnyException();
|
||||
}
|
||||
|
||||
@Test
|
||||
void clientTaskDoorStillDeniesNormalAccountWithoutIt() {
|
||||
grants(7L, SHOP_PAGE_ID);
|
||||
|
||||
BusinessException ex = catchThrowableOfType(
|
||||
() -> service.requireClientTaskCenterAccess(user(7L, "normal")), BusinessException.class);
|
||||
|
||||
assertThat(ex.getCode()).isEqualTo(403);
|
||||
assertThat(ex.getMessage()).isEqualTo("无权查看客户端任务管理");
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- 夹具
|
||||
|
||||
private void grants(Long userId, Long... columnIds) {
|
||||
List<UserColumnPermissionEntity> rows = new ArrayList<>();
|
||||
for (Long columnId : columnIds) {
|
||||
UserColumnPermissionEntity row = new UserColumnPermissionEntity();
|
||||
row.setUserId(userId);
|
||||
row.setColumnId(columnId);
|
||||
rows.add(row);
|
||||
}
|
||||
when(permissionMapper.selectByUserId(userId)).thenReturn(rows);
|
||||
}
|
||||
|
||||
/** 取出 wrapper 上的绑定值;MP 是惰性绑定,不求值 SQL 段时那个 map 是空的。 */
|
||||
private static Collection<Object> params(LambdaQueryWrapper<PermissionMenuEntity> query) {
|
||||
String segment = query.getSqlSegment();
|
||||
Collection<Object> values = query.getParamNameValuePairs().values();
|
||||
if (values.isEmpty()) {
|
||||
throw new IllegalStateException("夹具读不到 wrapper 条件(segment=" + segment
|
||||
+ ")——空 map 会让命中/不命中两支断言同时通过");
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
private List<PermissionMenuEntity> catalog() {
|
||||
return List.of(
|
||||
menu(GROUP_ID, "admin_group_shop", null),
|
||||
menu(SHOP_PAGE_ID, "admin_shop_manage", GROUP_ID),
|
||||
menu(USER_PAGE_ID, "admin_users", null),
|
||||
menu(SECRET_PAGE_ID, "admin_user_secrets", null),
|
||||
menu(TASK_CENTER_ID, "admin_task_center", null),
|
||||
// 店铺数据那道门要同时命中「可见菜单」与内部数据权限
|
||||
menu(SHOP_DATA_MENU_ID, "admin_shop_data_crawl_tasks", null),
|
||||
menu(SHOP_DATA_CHECK_ID, "admin_shop_data_duplicate_check", null),
|
||||
menu(SHOP_DATA_KEY_ID, "admin_shop_data_crawl_task_data", null));
|
||||
}
|
||||
|
||||
private PermissionMenuEntity menu(Long id, String columnKey, Long parentId) {
|
||||
PermissionMenuEntity entity = new PermissionMenuEntity();
|
||||
entity.setId(id);
|
||||
entity.setColumnKey(columnKey);
|
||||
entity.setName(columnKey);
|
||||
entity.setParentId(parentId);
|
||||
entity.setMenuType("admin");
|
||||
entity.setCompanyId(1L);
|
||||
entity.setSortOrder(id.intValue());
|
||||
return entity;
|
||||
}
|
||||
|
||||
/** 缺省按普通账号建:夹具里 7L/8L/1L 这些 id 的角色由显式重载覆盖。 */
|
||||
private AdminUserEntity user(Long id) {
|
||||
AdminUserEntity user = new AdminUserEntity();
|
||||
user.setId(id);
|
||||
user.setUsername("u" + id);
|
||||
user.setRole("normal");
|
||||
user.setIsAdmin(0);
|
||||
user.setCreatedById(1L);
|
||||
user.setCompanyId(1L);
|
||||
return user;
|
||||
}
|
||||
|
||||
private AdminUserEntity user(Long id, String role) {
|
||||
AdminUserEntity user = user(id);
|
||||
user.setRole(role);
|
||||
user.setIsAdmin("normal".equals(role) ? 0 : 1);
|
||||
return user;
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -25,7 +25,7 @@ class AdminShopDataCrawlTaskControllerTest {
|
||||
AdminShopDataCrawlTaskController controller = new AdminShopDataCrawlTaskController(
|
||||
taskService, authSupport, permissionService);
|
||||
AdminUserEntity operator = admin(8L);
|
||||
when(authSupport.requireAdmin(request)).thenReturn(operator);
|
||||
when(authSupport.requireConsoleOperator(request)).thenReturn(operator);
|
||||
|
||||
controller.deleteHistory(101L, request);
|
||||
|
||||
@@ -43,7 +43,7 @@ class AdminShopDataCrawlTaskControllerTest {
|
||||
taskService, authSupport, permissionService);
|
||||
when(authSupport.isTrustedSuppliedToken("shared-token")).thenReturn(true);
|
||||
AdminUserEntity operator = admin(8L);
|
||||
when(authSupport.requireAdmin(request)).thenThrow(new BusinessException(401, "not logged in"));
|
||||
when(authSupport.requireConsoleOperator(request)).thenThrow(new BusinessException(401, "not logged in"));
|
||||
when(request.getHeader("X-Internal-Token")).thenReturn("shared-token");
|
||||
when(request.getParameter("operatorId")).thenReturn("8");
|
||||
when(permissionService.requireAdminOperator(8L)).thenReturn(operator);
|
||||
@@ -65,7 +65,7 @@ class AdminShopDataCrawlTaskControllerTest {
|
||||
taskService, authSupport, permissionService);
|
||||
AdminUserEntity operator = admin(8L);
|
||||
BusinessException denied = new BusinessException(403, "no data permission");
|
||||
when(authSupport.requireAdmin(request)).thenReturn(operator);
|
||||
when(authSupport.requireConsoleOperator(request)).thenReturn(operator);
|
||||
org.mockito.Mockito.doThrow(denied)
|
||||
.when(permissionService).requireShopDataCrawlTaskAccess(operator);
|
||||
|
||||
|
||||
+9
-7
@@ -45,16 +45,18 @@ class ShopKeyControllerCompanyScopeTest {
|
||||
private AdminAuthSupport adminAuthSupport;
|
||||
@Mock
|
||||
private DataReadScope dataReadScope;
|
||||
@Mock
|
||||
private com.nanri.aiimage.modules.permission.service.PermissionMenuService permissionMenuService;
|
||||
|
||||
private ShopKeyController controller() {
|
||||
return new ShopKeyController(shopKeyService, adminAuthSupport, dataReadScope);
|
||||
return new ShopKeyController(shopKeyService, adminAuthSupport, dataReadScope, permissionMenuService);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("列表:tab 的公司 id 交给 readCompanyIdOrOwn,出口给什么 service 就用什么")
|
||||
void pagePassesTheTabValueThroughTheDoor() {
|
||||
HttpServletRequest request = login();
|
||||
when(adminAuthSupport.requireAdminOrInternal(request)).thenReturn(user());
|
||||
when(adminAuthSupport.requireConsoleOperatorOrInternal(request)).thenReturn(user());
|
||||
when(dataReadScope.readCompanyIdOrOwn(any(AdminUserEntity.class), eq(COMPANY_ID))).thenReturn(COMPANY_ID);
|
||||
|
||||
controller().page(request, 1L, 15L, COMPANY_ID);
|
||||
@@ -72,7 +74,7 @@ class ShopKeyControllerCompanyScopeTest {
|
||||
@DisplayName("列表:出口判超管(null)时把 null 传下去,不补任何公司 id")
|
||||
void pageKeepsTheDoorsUnfilteredVerdict() {
|
||||
HttpServletRequest request = login();
|
||||
when(adminAuthSupport.requireAdminOrInternal(request)).thenReturn(user());
|
||||
when(adminAuthSupport.requireConsoleOperatorOrInternal(request)).thenReturn(user());
|
||||
when(dataReadScope.readCompanyIdOrOwn(any(AdminUserEntity.class), eq(COMPANY_ID))).thenReturn(null);
|
||||
|
||||
controller().page(request, 1L, 15L, COMPANY_ID);
|
||||
@@ -88,7 +90,7 @@ class ShopKeyControllerCompanyScopeTest {
|
||||
@DisplayName("列表:出口按会话收窄后,交给 service 的是收窄值而不是请求里的值")
|
||||
void pageUsesTheNarrowedValueNotTheRequestedOne() {
|
||||
HttpServletRequest request = login();
|
||||
when(adminAuthSupport.requireAdminOrInternal(request)).thenReturn(user());
|
||||
when(adminAuthSupport.requireConsoleOperatorOrInternal(request)).thenReturn(user());
|
||||
when(dataReadScope.readCompanyIdOrOwn(any(AdminUserEntity.class), eq(99L))).thenReturn(COMPANY_ID);
|
||||
|
||||
controller().page(request, 1L, 15L, 99L);
|
||||
@@ -100,7 +102,7 @@ class ShopKeyControllerCompanyScopeTest {
|
||||
@DisplayName("更新/删除/白名单检测:把 writeCompanyId 的判定原样交给 service,controller 不自己补公司 id")
|
||||
void writeEndpointsPassTheRowOwnershipGate() {
|
||||
HttpServletRequest request = login();
|
||||
when(adminAuthSupport.requireAdminOrInternal(request)).thenReturn(user());
|
||||
when(adminAuthSupport.requireConsoleOperatorOrInternal(request)).thenReturn(user());
|
||||
when(dataReadScope.writeCompanyId(any(AdminUserEntity.class))).thenReturn(COMPANY_ID);
|
||||
ShopKeyUpdateRequest body = new ShopKeyUpdateRequest();
|
||||
body.setZiniaoAccountName("ziniao-a");
|
||||
@@ -121,7 +123,7 @@ class ShopKeyControllerCompanyScopeTest {
|
||||
@DisplayName("写侧:闸门判超管(null)时把 null 传下去,否则超管被锁死在本公司")
|
||||
void writeGateKeepsTheSuperAdminVerdict() {
|
||||
HttpServletRequest request = login();
|
||||
when(adminAuthSupport.requireAdminOrInternal(request)).thenReturn(user());
|
||||
when(adminAuthSupport.requireConsoleOperatorOrInternal(request)).thenReturn(user());
|
||||
when(dataReadScope.writeCompanyId(any(AdminUserEntity.class))).thenReturn(null);
|
||||
ShopKeyUpdateRequest body = new ShopKeyUpdateRequest();
|
||||
body.setZiniaoAccountName("ziniao-a");
|
||||
@@ -140,7 +142,7 @@ class ShopKeyControllerCompanyScopeTest {
|
||||
@DisplayName("新增:只把操作者 id 交给 service,公司由 service 从会话推导")
|
||||
void createPassesOnlyTheOperator() {
|
||||
HttpServletRequest request = login();
|
||||
when(adminAuthSupport.requireAdminOrInternal(request)).thenReturn(user());
|
||||
when(adminAuthSupport.requireConsoleOperatorOrInternal(request)).thenReturn(user());
|
||||
ShopKeyCreateRequest body = new ShopKeyCreateRequest();
|
||||
body.setZiniaoAccountName("ziniao-a");
|
||||
body.setZiniaoToken("token-a");
|
||||
|
||||
+4
-1
@@ -32,10 +32,13 @@ class ShopManageCredentialAuthTest {
|
||||
private final ShopManageGroupService shopManageGroupService = mock(ShopManageGroupService.class);
|
||||
private final AdminAuthSupport adminAuthSupport = mock(AdminAuthSupport.class);
|
||||
private final DataReadScope dataReadScope = mock(DataReadScope.class);
|
||||
private final com.nanri.aiimage.modules.permission.service.PermissionMenuService permissionMenuService =
|
||||
mock(com.nanri.aiimage.modules.permission.service.PermissionMenuService.class);
|
||||
private final HttpServletRequest request = mock(HttpServletRequest.class);
|
||||
|
||||
private ShopManageController newController() {
|
||||
return new ShopManageController(shopManageService, shopManageGroupService, adminAuthSupport, dataReadScope);
|
||||
return new ShopManageController(shopManageService, shopManageGroupService, adminAuthSupport,
|
||||
dataReadScope, permissionMenuService);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user