feat: 完成现有小程序接口的全部迁移至新后端

This commit is contained in:
R524809
2026-10-19 13:17:51 +08:00
parent 8827110f2f
commit d30cf25890
148 changed files with 13287 additions and 34 deletions
+57
View File
@@ -106,3 +106,60 @@ test('微信错误、畸形响应和网络失败映射为有限安全错误,
error.reason === 'AUTH_UPSTREAM_UNAVAILABLE',
);
});
test('微信白名单拒绝记录有限错误码和出口 IP,可按 requestId 排查且不泄漏原文', async () => {
const diagnostics: unknown[] = [];
const http = responding({
errcode: 40164,
errmsg: 'invalid ip 98.98.125.169, not in whitelist secret=private-secret',
session_key: 'private-session-key',
});
await assert.rejects(
new WechatClient(testConfig, http, (entry) =>
diagnostics.push(entry),
).exchangeCode('private-once-code', 'req_diagnostic'),
(error: unknown) =>
error instanceof ApiException &&
error.getStatus() === 503 &&
error.reason === 'AUTH_UPSTREAM_UNAVAILABLE',
);
assert.deepEqual(diagnostics, [
{
request_id: 'req_diagnostic',
failure_type: 'wechat_error',
http_status: 200,
wechat_errcode: 40164,
egress_ip: '98.98.125.169',
},
]);
const output = JSON.stringify(diagnostics);
for (const value of [
'private-secret',
'private-session-key',
'private-once-code',
testConfig.wechatMiniAppSecret,
])
assert.ok(!output.includes(value));
});
test('网络、HTTP 和响应解析诊断不携带原异常或微信响应', async () => {
const diagnostics: unknown[] = [];
for (const http of [
(async () => {
throw new Error('https://api.weixin.qq.com?secret=private-secret');
}) as WechatFetch,
responding({}, 502),
(async () => new Response('private-invalid-json')) as WechatFetch,
])
await assert.rejects(
new WechatClient(testConfig, http, (entry) =>
diagnostics.push(entry),
).exchangeCode('private-code'),
);
assert.deepEqual(diagnostics, [
{ request_id: undefined, failure_type: 'network' },
{ request_id: undefined, failure_type: 'http', http_status: 502 },
{ request_id: undefined, failure_type: 'json', http_status: 200 },
]);
assert.ok(!JSON.stringify(diagnostics).includes('private-'));
});