fix: 收口模板契约与安全门禁

统一模板包 visual 契约并补齐完成证据;修复 release 版本一致性、管理员 token 撤销、CORS 与默认品牌配置;收敛依赖安全风险并完成全量回归验证。
This commit is contained in:
que01 committed 2026-10-18 22:05:31 +08:00
1 parent 456171aa85
commit 4f0b50c7f1
84 files changed
+7367 -5180

No files matched your search

+68 -2
View File
@@ -5,8 +5,9 @@ import { mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync } from "n
import os from "node:os";
import path from "node:path";
import { after, before, test } from "node:test";
import bcrypt from "bcryptjs";
import { PrismaClient } from "@prisma/client";
import { getVisualTemplateManifest } from "@personal-brand/config";
import { getTemplatePackageManifest, getVisualTemplateManifest } from "@personal-brand/config";
import { createApp } from "../dist/main.js";
import { readIdentity, signIdentity } from "../dist/auth.js";
import { WechatAuthService } from "../dist/wechat-auth.js";
@@ -140,7 +141,7 @@ test("模板目录只允许平台模板管理员访问,并支持安全、幂
]);
const linjingVersion = baseline.items.find((item) => item.packageKey === "linjing-editorial");
assert.ok(linjingVersion);
assert.equal(linjingVersion.version, "1.0.5");
assert.equal(linjingVersion.version, "1.0.6");
const linjingPreview = await request(
`/admin/templates/${linjingVersion.id}/preview?industry=doors`,
{ headers },
@@ -1882,8 +1883,13 @@ test("visual template compatibility is enforced by catalog, preview, and version
const visuals = JSON.parse(catalog.body).visuals;
for (const visual of visuals) {
const manifest = getVisualTemplateManifest(visual.key);
const packageManifest = getTemplatePackageManifest(visual.key);
assert.ok(manifest, `Catalog visual must be installable: ${visual.key}`);
assert.ok(packageManifest, `Catalog visual must have a package manifest: ${visual.key}`);
assert.equal(manifest.key, visual.key);
assert.equal(manifest.key, packageManifest.visualTemplateKey);
assert.equal(manifest.version, packageManifest.version);
assert.equal(visual.version, packageManifest.version);
assert.deepEqual(manifest.supportedIndustryTemplates, visual.supportedIndustryTemplates);
}
assert.deepEqual(
@@ -3862,6 +3868,66 @@ test("admin login validates credentials", async () => {
assert.equal(response.statusCode, 401);
});
test("admin login does not auto-grant ownership to users without memberships", async () => {
const username = `no-membership-${Date.now()}`;
const user = await prisma.adminUser.create({
data: {
username,
passwordHash: await bcrypt.hash("initial-password-123", 12),
displayName: "未分配品牌管理员",
mustChangePassword: false,
},
});
try {
const login = await request("/admin/session/login", {
method: "POST",
payload: { username, password: "initial-password-123" },
});
assert.equal(login.statusCode, 403);
assert.equal(await prisma.brandMembership.count({ where: { adminUserId: user.id } }), 0);
} finally {
await prisma.adminUser.delete({ where: { id: user.id } });
}
});
test("changing an admin password revokes existing admin tokens", async () => {
const username = `token-version-${Date.now()}`;
const user = await prisma.adminUser.create({
data: {
username,
passwordHash: await bcrypt.hash("initial-password-123", 12),
displayName: "Token 版本管理员",
mustChangePassword: false,
memberships: {
create: { brandId, role: "admin", isEnabled: true },
},
},
});
try {
const login = await request("/admin/session/login", {
method: "POST",
payload: { username, password: "initial-password-123" },
});
assert.equal(login.statusCode, 201, login.body);
const token = JSON.parse(login.body).token;
const headers = { authorization: `Bearer ${token}` };
const before = await request("/admin/bookings/unread-count", { headers });
assert.equal(before.statusCode, 200, before.body);
const changed = await request("/admin/session/change-password", {
method: "POST",
headers,
payload: { currentPassword: "initial-password-123", newPassword: "changed-password-456" },
});
assert.equal(changed.statusCode, 201, changed.body);
const after = await request("/admin/bookings/unread-count", { headers });
assert.equal(after.statusCode, 401, after.body);
} finally {
await prisma.adminUser.delete({ where: { id: user.id } });
}
});
test("admin can list and switch only enabled brand memberships", async () => {
const login = await request("/admin/session/login", {
method: "POST",