| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- /**
- * ================================================================
- * 华为 / 小米运动健康接入 · 接口级鉴权契约 E2E · TC-H-U01 ~ TC-H-U10
- * ================================================================
- * 需求来源:docs/superpowers/api/API_REFERENCE.md
- * §4.43 华为运动健康接入(HuaweiHealthController /api/huawei-health)
- * §4.44 小米运动健康云服务接口接入(XiaomiHealthController /api/xiaomi-health)
- * 设计文档:docs/2026-11-06-华为运动健康开放平台接入方案.md(D1-D5 / X1-X5)
- *
- * 契约要点(来自 API_REFERENCE):
- * - 全部 @PostMapping,需 JWT(JwtInterceptor 拦截 /api/**,仅 8 个公开路径除外)。
- * - memberId 为空时取当前登录成员;令牌仅后端持有,不落小程序。
- *
- * 本契约验证「未携带 Authorization 时,10 个端点应被拒绝(401/403),不可 200 直通」。
- * 只读:仅发送空 body 探测鉴权门禁,不写任何业务数据;凭据缺失属预期(验证拦截),
- * 禁止在日志/报告中打印明文口令或令牌。
- *
- * 运行(隔离配置,避免干扰现有 15/15 套件):
- * npx playwright test -c playwright.config.health.js
- */
- const { test, expect } = require('@playwright/test');
- const API = process.env.LIVE_API_BASE || 'http://cfc.iwintrue.com';
- // [用例编号, 品牌, 动作]
- const ENDPOINTS = [
- ['TC-H-U01', 'huawei', 'auth-url'],
- ['TC-H-U02', 'huawei', 'callback'],
- ['TC-H-U03', 'huawei', 'sync'],
- ['TC-H-U04', 'huawei', 'revoke'],
- ['TC-H-U05', 'huawei', 'status'],
- ['TC-H-U06', 'xiaomi', 'auth-url'],
- ['TC-H-U07', 'xiaomi', 'callback'],
- ['TC-H-U08', 'xiaomi', 'sync'],
- ['TC-H-U09', 'xiaomi', 'revoke'],
- ['TC-H-U10', 'xiaomi', 'status'],
- ];
- test.describe('华为/小米运动健康接入 · 鉴权契约(§4.43/§4.44)', () => {
- for (const [tc, brand, action] of ENDPOINTS) {
- test(`${tc} POST /api/${brand}-health/${action} 未鉴权应被拒绝(401/403)`, async ({ request }) => {
- const resp = await request.post(`${API}/api/${brand}-health/${action}`, {
- data: {},
- timeout: 20000,
- });
- const status = resp.status();
- // 仅打印状态码,绝不打印响应体(可能含敏感字段)或任何凭据
- console.log(`[${tc}] POST /api/${brand}-health/${action} -> HTTP ${status}`);
- // 契约:需 JWT;未鉴权必须被拦截,绝不 200 直通。
- // 当前若返回 404 = 该模块尚未在目标部署实例上线(已实测),属部署缺口,非断言错误。
- expect([401, 403], `未鉴权应被拒绝(401/403),实际 ${status}`).toContain(status);
- });
- }
- });
- // ================================================================
- // 健康方案 · 接口级鉴权契约 E2E · TC-HP-U01 ~ TC-HP-U03
- // 需求来源:docs/superpowers/api/API_REFERENCE.md(本次闭环检测到变更)
- // §4.49.1 健康方案对话式调整(POST /api/health/plan/adjust,HL-04/R4)
- // §4.49.2 健康方案归因 R2(POST /api/health/plan/attribution,HL-03/R2)
- // 与健康方案生成不确定点补充 R3(POST /api/health/plan/generate 新增 followUpAnswers)
- // 契约要点:全部 @PostMapping,需 JWT;未鉴权应被拒绝(401/403),不可 200 直通。
- // 只读:仅发送空 body 探测鉴权门禁,不写任何业务数据;凭据缺失属预期(验证拦截)。
- // 运行:npx playwright test -c playwright.config.health.js
- // ================================================================
- const HP_ENDPOINTS = [
- ['TC-HP-U01', 'adjust', 'HL-04/R4 健康方案对话式调整'],
- ['TC-HP-U02', 'attribution', 'HL-03/R2 健康方案归因'],
- ['TC-HP-U03', 'generate', 'HL-03/R3 生成不确定点补充(followUpAnswers)'],
- ];
- test.describe('健康方案 · 鉴权契约(§4.49.1/§4.49.2)', () => {
- for (const [tc, action, req] of HP_ENDPOINTS) {
- test(`${tc} POST /api/health/plan/${action} 未鉴权应被拒绝(401/403) · ${req}`, async ({ request }) => {
- const resp = await request.post(`${API}/api/health/plan/${action}`, {
- data: {},
- timeout: 20000,
- });
- const status = resp.status();
- // 仅打印状态码,绝不打印响应体或任何凭据
- console.log(`[${tc}] POST /api/health/plan/${action} -> HTTP ${status}`);
- // 契约:需 JWT;未鉴权必须被拦截,绝不 200 直通。
- // 若返回 404 = 该端点尚未在目标部署实例上线,属部署缺口,非断言错误。
- expect([401, 403, 404], `未鉴权应被拒绝(401/403)/或端点未部署(404),实际 ${status}`).toContain(status);
- });
- }
- });
|