| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- /**
- * ================================================================
- * 匿名访问鉴权门禁 · 已登记私有端点守卫(R556 新增)· TC-AU-U13 ~ TC-AU-U15
- * ================================================================
- * 需求/缺陷溯源:
- * - N-R478-1:POST /api/nutrition/profile/get 匿名 HTTP200/code200/data 非空
- * - N-R525-1:POST /api/team-star/my-view 匿名 HTTP200/code200/data 非空(哨兵零值 VO)
- * - N-R543-1:POST /api/product/review/reply 匿名 HTTP200/code500(写入口被放行到业务校验层)
- * 三处均由忽略型探针实测取证并已登记 blocker、push 研发通知;本 spec 把它们固化为
- * CI 可回归的**缺陷守卫**(当前预期红),修复(路由收录 + userId<=0→401)后自动转绿。
- *
- * 与既有 tests/e2e-live/auth-anonymous-guard.spec.js 的 TC-AU-U01~U12 不重叠:
- * 本文件只覆盖「已登记但未入库守卫」的 3 个私有端点,不重复造 U01~U12 的 12 点位。
- *
- * 三流口径:
- * - 权限流:匿名必须 401/403(当前 3 例红,属已登记缺陷,不放水为 200)
- * - 异常流:匿名空体探测不得返回业务 data / 业务成功码(当前 2 例红)
- * - 正常流:需真实 JWT + 业务身份,本档未注入凭据,禁臆造断言,交有凭据档承接
- *
- * 只读:仅发送空 body 探测鉴权门禁,不构造跨用户参数、不写业务数据;
- * 不打印响应体(可能含用户数据),仅打印状态码与用例编号。
- *
- * 运行:npx playwright test -c playwright.config.api.js --project=desktop \
- * e2e/api/auth-guard-registered-private.spec.js
- * ================================================================
- */
- const { test, expect } = require('@playwright/test');
- const API = process.env.LIVE_API_BASE || 'http://cfc.iwintrue.com';
- // [用例编号, 路径, blocker 编号, 说明]
- const ENDPOINTS = [
- ['TC-AU-U13', '/api/nutrition/profile/get', 'N-R478-1', '营养画像查询(私有读面)'],
- ['TC-AU-U14', '/api/team-star/my-view', 'N-R525-1', '星级看板我的视图(私有读面)'],
- ['TC-AU-U15', '/api/product/review/reply', 'N-R543-1', '商品评价回复(私有写入口)'],
- ];
- test.describe('匿名访问鉴权门禁 · 已登记私有端点缺陷守卫(N-R478-1/N-R525-1/N-R543-1)', () => {
- for (const [tc, path, bug, desc] of ENDPOINTS) {
- test(`${tc} [权限流] POST ${path} 未鉴权应被拒绝(401/403) · ${bug} ${desc}`, async ({ request }) => {
- const resp = await request.post(`${API}${path}`, {
- data: {},
- timeout: 20000,
- failOnStatusCode: false,
- });
- const status = resp.status();
- console.log(`[${tc}] POST ${path} -> HTTP ${status}`);
- expect(
- [401, 403],
- `${tc}/${bug} ${path} 匿名返回 ${status},期望 401/403(200 直通=鉴权门禁失守,已登记缺陷)`
- ).toContain(status);
- });
- test(`${tc}-E [异常流] POST ${path} 匿名空体不得返回业务成功码或业务数据 · ${bug}`, async ({ request }) => {
- const resp = await request.post(`${API}${path}`, {
- data: {},
- timeout: 20000,
- failOnStatusCode: false,
- });
- const status = resp.status();
- console.log(`[${tc}-E] POST ${path} -> HTTP ${status}`);
- const body = await resp.json().catch(() => ({}));
- expect(
- body.code === 200,
- `${tc}-E/${bug} 匿名空体不应得到业务成功码 200(HTTP ${status})`
- ).toBe(false);
- expect(
- body.data,
- `${tc}-E/${bug} 匿名空体不应返回业务数据(HTTP ${status} code=${body.code})`
- ).toBeFalsy();
- });
- }
- });
|