|
@@ -0,0 +1,337 @@
|
|
|
|
|
+/**
|
|
|
|
|
+ * ================================================================
|
|
|
|
|
+ * SC-A-25 / SC-A-26 — 维度配置 + 能量配置 admin CRUD 三流 API 契约守卫
|
|
|
|
|
+ * (admin.dimension.config · S-cfc-199 1:N)
|
|
|
|
|
+ * ================================================================
|
|
|
|
|
+ * 契约溯源:docs/superpowers/api/API_REFERENCE.md §4.13 / §4.22
|
|
|
|
|
+ * DimensionConfigController /api/admin/dimension-config(5 端点)
|
|
|
|
|
+ * list / get / save / delete / tree
|
|
|
|
|
+ * AdminEnergyConfigController /api/admin/energy-config(6 端点)
|
|
|
|
|
+ * source-list / source-save / source-delete / daily-limits / daily-limit-save / overview
|
|
|
|
|
+ * 11 个 @PostMapping,与源码 @RequestMapping 逐条核对一致。
|
|
|
|
|
+ *
|
|
|
|
|
+ * 覆盖盘点(避免重复造用例):
|
|
|
|
|
+ * - 匿名 401(JwtInterceptor LOGIN_REQUIRED_PATHS 含 "/api/admin/" 整族)已由
|
|
|
|
|
+ * tests/e2e/api/auth-guard-admin-dimension-energy.spec.js
|
|
|
|
|
+ * (TC-AU-U153~U166,11/11 实测 401 请先登录 + data null)覆盖 —— 本轮不重复;
|
|
|
|
|
+ * - 本文件补齐其未覆盖的「正常流(admin)」「非 admin 403」「异常流细化」,
|
|
|
|
|
+ * 并将探针实测到的真实越权/写入缺陷以【承袭·真实缺陷未修】钉住,不造绿、不放水。
|
|
|
|
|
+ *
|
|
|
|
|
+ * 探针取证(tests/e2e/api/_probe_a25a26_*.spec.js,gitignored,本轮实测):
|
|
|
|
|
+ * - 匿名:11/11 → HTTP 401 {code:401,message:"请先登录",data:null}
|
|
|
|
|
+ * - 非 admin(parent token,注意 admin 族业务码在 body 内、HTTP 恒 200):
|
|
|
|
|
+ * dimension-config list/save/tree → code=403 无权限;
|
|
|
|
|
+ * get/delete 带 ?id → 403 无权限(不带 id 时 Spring 先报 400 缺少必填参数);
|
|
|
|
|
+ * energy-config source-delete → 403 无权限;
|
|
|
|
|
+ * energy-config source-list/daily-limits/overview → code=200 且带真实数据(越权读缺口);
|
|
|
|
|
+ * energy-config source-save/daily-limit-save → 未被 403 拦截(越权写入口,空体时 500)。
|
|
|
|
|
+ * - admin 正常流:
|
|
|
|
|
+ * dimension-config tree/list/get → 200;save 新增→get→save 编辑→delete 往返 → 200;
|
|
|
|
|
+ * energy-config source-list/daily-limits/overview → 200;daily-limit-save 幂等保存 → 200;
|
|
|
|
|
+ * energy-config source-save 合法写入 → code=400「数据不完整或格式错误」(DataIntegrityViolation),
|
|
|
|
|
+ * 远端部署写入链路阻塞(本地 origin/cfclub schema 无此约束,疑远端库表漂移)→ 钉为缺陷。
|
|
|
|
|
+ * - 异常流:见各用例断言(均来自探针实测,不臆造)。
|
|
|
|
|
+ *
|
|
|
|
|
+ * 跨家庭 403 说明(N/A):
|
|
|
|
|
+ * 维度/能量配置为「全局平台级 admin 配置」,请求体与路径均无 familyId 维度;
|
|
|
|
|
+ * 且 FamilyAccessInterceptor 对 /api/admin/** 直接放行(见该类 preHandle)。
|
|
|
|
|
+ * 故不存在「跨家庭越权面」,等价收敛为「非 admin 403」。此处显式记录,不造伪测例。
|
|
|
|
|
+ *
|
|
|
|
|
+ * 三流口径:
|
|
|
|
|
+ * - 正常流:admin 角色 CRUD/查询成功(source-save 因远端写入缺陷除外,已钉住);
|
|
|
|
|
+ * - 异常流:非法参数/缺失参数/不存在资源返回 400/500 且无业务数据(不 200 success);
|
|
|
|
|
+ * - 权限流:非 admin 访问受 rol 守卫端点必须 403(受守卫者),未受守卫者按实测钉缺陷。
|
|
|
|
|
+ *
|
|
|
|
|
+ * 运行:cd tests && npx playwright test -c playwright.config.api.js --project=desktop \
|
|
|
|
|
+ * e2e/api/sc-a25-a26-admin-dimension-energy-config.spec.js
|
|
|
|
|
+ * ================================================================
|
|
|
|
|
+ */
|
|
|
|
|
+const { test, expect } = require('@playwright/test');
|
|
|
|
|
+const { registerRole, apiPost, uniqueSuffix } = require('../helpers/api');
|
|
|
|
|
+
|
|
|
|
|
+test.describe('SC-A-25/A-26 admin 维度/能量配置 三流契约守卫', () => {
|
|
|
|
|
+ let admin;
|
|
|
|
|
+ let parent;
|
|
|
|
|
+
|
|
|
|
|
+ test.beforeAll(async ({ request }) => {
|
|
|
|
|
+ admin = await registerRole(request, 'admin', 'QA-A2526-ADM');
|
|
|
|
|
+ parent = await registerRole(request, 'parent', 'QA-A2526-PAR');
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // 辅助:取一个真实维度根 id(用于 get/delete 的 id 绑定场景)
|
|
|
|
|
+ async function firstDimRootId(request) {
|
|
|
|
|
+ const tree = await apiPost(request, '/api/admin/dimension-config/tree', {}, admin.token);
|
|
|
|
|
+ const roots = Array.isArray(tree.data) ? tree.data : [];
|
|
|
|
|
+ return roots.length && roots[0].id ? roots[0].id : null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // ==================================================================
|
|
|
|
|
+ // 正常流(admin)
|
|
|
|
|
+ // ==================================================================
|
|
|
|
|
+ test.describe('正常流(admin)', () => {
|
|
|
|
|
+ test('SC-A-25 正常流: dimension-config tree/list/get 均返回 200 且结构正确', async ({ request }) => {
|
|
|
|
|
+ const tree = await apiPost(request, '/api/admin/dimension-config/tree', {}, admin.token);
|
|
|
|
|
+ expect(tree.code, 'tree: ' + tree.message).toBe(200);
|
|
|
|
|
+ expect(Array.isArray(tree.data)).toBe(true);
|
|
|
|
|
+ expect(tree.data.length).toBeGreaterThanOrEqual(1);
|
|
|
|
|
+ expect(typeof tree.data[0].dimensionCode).toBe('string');
|
|
|
|
|
+ expect(tree.data[0].id).toBeTruthy();
|
|
|
|
|
+
|
|
|
|
|
+ const list = await apiPost(request, '/api/admin/dimension-config/list', { page: 1, size: 5 }, admin.token);
|
|
|
|
|
+ expect(list.code, 'list: ' + list.message).toBe(200);
|
|
|
|
|
+ expect(Array.isArray(list.data && list.data.records)).toBe(true);
|
|
|
|
|
+ expect(typeof (list.data && list.data.total)).toBe('number');
|
|
|
|
|
+
|
|
|
|
|
+ const id = tree.data[0].id;
|
|
|
|
|
+ const got = await apiPost(request, '/api/admin/dimension-config/get?id=' + id, {}, admin.token);
|
|
|
|
|
+ expect(got.code, 'get: ' + got.message).toBe(200);
|
|
|
|
|
+ expect(got.data && got.data.id).toBe(id);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ test('SC-A-25 正常流: dimension-config 新增→详情→编辑→删除 往返 200(自清理)', async ({ request }) => {
|
|
|
|
|
+ const code = '__e2e_a25_dim_' + uniqueSuffix();
|
|
|
|
|
+ const created = await apiPost(request, '/api/admin/dimension-config/save', {
|
|
|
|
|
+ dimensionCode: code, dimensionName: 'E2E维度' + code, dimensionType: 'health',
|
|
|
|
|
+ enabled: 1, sort: 999, nodeKind: 'sub', sourceSystem: 'health',
|
|
|
|
|
+ }, admin.token);
|
|
|
|
|
+ expect(created.code, 'save(create): ' + created.message).toBe(200);
|
|
|
|
|
+ const id = created.data && created.data.id;
|
|
|
|
|
+ expect(id).toBeTruthy();
|
|
|
|
|
+ try {
|
|
|
|
|
+ const got = await apiPost(request, '/api/admin/dimension-config/get?id=' + id, {}, admin.token);
|
|
|
|
|
+ expect(got.code, 'get(created): ' + got.message).toBe(200);
|
|
|
|
|
+ expect(got.data && got.data.dimensionCode).toBe(code);
|
|
|
|
|
+
|
|
|
|
|
+ // 编辑(updateById 仅更新非空字段 → 名称生效、其余保留)
|
|
|
|
|
+ const edited = await apiPost(request, '/api/admin/dimension-config/save', {
|
|
|
|
|
+ id, dimensionName: 'E2E维度-改' + code,
|
|
|
|
|
+ }, admin.token);
|
|
|
|
|
+ expect(edited.code, 'save(edit): ' + edited.message).toBe(200);
|
|
|
|
|
+ const after = await apiPost(request, '/api/admin/dimension-config/get?id=' + id, {}, admin.token);
|
|
|
|
|
+ expect(after.data && after.data.dimensionName).toBe('E2E维度-改' + code);
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ const del = await apiPost(request, '/api/admin/dimension-config/delete?id=' + id, {}, admin.token);
|
|
|
|
|
+ expect(del.code, 'delete(cleanup): ' + del.message).toBe(200);
|
|
|
|
|
+ expect(del.data == null).toBe(true);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ test('SC-A-26 正常流: energy-config source-list/daily-limits/overview 返回 200 且结构正确', async ({ request }) => {
|
|
|
|
|
+ const src = await apiPost(request, '/api/admin/energy-config/source-list', {}, admin.token);
|
|
|
|
|
+ expect(src.code, 'source-list: ' + src.message).toBe(200);
|
|
|
|
|
+ expect(Array.isArray(src.data)).toBe(true);
|
|
|
|
|
+ if (src.data.length > 0) {
|
|
|
|
|
+ expect(src.data[0]).toHaveProperty('sourceType');
|
|
|
|
|
+ expect(src.data[0]).toHaveProperty('sourceId');
|
|
|
|
|
+ expect(src.data[0]).toHaveProperty('ratio');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const dl = await apiPost(request, '/api/admin/energy-config/daily-limits', {}, admin.token);
|
|
|
|
|
+ expect(dl.code, 'daily-limits: ' + dl.message).toBe(200);
|
|
|
|
|
+ expect(Array.isArray(dl.data)).toBe(true);
|
|
|
|
|
+ if (dl.data.length > 0) {
|
|
|
|
|
+ expect(dl.data[0]).toHaveProperty('dimensionCode');
|
|
|
|
|
+ expect(dl.data[0]).toHaveProperty('dailyLimit');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const ov = await apiPost(request, '/api/admin/energy-config/overview', {}, admin.token);
|
|
|
|
|
+ expect(ov.code, 'overview: ' + ov.message).toBe(200);
|
|
|
|
|
+ expect(Array.isArray(ov.data && ov.data.sources)).toBe(true);
|
|
|
|
|
+ expect(Array.isArray(ov.data && ov.data.dailyLimits)).toBe(true);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ test('SC-A-26 正常流: daily-limit-save 幂等保存(回写现有值)返回 200', async ({ request }) => {
|
|
|
|
|
+ const dl = await apiPost(request, '/api/admin/energy-config/daily-limits', {}, admin.token);
|
|
|
|
|
+ expect(dl.code).toBe(200);
|
|
|
|
|
+ const first = (dl.data || [])[0];
|
|
|
|
|
+ test.skip(!first, '远端无既有每日上限行,跳过幂等回写(不新增、不留脏数据)');
|
|
|
|
|
+ const r = await apiPost(request, '/api/admin/energy-config/daily-limit-save', {
|
|
|
|
|
+ limits: [{ dimensionCode: first.dimensionCode, dailyLimit: first.dailyLimit }],
|
|
|
|
|
+ }, admin.token);
|
|
|
|
|
+ expect(r.code, 'daily-limit-save(idempotent): ' + r.message).toBe(200);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // 【承袭·真实缺陷未修】source-save 合法写入在远端部署被 DataIntegrityViolation 拦截。
|
|
|
|
|
+ // 断言钉住「当前真实契约」= 400「数据不完整或格式错误」(不落库),不伪造 200 绿。
|
|
|
|
|
+ // 若远端修复为可写入,本用例将因 code 变为 200 而转红,提示更新(回归绊线)。
|
|
|
|
|
+ test('SC-A-26 正常流【承袭·真实缺陷未修】: source-save 合法写入当前 400 DataIntegrity(远端写入链路阻塞)', async ({ request }) => {
|
|
|
|
|
+ const r = await apiPost(request, '/api/admin/energy-config/source-save', {
|
|
|
|
|
+ sourceType: '__E2E_' + uniqueSuffix(), sourceId: 12345, sourceName: 'e2e探针',
|
|
|
|
|
+ ratios: [{ dimensionId: 1, ratio: 100 }],
|
|
|
|
|
+ }, admin.token);
|
|
|
|
|
+ expect(r.code, '承袭缺陷:合法 source-save 被 DataIntegrityViolation 拦截 → ' + r.message).toBe(400);
|
|
|
|
|
+ expect(String(r.message || '')).toContain('数据不完整或格式错误');
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // ==================================================================
|
|
|
|
|
+ // 异常流
|
|
|
|
|
+ // ==================================================================
|
|
|
|
|
+ test.describe('异常流', () => {
|
|
|
|
|
+ test('异常流: dimension-config get/delete 缺 id → 400 缺少必填参数', async ({ request }) => {
|
|
|
|
|
+ const g = await apiPost(request, '/api/admin/dimension-config/get', {}, admin.token);
|
|
|
|
|
+ expect(g.code).toBe(400);
|
|
|
|
|
+ expect(String(g.message || '')).toContain('缺少必填参数');
|
|
|
|
|
+ expect(g.data == null).toBe(true);
|
|
|
|
|
+
|
|
|
|
|
+ const d = await apiPost(request, '/api/admin/dimension-config/delete', {}, admin.token);
|
|
|
|
|
+ expect(d.code).toBe(400);
|
|
|
|
|
+ expect(String(d.message || '')).toContain('缺少必填参数');
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ test('异常流: dimension-config get/delete 不存在 id → 500 业务失败无数据', async ({ request }) => {
|
|
|
|
|
+ const g = await apiPost(request, '/api/admin/dimension-config/get?id=99999999', {}, admin.token);
|
|
|
|
|
+ expect(g.code).toBe(500);
|
|
|
|
|
+ expect(String(g.message || '')).toContain('维度配置不存在');
|
|
|
|
|
+ expect(g.data == null).toBe(true);
|
|
|
|
|
+
|
|
|
|
|
+ const d = await apiPost(request, '/api/admin/dimension-config/delete?id=99999999', {}, admin.token);
|
|
|
|
|
+ expect(d.code).toBe(500);
|
|
|
|
|
+ expect(String(d.message || '')).toContain('删除失败');
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ test('异常流: dimension-config save 空体 → 非 200(服务端内部错误缺口,已钉住)', async ({ request }) => {
|
|
|
|
|
+ const r = await apiPost(request, '/api/admin/dimension-config/save', {}, admin.token);
|
|
|
|
|
+ expect(r.code).not.toBe(200);
|
|
|
|
|
+ expect(r.code).toBe(500); // 实测:{} → 500 服务器内部错误(NPE 缺口)
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ test('异常流: dimension-config save 缺 dimensionCode → 400 数据完整性拦截', async ({ request }) => {
|
|
|
|
|
+ const r = await apiPost(request, '/api/admin/dimension-config/save', { dimensionName: 'x' }, admin.token);
|
|
|
|
|
+ expect(r.code).toBe(400);
|
|
|
|
|
+ expect(String(r.message || '')).toContain('数据不完整或格式错误');
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ test('异常流: source-save 比例和≠100 → 400 来源比例之和必须为100', async ({ request }) => {
|
|
|
|
|
+ const r = await apiPost(request, '/api/admin/energy-config/source-save', {
|
|
|
|
|
+ sourceType: 'x', sourceId: 1, sourceName: 'x',
|
|
|
|
|
+ ratios: [{ dimensionId: 1, ratio: 40 }, { dimensionId: 2, ratio: 40 }],
|
|
|
|
|
+ }, admin.token);
|
|
|
|
|
+ expect(r.code).toBe(400);
|
|
|
|
|
+ expect(String(r.message || '')).toContain('来源比例之和必须为100');
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ test('异常流: source-save 负比例 → 400 来源比例不能为负数', async ({ request }) => {
|
|
|
|
|
+ const r = await apiPost(request, '/api/admin/energy-config/source-save', {
|
|
|
|
|
+ sourceType: 'x', sourceId: 1, sourceName: 'x', ratios: [{ dimensionId: 1, ratio: -10 }],
|
|
|
|
|
+ }, admin.token);
|
|
|
|
|
+ expect(r.code).toBe(400);
|
|
|
|
|
+ expect(String(r.message || '')).toContain('来源比例不能为负数');
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ test('异常流: source-save 比例>100 → 400 来源比例不能超过100', async ({ request }) => {
|
|
|
|
|
+ const r = await apiPost(request, '/api/admin/energy-config/source-save', {
|
|
|
|
|
+ sourceType: 'x', sourceId: 1, sourceName: 'x', ratios: [{ dimensionId: 1, ratio: 150 }],
|
|
|
|
|
+ }, admin.token);
|
|
|
|
|
+ expect(r.code).toBe(400);
|
|
|
|
|
+ expect(String(r.message || '')).toContain('来源比例不能超过100');
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ test('异常流: source-save ratio 元素为空 → 400 ratio 不能为空', async ({ request }) => {
|
|
|
|
|
+ const r = await apiPost(request, '/api/admin/energy-config/source-save', {
|
|
|
|
|
+ sourceType: 'x', sourceId: 1, sourceName: 'x', ratios: [{ dimensionId: 1, ratio: null }],
|
|
|
|
|
+ }, admin.token);
|
|
|
|
|
+ expect(r.code).toBe(400);
|
|
|
|
|
+ expect(String(r.message || '')).toContain('ratio 不能为空');
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ test('异常流: source-save ratios 为空窜 → 非 200(NPE 缺口,已钉住)', async ({ request }) => {
|
|
|
|
|
+ const r = await apiPost(request, '/api/admin/energy-config/source-save', {
|
|
|
|
|
+ sourceType: 'x', sourceId: 1, sourceName: 'x', ratios: null,
|
|
|
|
|
+ }, admin.token);
|
|
|
|
|
+ expect(r.code).not.toBe(200);
|
|
|
|
|
+ expect(r.code).toBe(500); // 实测:ratios=null → NPE → 500 服务器内部错误
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ test('异常流: daily-limit-save 负上限 → 400 每日能量上限不能为负数', async ({ request }) => {
|
|
|
|
|
+ const r = await apiPost(request, '/api/admin/energy-config/daily-limit-save', {
|
|
|
|
|
+ limits: [{ dimensionCode: 'body', dailyLimit: -5 }],
|
|
|
|
|
+ }, admin.token);
|
|
|
|
|
+ expect(r.code).toBe(400);
|
|
|
|
|
+ expect(String(r.message || '')).toContain('每日能量上限不能为负数');
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ test('异常流: daily-limit-save 超界(>1000) → 400 超出合理范围', async ({ request }) => {
|
|
|
|
|
+ const r = await apiPost(request, '/api/admin/energy-config/daily-limit-save', {
|
|
|
|
|
+ limits: [{ dimensionCode: 'body', dailyLimit: 1001 }],
|
|
|
|
|
+ }, admin.token);
|
|
|
|
|
+ expect(r.code).toBe(400);
|
|
|
|
|
+ expect(String(r.message || '')).toContain('超出合理范围');
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ test('异常流: daily-limit-save limits 为空 → 非 200 且无数据', async ({ request }) => {
|
|
|
|
|
+ const r = await apiPost(request, '/api/admin/energy-config/daily-limit-save', {}, admin.token);
|
|
|
|
|
+ expect(r.code).not.toBe(200);
|
|
|
|
|
+ expect(String(r.message || '')).toContain('limits不能为空');
|
|
|
|
|
+ expect(r.data == null).toBe(true);
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // ==================================================================
|
|
|
|
|
+ // 权限流(非 admin;匿名 401 已由 auth-guard-admin-dimension-energy.spec.js 覆盖)
|
|
|
|
|
+ // ==================================================================
|
|
|
|
|
+ test.describe('权限流(非 admin 403)', () => {
|
|
|
|
|
+ test('权限流: 非 admin 访问 dimension-config list/save/tree → 403 无权限', async ({ request }) => {
|
|
|
|
|
+ for (const [path, body] of [
|
|
|
|
|
+ ['/api/admin/dimension-config/list', {}],
|
|
|
|
|
+ ['/api/admin/dimension-config/save', {}],
|
|
|
|
|
+ ['/api/admin/dimension-config/tree', {}],
|
|
|
|
|
+ ]) {
|
|
|
|
|
+ const r = await apiPost(request, path, body, parent.token);
|
|
|
|
|
+ expect(r.code, path + ' 非 admin code=' + r.code + ' msg=' + r.message).toBe(403);
|
|
|
|
|
+ expect(String(r.message || '')).toContain('无权限');
|
|
|
|
|
+ expect(r.data == null).toBe(true);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ test('权限流: 非 admin 访问 dimension-config get/delete(带 id)→ 403 无权限', async ({ request }) => {
|
|
|
|
|
+ const id = await firstDimRootId(request);
|
|
|
|
|
+ expect(id, '需至少一个维度根用于 id 绑定场景').toBeTruthy();
|
|
|
|
|
+ for (const path of [
|
|
|
|
|
+ '/api/admin/dimension-config/get?id=' + id,
|
|
|
|
|
+ '/api/admin/dimension-config/delete?id=' + id,
|
|
|
|
|
+ ]) {
|
|
|
|
|
+ const r = await apiPost(request, path, {}, parent.token);
|
|
|
|
|
+ expect(r.code, path + ' 非 admin code=' + r.code + ' msg=' + r.message).toBe(403);
|
|
|
|
|
+ expect(String(r.message || '')).toContain('无权限');
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ test('权限流: 非 admin 访问 energy-config source-delete → 403 无权限(该端点唯一有 role 守卫)', async ({ request }) => {
|
|
|
|
|
+ const r = await apiPost(request, '/api/admin/energy-config/source-delete', { id: 1 }, parent.token);
|
|
|
|
|
+ expect(r.code).toBe(403);
|
|
|
|
|
+ expect(String(r.message || '')).toContain('无权限');
|
|
|
|
|
+ expect(r.data == null).toBe(true);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // 【承袭·真实缺陷未修】AdminEnergyConfigController 未对以下端点做 role=="admin" 守卫,
|
|
|
|
|
+ // 仅靠 JwtInterceptor 登录门;非 admin 登录用户可直接读到平台级配置(越权读泄露)。
|
|
|
|
|
+ // 断言钉住当前真实契约(200 + 真实数据),修复为 403 后本用例会转红,提示更新(回归绊线)。
|
|
|
|
|
+ test('权限流【承袭·真实缺陷未修】: 非 admin 读取 energy-config source-list/daily-limits/overview → 200 数据泄露', async ({ request }) => {
|
|
|
|
|
+ const src = await apiPost(request, '/api/admin/energy-config/source-list', {}, parent.token);
|
|
|
|
|
+ expect(src.code, '越权读缺口:source-list 非 admin code=' + src.code).toBe(200);
|
|
|
|
|
+ expect(Array.isArray(src.data)).toBe(true);
|
|
|
|
|
+
|
|
|
|
|
+ const dl = await apiPost(request, '/api/admin/energy-config/daily-limits', {}, parent.token);
|
|
|
|
|
+ expect(dl.code, '越权读缺口:daily-limits 非 admin code=' + dl.code).toBe(200);
|
|
|
|
|
+ expect(Array.isArray(dl.data)).toBe(true);
|
|
|
|
|
+
|
|
|
|
|
+ const ov = await apiPost(request, '/api/admin/energy-config/overview', {}, parent.token);
|
|
|
|
|
+ expect(ov.code, '越权读缺口:overview 非 admin code=' + ov.code).toBe(200);
|
|
|
|
|
+ expect(ov.data && Array.isArray(ov.data.sources)).toBe(true);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // 【承袭·真实缺陷未修】写入口同样无 role 守卫;用空体避免真实落库,
|
|
|
|
|
+ // 断言「未被 403 拦截、业务层被执行(返回 500 而非 403)」,证明越权写入口可达。
|
|
|
|
|
+ // 修复为 403 后本用例会转红,提示更新(回归绊线)。
|
|
|
|
|
+ test('权限流【承袭·真实缺陷未修】: 非 admin 可穿透至 energy-config source-save/daily-limit-save 业务层(未被 403 拦截)', async ({ request }) => {
|
|
|
|
|
+ const ss = await apiPost(request, '/api/admin/energy-config/source-save', {}, parent.token);
|
|
|
|
|
+ expect(ss.code, '越权写入口:source-save 非 admin 业务码=' + ss.code).not.toBe(403);
|
|
|
|
|
+ expect(ss.code).toBe(500); // 空体 → NPE → 500(证未在鉴权层被拦)
|
|
|
|
|
+
|
|
|
|
|
+ const ds = await apiPost(request, '/api/admin/energy-config/daily-limit-save', {}, parent.token);
|
|
|
|
|
+ expect(ds.code, '越权写入口:daily-limit-save 非 admin 业务码=' + ds.code).not.toBe(403);
|
|
|
|
|
+ expect(ds.code).toBe(500); // 空体 → limits不能为空(500)→ 证未在鉴权层被拦
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+});
|