| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- /**
- * AqXGNNVRNb v0.2.0 线上实测(2026-12-01):管理员 / 个人版各测一次改名并改回原名,另测越权 403。
- * 每次写入前把原名记入结果文件;结束后用 Master-Key 回读确认名称已恢复。
- * node scripts/verify-rename-live.mjs
- */
- import fs from 'node:fs';
- const OUT = 'test-results/rename-owner-20261201/live-verify.json';
- const FN = 'AqXGNNVRNb';
- const admin = JSON.parse(fs.readFileSync('.claude/dev-login.json', 'utf8'));
- const personal = JSON.parse(fs.readFileSync('.local-backup/dual-channel-20261201/personal-session.json', 'utf8').replace(/^"|"$/g, ''));
- const MK = admin.masterKey;
- const log = { startedAt: new Date().toISOString(), steps: [] };
- const save = () => fs.writeFileSync(OUT, JSON.stringify(log, null, 2));
- async function rename(token, agentId, displayName) {
- const res = await fetch('https://server.fmode.cn/api/functions', {
- method: 'POST',
- headers: { 'Content-Type': 'application/json' },
- body: JSON.stringify({ id: FN, token, params: { op: 'rename', agentId, displayName } }),
- });
- return { http: res.status, body: await res.json().catch(() => null) };
- }
- async function nameOf(agentId) {
- const where = encodeURIComponent(JSON.stringify({ agentId }));
- const res = await fetch(`https://server.fmode.cn/parse/classes/FmodeAgent?where=${where}&keys=name&limit=1`, {
- headers: { 'X-Parse-Application-Id': 'ncloudmaster', 'X-Parse-Master-Key': MK },
- });
- return (await res.json()).results?.[0]?.name;
- }
- async function step(label, who, token, agentId, displayName, expect) {
- const before = await nameOf(agentId);
- const entry = { label, who, agentId, displayName, expect, before };
- log.steps.push(entry);
- save(); // 先落盘再写线上
- const r = await rename(token, agentId, displayName);
- entry.result = r;
- entry.after = await nameOf(agentId);
- entry.pass = r.body?.code === expect && (expect === 200 ? entry.after === displayName : entry.after === before);
- save();
- console.log(`${entry.pass ? '✅' : '❌'} ${label}: code=${r.body?.code} msg=${r.body?.msg ?? ''} 名称 ${JSON.stringify(before)} → ${JSON.stringify(entry.after)}`);
- return entry;
- }
- const ADMIN_BOX = 'agent-node-app-harness-test';
- const MY_BOX = 'agent-node-app-0lk9iavzmm';
- const a = await step('管理员改自己的容器', 'admin', admin.token, ADMIN_BOX, '改名实测A', 200);
- if (a.pass) await step('管理员改回原名', 'admin', admin.token, ADMIN_BOX, a.before, 200);
- await step('管理员改外公司个人容器(应拒绝)', 'admin', admin.token, MY_BOX, '越权实测', 403);
- const p = await step('个人改自己的容器', 'personal', personal.t, MY_BOX, '改名实测P', 200);
- if (p.pass) await step('个人改回原名', 'personal', personal.t, MY_BOX, p.before, 200);
- await step('个人改别人的容器(应拒绝)', 'personal', personal.t, ADMIN_BOX, '越权实测', 403);
- const miss = await rename(personal.t, 'no-such-box-20261201', 'x');
- log.steps.push({ label: '个人改不存在的容器(应 403)', result: miss, pass: miss.body?.code === 403 });
- console.log(`${miss.body?.code === 403 ? '✅' : '❌'} 个人改不存在的容器: code=${miss.body?.code}`);
- log.finalNames = { [ADMIN_BOX]: await nameOf(ADMIN_BOX), [MY_BOX]: await nameOf(MY_BOX) };
- log.finishedAt = new Date().toISOString();
- log.allPass = log.steps.every((s) => s.pass);
- save();
- console.log('最终名称', log.finalNames, log.allPass ? '全部通过' : '有失败,见 ' + OUT);
|