test(admin): 京东上架额度写闸补三支回归判据(零生产码改动,2026-11-24 客户口径)

额度写权闸(AdminUserService.updateUser「无权修改京东上架额度」403)早已存在,本笔只钉死
它不被将来重构悄悄放宽:
- 管理员档操作者(非超管档)带额度提交(哪怕目标合法)→ 403 且不触库
- 公司超管改自己名下管理员额度 → 正面放行且 sqlSet 落 jd_publish_quota=8000
- 管理员档操作者编辑自己(target=admin)→ 编辑门 403「只能编辑自己创建的普通账号」,额度更碰不到
mvn -o test -Dtest=AdminUserServiceCompanySuperAdminTest 22/22 绿
This commit is contained in:
2026-11-24 15:16:38 +08:00
parent 4706c91afc
commit cf06872cb6
@@ -79,6 +79,66 @@ class AdminUserServiceCompanySuperAdminTest {
.isInstanceOf(BusinessException.class).hasMessageContaining("只能为管理员"); .isInstanceOf(BusinessException.class).hasMessageContaining("只能为管理员");
} }
/**
* 2026-11-24 客户口径「管理员 没办法给自己配合(改)这个配额,只有 公司管理员才可以;
* 如果管理员能配合的话 那大家都随便乱改了」——额度写权只归站点/公司超管档。
* 后端闸(updateUser「无权修改京东上架额度」)早已在,这三支钉死它不被将来重构悄悄放宽:
* ① 管理员档操作者(非超管档)带额度提交(哪怕目标是合法的自己名下 normal 账号)→ 403;
* ② 公司超管改自己名下管理员的额度 → 正面放行且落库;
* ③ 管理员档操作者编辑自己(target=admin)→ 连编辑门都进不去,额度更碰不到。
*/
@Test
void 管理员档操作者带额度提交一律被拒() {
AdminUserEntity operator = user(10L, "admin", 1L, 1L);
AdminUserEntity target = user(11L, "normal", 1L, 10L);
when(authSupport.currentRole(operator)).thenReturn("admin");
when(userMapper.selectById(11L)).thenReturn(target);
AdminUserUpdateRequest request = new AdminUserUpdateRequest();
request.setJdPublishQuota(3000);
BusinessException ex = catchThrowableOfType(() -> service.updateUser(operator, 11L, request),
BusinessException.class);
assertThat(ex).isNotNull();
assertThat(ex.getCode()).isEqualTo(403);
assertThat(ex.getMessage()).contains("无权修改京东上架额度");
verify(userMapper, never()).update(any(), any());
}
@Test
void 公司超管改自己名下管理员的额度放行并落库() {
AdminUserEntity operator = user(9L, "company_super_admin", 1L, 2L);
AdminUserEntity target = user(12L, "admin", 1L, 9L);
when(authSupport.currentRole(operator)).thenReturn("company_super_admin");
when(userMapper.selectById(12L)).thenReturn(target);
AdminUserUpdateRequest request = new AdminUserUpdateRequest();
request.setJdPublishQuota(8000);
service.updateUser(operator, 12L, request);
ArgumentCaptor<LambdaUpdateWrapper<AdminUserEntity>> captor =
ArgumentCaptor.forClass(LambdaUpdateWrapper.class);
verify(userMapper).update(org.mockito.ArgumentMatchers.isNull(), captor.capture());
assertThat(captor.getValue().getSqlSet()).contains("jd_publish_quota");
assertThat(captor.getValue().getParamNameValuePairs().values()).contains(8000);
}
@Test
void 管理员档操作者编辑自己连额度门都进不去() {
AdminUserEntity operator = user(10L, "admin", 1L, 1L);
when(authSupport.currentRole(operator)).thenReturn("admin");
when(userMapper.selectById(10L)).thenReturn(operator);
AdminUserUpdateRequest request = new AdminUserUpdateRequest();
request.setJdPublishQuota(9999);
assertThatThrownBy(() -> service.updateUser(operator, 10L, request))
.isInstanceOf(BusinessException.class)
.hasMessageContaining("只能编辑自己创建的普通账号");
verify(userMapper, never()).update(any(), any());
}
// ---------- 建号 ---------- // ---------- 建号 ----------
@Test @Test