|
@@ -0,0 +1,79 @@
|
|
|
|
|
+/**
|
|
|
|
|
+ * ================================================================
|
|
|
|
|
+ * 匿名访问鉴权门禁 · 报告模板管理端点守卫(本轮新增)· TC-AU-U176 ~ TC-AU-U181
|
|
|
|
|
+ * ================================================================
|
|
|
|
|
+ * 契约溯源:docs/superpowers/api/API_REFERENCE.md
|
|
|
|
|
+ * §4.16 报告模板管理(ReportTemplateController /api/admin/report-template,6 端点)
|
|
|
|
|
+ * 源码 cfc-backend/src/main/java/com/etotem/cfc/controller/admin/
|
|
|
|
|
+ * ReportTemplateController.java 6 个 @PostMapping,逐条与文档 Mapping 核对一致;
|
|
|
|
|
+ * JwtInterceptor LOGIN_REQUIRED_PATHS 含 "/api/admin/" 整族,匿名(无 token)必须由拦截器拒绝。
|
|
|
|
|
+ *
|
|
|
|
|
+ * 覆盖盘点(B 类 20 分档):
|
|
|
|
|
+ * - tests/** 下 *.spec.js 对 /api/admin/report-template 鉴权守卫 0 命中(源码存在、E2E 无守卫);
|
|
|
|
|
+ * - TC-AU-U01~U12(12 匿名点位)、U13~U15(已登记私有端点)、U16~U19(SC-A-04 字典)、
|
|
|
|
|
+ * U20~U31(food-rule)、U32~U42(file-record/supply-team)、U43~U58(org)、
|
|
|
|
|
+ * U59~U65(配置中心)、U66~U80(coupon/log/audit)、U81~U101(库存/供应商商品)、
|
|
|
|
|
+ * U102~U128(规划师认证/课程/考试)、U129~U145(规划师配置/测评材料)、
|
|
|
|
|
+ * U146~U175(知识库/维度能量等他轮新增)与本文件 6 端点不重叠;
|
|
|
|
|
+ * - 本文件只补权限流/异常流,不重复造正常流业务断言。
|
|
|
|
|
+ *
|
|
|
|
|
+ * 契约取证(忽略型探针,无凭据空体 {},本轮实测 6/6 逐位一致):
|
|
|
|
|
+ * HTTP 401 / {"code":401,"message":"请先登录","data":null}
|
|
|
|
|
+ * 探针只发空体,不写业务数据、不触碰 save/delete/toggle 真实写入(匿名即被拦截,未穿透)。
|
|
|
|
|
+ * get/delete 服务端签名为 @RequestParam,匿名空体同样在 JwtInterceptor 处被拒(401),
|
|
|
|
|
+ * 断言据此写,不臆造非 200、不构造业务参数。
|
|
|
|
|
+ *
|
|
|
|
|
+ * 三流口径:
|
|
|
|
|
+ * - 权限流:JWT 缺失必须被 JwtInterceptor 拒绝,不得放行到控制器/业务层(6 例);
|
|
|
|
|
+ * - 异常流:匿名空体不得返回业务成功码或任何业务数据(同 6 例内联合断言);
|
|
|
|
|
+ * - 正常流:admin 角色模板 CRUD/启停/指标列表需真实 JWT 与有效业务体,
|
|
|
|
|
+ * 本档未注入凭据、禁臆造断言,交有凭据档承接。
|
|
|
|
|
+ *
|
|
|
|
|
+ * 运行:cd tests && npx playwright test -c playwright.config.api.js --project=desktop \
|
|
|
|
|
+ * e2e/api/auth-guard-admin-report-template.spec.js
|
|
|
|
|
+ * ================================================================
|
|
|
|
|
+ */
|
|
|
|
|
+const { test, expect } = require('@playwright/test');
|
|
|
|
|
+
|
|
|
|
|
+const API = process.env.LIVE_API_BASE || 'http://cfc.iwintrue.com';
|
|
|
|
|
+
|
|
|
|
|
+// [用例编号, 完整路径, API_REFERENCE §4.16 接口说明]
|
|
|
|
|
+const ENDPOINTS = [
|
|
|
|
|
+ ['TC-AU-U176', '/api/admin/report-template/list', '§4.16 模板列表(只读,支持 reportType/isActive 过滤)'],
|
|
|
|
|
+ ['TC-AU-U177', '/api/admin/report-template/get', '§4.16 按 reportType 获取模板(只读)'],
|
|
|
|
|
+ ['TC-AU-U178', '/api/admin/report-template/save', '§4.16 保存模板(写入口)'],
|
|
|
|
|
+ ['TC-AU-U179', '/api/admin/report-template/delete', '§4.16 删除模板(写入口)'],
|
|
|
|
|
+ ['TC-AU-U180', '/api/admin/report-template/toggle', '§4.16 启停模板(写入口)'],
|
|
|
|
|
+ ['TC-AU-U181', '/api/admin/report-template/indicators', '§4.16 可选指标列表(只读,支持 domain 过滤)'],
|
|
|
|
|
+];
|
|
|
|
|
+
|
|
|
|
|
+test.describe('匿名访问鉴权门禁 · 报告模板管理六端点(§4.16 权限/异常流)', () => {
|
|
|
|
|
+ for (const [tc, path, desc] of ENDPOINTS) {
|
|
|
|
|
+ test(`${tc} [权限流+异常流] POST ${path} 匿名空体应被拒且无业务数据 · ${desc}`, async ({ request }) => {
|
|
|
|
|
+ const resp = await request.post(`${API}${path}`, {
|
|
|
|
|
+ data: {},
|
|
|
|
|
+ timeout: 20000,
|
|
|
|
|
+ failOnStatusCode: false,
|
|
|
|
|
+ });
|
|
|
|
|
+ const status = resp.status();
|
|
|
|
|
+ let body = {};
|
|
|
|
|
+ try { body = await resp.json(); } catch (e) { body = {}; }
|
|
|
|
|
+ console.log(`[${tc}] POST ${path} -> HTTP ${status} code=${body.code}`);
|
|
|
|
|
+
|
|
|
|
|
+ // 权限流:JWT 缺失必须由拦截器拒绝,不得放行到控制器/业务层
|
|
|
|
|
+ expect(
|
|
|
|
|
+ [401, 403],
|
|
|
|
|
+ `${tc} ${path} 匿名返回 HTTP ${status},期望 401/403(200 直通=报告模板配置失守)`
|
|
|
|
|
+ ).toContain(status);
|
|
|
|
|
+ expect(
|
|
|
|
|
+ [401, 403],
|
|
|
|
|
+ `${tc} ${path} 匿名业务码 ${body.code},期望 401/403`
|
|
|
|
|
+ ).toContain(body.code);
|
|
|
|
|
+ expect(String(body.message || '')).toContain('登录');
|
|
|
|
|
+
|
|
|
|
|
+ // 异常流:空体探测不得返回业务成功码或任何业务数据
|
|
|
|
|
+ expect(body.code === 200, `${tc} 匿名空体不应得到业务成功码 200`).toBe(false);
|
|
|
|
|
+ expect(body.data == null, `${tc} 匿名空体不应返回业务数据(HTTP ${status} code=${body.code})`).toBe(true);
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+});
|