- 新增 SECURE_MODE(仅 ALLOW_INSECURE_DEV_AUTH=1 时放开):后台登录口令、上传、内容检测、核销码归属全部改为默认收紧,修复线上以 NODE_ENV=development 运行时闸门失效 - 提现审核:未开通真实转账且未显式 ALLOW_SANDBOX_PAY=1 时一律 503,杜绝只改状态不打款 - 预支付:未开启沙箱时不再下发沙箱参数;小程序删除预支付失败伪造沙箱成功的兜底,改为抛错 - 订阅消息支持 MINIPROGRAM_STATE=formal|trial|developer 显式配置,避免真实用户收不到通知 - 动态列表/点赞身份统一 normalizeUserId;文档补充安全闸门与订阅消息环境变量 - 109 套件/720 用例全绿,tsc 构建通过
75 行
3.3 KiB
TypeScript
75 行
3.3 KiB
TypeScript
// 已读取AGENTS.md
|
|
import * as fs from 'fs';
|
|
import * as path from 'path';
|
|
|
|
/**
|
|
* 第七批回归闸门:评价回复归属 / 服务上下架归属 / 通用核销归属
|
|
* 以「源码契约断言」锁定安全边界。
|
|
*/
|
|
describe('第七批安全加固闸门 (评价回复 / 服务上下架 / 通用核销归属)', () => {
|
|
const rootDir = path.resolve(__dirname, '../../');
|
|
const serverRepoPath = path.join(rootDir, 'server/src/db/repository.ts');
|
|
const serverIndexPath = path.join(rootDir, 'server/src/index.ts');
|
|
const apiPath = path.join(rootDir, 'pwuniapp/common/api.js');
|
|
|
|
const indexCode = fs.readFileSync(serverIndexPath, 'utf-8');
|
|
const repoCode = fs.readFileSync(serverRepoPath, 'utf-8');
|
|
const apiCode = fs.readFileSync(apiPath, 'utf-8');
|
|
|
|
const routeBlock = (marker: string, len = 1400) => {
|
|
const start = indexCode.indexOf(marker);
|
|
expect(start).toBeGreaterThan(-1);
|
|
return indexCode.slice(start, start + len);
|
|
};
|
|
|
|
describe('1. 评价回复越权', () => {
|
|
it('仓储层必须提供 getReviewOwnership (基于 order_reviews.expert_id)', () => {
|
|
expect(repoCode).toContain('async getReviewOwnership(');
|
|
const start = repoCode.indexOf('async getReviewOwnership(');
|
|
const block = repoCode.slice(start, start + 400);
|
|
expect(block).toContain('SELECT expert_id FROM order_reviews');
|
|
expect(block).toContain('getCompanionOwnership');
|
|
});
|
|
|
|
it('回复路由必须校验归属', () => {
|
|
const block = routeBlock("app.post('/api/reviews/:id/reply'");
|
|
expect(block).toContain('repo.getReviewOwnership(reviewId)');
|
|
expect(block).toContain("assertCompanionActor(req, own, '回复评价')");
|
|
});
|
|
});
|
|
|
|
describe('2. 服务上下架越权', () => {
|
|
it('仓储层必须提供 getExpertServiceOwnership (基于 expert_services.expert_id)', () => {
|
|
expect(repoCode).toContain('async getExpertServiceOwnership(');
|
|
const start = repoCode.indexOf('async getExpertServiceOwnership(');
|
|
const block = repoCode.slice(start, start + 800);
|
|
expect(block).toContain('SELECT expert_id FROM expert_services');
|
|
expect(block).toContain('getCompanionOwnership');
|
|
});
|
|
|
|
it('上下架路由必须校验归属', () => {
|
|
const block = routeBlock("app.put('/api/companions/:id/services/:serviceId/status'");
|
|
expect(block).toContain('repo.getExpertServiceOwnership(serviceId)');
|
|
expect(block).toContain("assertCompanionActor(req, own, '调整服务上下架')");
|
|
});
|
|
});
|
|
|
|
describe('3. 通用核销归属 (生产闸门)', () => {
|
|
it('生产环境必须校验核销人:活动=发起人,订单=承接大神', () => {
|
|
const block = routeBlock("app.post('/api/verify/universal'");
|
|
expect(block).toContain('SECURE_MODE && !isVerifiedAdminRequest(req)');
|
|
expect(block).toContain("info.type === 'ACTIVITY'");
|
|
expect(block).toContain('Number(info.creatorId) === operator');
|
|
expect(block).toContain('own!.companionIds.includes(operator)');
|
|
expect(block).toContain('无权核销该门票');
|
|
});
|
|
});
|
|
|
|
describe('4. 小程序端写接口携带真实身份', () => {
|
|
it('回复评价/切换服务状态必须携带当前用户身份', () => {
|
|
expect(apiCode).toContain('{ replyContent, userId: normalizeUserId() }');
|
|
expect(apiCode).toContain('{ status, userId: normalizeUserId() }');
|
|
});
|
|
});
|
|
});
|