fix: 修复系统一致性与安全问题
This commit is contained in:
1 parent
aaeec14733
commit
f158f906d5
19 files changed
+194
-34
No files matched your search
@@ -164,6 +164,7 @@ test("miniapp release settings never expose or persist plaintext private keys",
|
||||
const brand = await prisma.brandProfile.findUniqueOrThrow({ where: { id: brandId } });
|
||||
const credential = brand.miniAppSettings?.credential;
|
||||
assert.ok(credential);
|
||||
assert.equal(brand.miniAppSettings.apiBaseUrl, "https://wechat.example.com/api");
|
||||
assert.equal(typeof credential.ciphertext, "string");
|
||||
assert.ok(!JSON.stringify(brand.miniAppSettings).includes(privateKey));
|
||||
const missing = await request("/admin/miniapp-releases/settings");
|
||||
@@ -1552,6 +1553,11 @@ test("manually created member must change the initial password before normal use
|
||||
});
|
||||
assert.equal(login.statusCode, 201);
|
||||
assert.equal(JSON.parse(login.body).mustChangePassword, true);
|
||||
const blocked = await request("/admin/brands/members", {
|
||||
headers: { authorization: `Bearer ${JSON.parse(login.body).token}` },
|
||||
});
|
||||
assert.equal(blocked.statusCode, 403);
|
||||
assert.match(errorMessage(blocked.body), /初始密码/);
|
||||
const changed = await request("/admin/session/change-password", {
|
||||
method: "POST",
|
||||
headers: { authorization: `Bearer ${JSON.parse(login.body).token}` },
|
||||
@@ -2388,6 +2394,12 @@ test("admin can create and version an inquiry form", async () => {
|
||||
{ label: "设计", value: "design" },
|
||||
],
|
||||
},
|
||||
{
|
||||
key: "wechat",
|
||||
type: "text",
|
||||
label: "微信号",
|
||||
visibleWhen: [{ field: "contact_method", operator: "equals", value: "wechat" }],
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
@@ -2443,6 +2455,10 @@ test("admin can create and version an inquiry form", async () => {
|
||||
const publicOffering = await request(`/public/offerings/${offering.id}`);
|
||||
assert.equal(publicOffering.statusCode, 200);
|
||||
assert.equal(JSON.parse(publicOffering.body).inquiryForms[0].id, id);
|
||||
assert.equal(
|
||||
(await request("/public/offerings/00000000-0000-0000-0000-000000000000")).statusCode,
|
||||
404,
|
||||
);
|
||||
const publicWorkspace = await request("/public/workspace");
|
||||
assert.equal(publicWorkspace.statusCode, 200);
|
||||
const runtimeForm = JSON.parse(publicWorkspace.body).inquiryForms.find(
|
||||
@@ -2456,6 +2472,9 @@ test("admin can create and version an inquiry form", async () => {
|
||||
),
|
||||
);
|
||||
assert.deepEqual(runtimeForm.fields[1].options, [{ label: "微信", value: "wechat" }]);
|
||||
assert.deepEqual(runtimeForm.fields[3].visibleWhen, [
|
||||
{ field: "contact_method", operator: "equals", value: "wechat" },
|
||||
]);
|
||||
await prisma.inquiryForm.update({
|
||||
where: { id },
|
||||
data: {
|
||||
@@ -2466,13 +2485,25 @@ test("admin can create and version an inquiry form", async () => {
|
||||
const submission = await request("/customer/inquiry-submissions", {
|
||||
method: "POST",
|
||||
headers: { authorization: `Bearer ${customerToken}` },
|
||||
payload: { formId: id, values: { budget: 1000, ignored: "not persisted" } },
|
||||
payload: {
|
||||
formId: id,
|
||||
values: {
|
||||
budget: 1000,
|
||||
contact_method: "wechat",
|
||||
ignored: "not persisted",
|
||||
wechat: "brand-wechat",
|
||||
},
|
||||
},
|
||||
});
|
||||
assert.equal(submission.statusCode, 201);
|
||||
assert.equal(JSON.parse(submission.body).formVersion, 2);
|
||||
assert.equal(JSON.parse(submission.body).fieldsSnapshot[0].key, "budget");
|
||||
assert.equal(JSON.parse(submission.body).offeringId, offering.id);
|
||||
assert.deepEqual(JSON.parse(submission.body).values, { budget: 1000 });
|
||||
assert.deepEqual(JSON.parse(submission.body).values, {
|
||||
budget: 1000,
|
||||
contact_method: "wechat",
|
||||
wechat: "brand-wechat",
|
||||
});
|
||||
assert.equal((await request("/customer/inquiry-submissions")).statusCode, 401);
|
||||
const adminCannotListCustomerSubmissions = await request("/customer/inquiry-submissions", {
|
||||
headers: { authorization: `Bearer ${token}` },
|
||||
@@ -2760,7 +2791,7 @@ test("admin can manage offerings and public endpoint hides disabled offerings",
|
||||
assert.equal(previewOffering?.presentation?.categoryKey, "set-meal");
|
||||
assert.equal(previewOffering?.presentation?.categoryLabel, "套餐");
|
||||
const publicItem = await request(`/public/offerings/${id}`);
|
||||
assert.equal(publicItem.statusCode, 400);
|
||||
assert.equal(publicItem.statusCode, 404);
|
||||
const publicList = await request("/public/offerings");
|
||||
assert.equal(publicList.statusCode, 200);
|
||||
assert.ok(!JSON.parse(publicList.body).some((item) => item.id === id));
|
||||
@@ -2771,14 +2802,14 @@ test("admin can manage offerings and public endpoint hides disabled offerings",
|
||||
});
|
||||
assert.equal(updated.statusCode, 200);
|
||||
const hidden = await request(`/public/offerings/${id}`);
|
||||
assert.equal(hidden.statusCode, 400);
|
||||
assert.equal(hidden.statusCode, 404);
|
||||
const reenabled = await request(`/admin/workspace/offerings/${id}`, {
|
||||
method: "PATCH",
|
||||
headers: { authorization: `Bearer ${token}` },
|
||||
payload: { isEnabled: true },
|
||||
});
|
||||
assert.equal(reenabled.statusCode, 200);
|
||||
assert.equal((await request(`/public/offerings/${id}`)).statusCode, 400);
|
||||
assert.equal((await request(`/public/offerings/${id}`)).statusCode, 404);
|
||||
} finally {
|
||||
const deleted = await request(`/admin/workspace/offerings/${id}`, {
|
||||
method: "DELETE",
|
||||
|
||||
@@ -39,7 +39,7 @@ test("local upload presign targets the API route and requires brand access", asy
|
||||
{},
|
||||
{ fileName: "portrait.jpg", contentType: "image/jpeg" },
|
||||
);
|
||||
assert.match(result.uploadUrl, /^\/api\/admin\/uploads\/local\?key=\d{4}%2F[a-f0-9]{16}\.jpg$/);
|
||||
assert.match(result.uploadUrl, /^\/admin\/uploads\/local\?key=\d{4}%2F[a-f0-9]{16}\.jpg$/);
|
||||
assert.equal(result.mode, "local");
|
||||
} finally {
|
||||
for (const [name, value] of [
|
||||
|
||||
@@ -46,6 +46,10 @@ async function main() {
|
||||
initialReleases,
|
||||
"Repeated seed must preserve release history and snapshots",
|
||||
);
|
||||
await fixtureDatabase.adminUser.updateMany({
|
||||
where: { username: "admin" },
|
||||
data: { mustChangePassword: false },
|
||||
});
|
||||
console.log("Seed idempotency verified: content, forms and release history preserved");
|
||||
status = run(process.execPath, ["--test", "test/http.integration.test.js"]);
|
||||
return status;
|
||||
|
||||
Reference in new issue
Block a user