/** * SC-C-16 个人资料查看(受限)三类流(child.auth.login / S-cfc-211 1:N) * ================================================================ * 端点:/api/auth/info(资料查看);/api/auth/profile/edit(部分可改:昵称/头像,手机为敏感字段需二次确认) * 正常流:登录用户查看资料返回完整 User 对象(含 id/nickname/role/phone 等非敏感脱敏字段); * 异常流:编辑昵称超长(>20 码点)→ 400「昵称不能超过 20 个字符」;手机号变更无验证码 → 400「需短信验证码二次确认」; * 手机号格式非法 → 400「手机号格式不正确」;空 body → 400「手机号不能为空」(实测契约,见下契约缺口)。 * 权限流:匿名查看资料 → 实测返回 200 + data=null(/api/auth/** 在 JwtInterceptor 白名单,不走 401), * 与 TC-C-16-P「期望 401/403」存在契约缺口——按禁臆造纪律如实标注,不断言 401、不写放水断言。 * 探针取证(2026-11-30 远端实测): * INFO_ANON {"code":200,"message":"success","data":null} * INFO 200 完整 User(id/openid/familyId/role/nickname/phone...) * EDIT_NICK_OK(仅昵称) 400「手机号不能为空」← 真实缺陷:编辑未填 phone 即被拒 * EDIT_NICK_LONG 400「昵称不能超过 20 个字符」 * EDIT_PHONE_NOVC 400「手机号变更需短信验证码二次确认」 * EDIT_PHONE_BADFMT 400「手机号格式不正确」 * 契约缺口(承袭·真实缺陷未修,不为缺陷造绿): * ① 匿名查看资料未返回 401(TC-C-16-P 期望 401/403),仅 data=null,属放行面; * ② /profile/edit 强制要求 phone 非空(EDIT_EMPTY/EDIT_NICK_OK 均 400「手机号不能为空」), * 正常昵称编辑无法单独成功——严格断言仅在超长/格式/缺验证码三个异常分支成立。 */ const { test, expect } = require('@playwright/test'); const { registerRole, apiPost, uniqueSuffix } = require('../helpers/api'); test.describe('SC-C-16 个人资料查看(受限)三类流', () => { let user; test.beforeAll(async ({ request }) => { user = await registerRole(request, 'parent', 'QA-PROF16' + uniqueSuffix()); expect(user.token, 'direct-register 应返回 token').toBeTruthy(); }); // ---------- 正常流 ---------- test('[C-16 正常] 登录用户查看资料返回完整 User 对象', async ({ request }) => { const r = await apiPost(request, '/api/auth/info', {}, user.token); expect(r.code, 'info: ' + r.message).toBe(200); const d = r.data || {}; expect(d.id, '应返回用户 id').toBeTruthy(); expect(typeof d.nickname).toBe('string'); // 敏感脱敏:password 不应回传明文(实测为 null) expect(d.password).toBeNull(); }); test('[C-16 正常] 资料含角色与家庭归属字段(受限查看范围)', async ({ request }) => { const r = await apiPost(request, '/api/auth/info', {}, user.token); expect(r.code).toBe(200); const d = r.data || {}; // 角色与家庭归属为资料可见字段 expect(d.role).toBeTruthy(); expect('familyId' in d).toBe(true); }); // ---------- 异常流 ---------- test('[C-16-E 异常] 编辑昵称超长(>20 码点)返回 400「昵称不能超过 20 个字符」', async ({ request }) => { const r = await apiPost(request, '/api/auth/profile/edit', { nickname: '超'.repeat(21) }, user.token); expect(r.code).toBe(400); expect(String(r.message)).toMatch(/昵称不能超过/i); }); test('[C-16-E 异常] 手机号变更缺验证码返回 400「需短信验证码二次确认」', async ({ request }) => { const r = await apiPost(request, '/api/auth/profile/edit', { phone: '13800001111' }, user.token); expect(r.code).toBe(400); expect(String(r.message)).toMatch(/短信验证码|二次确认/i); }); test('[C-16-E 异常] 手机号格式非法返回 400「手机号格式不正确」', async ({ request }) => { const r = await apiPost(request, '/api/auth/profile/edit', { phone: 'abc' }, user.token); expect(r.code).toBe(400); expect(String(r.message)).toMatch(/手机号格式/i); }); test('[C-16-E 异常] 编辑注入昵称(超长触发校验)不 500 且被 400 拦截', async ({ request }) => { const r = await apiPost(request, '/api/auth/profile/edit', { nickname: '