收紧微信支付能力日志边界
微信虚拟支付不可用时只记录稳定标签 补充不可用路径日志脱敏测试 更新原生壳根门禁防止能力细节泄露
This commit is contained in:
@@ -96,10 +96,7 @@ function requestOrdinaryPayment(payParams) {
|
||||
function requestVirtualPayment(payParams) {
|
||||
return new Promise((resolve) => {
|
||||
if (!canUseVirtualPayment() || typeof wx.requestVirtualPayment !== 'function') {
|
||||
console.error('[wechat-pay] requestVirtualPayment unavailable', {
|
||||
canUseVirtualPayment: canUseVirtualPayment(),
|
||||
hasRequestVirtualPayment: typeof wx.requestVirtualPayment === 'function',
|
||||
});
|
||||
logWechatPayFailure('requestVirtualPayment unavailable');
|
||||
resolve({
|
||||
status: 'fail',
|
||||
errorMessage: '当前微信基础库不支持 requestVirtualPayment',
|
||||
|
||||
@@ -133,6 +133,32 @@ describe('wechat-pay mini program payment bridge', () => {
|
||||
expect(console.error.mock.calls.flat()).not.toContain(payError);
|
||||
});
|
||||
|
||||
test('logs virtual payment unavailable without exposing capability details', async () => {
|
||||
const { requestWechatPayment } = wechatPayBridge;
|
||||
globalThis.wx.canIUse = vi.fn(() => false);
|
||||
globalThis.wx.getSystemInfoSync = vi.fn(() => ({ SDKVersion: '2.18.0' }));
|
||||
delete globalThis.wx.requestVirtualPayment;
|
||||
|
||||
await expect(
|
||||
requestWechatPayment({
|
||||
mode: 'short_series_coin',
|
||||
signData: '{}',
|
||||
paySig: 'pay-sig',
|
||||
signature: 'user-sig',
|
||||
}),
|
||||
).resolves.toEqual({
|
||||
status: 'fail',
|
||||
errorMessage: '当前微信基础库不支持 requestVirtualPayment',
|
||||
});
|
||||
|
||||
expect(console.error).toHaveBeenCalledWith(
|
||||
'[wechat-pay] requestVirtualPayment unavailable',
|
||||
);
|
||||
expect(console.error.mock.calls).toContainEqual([
|
||||
'[wechat-pay] requestVirtualPayment unavailable',
|
||||
]);
|
||||
});
|
||||
|
||||
test('hides ordinary payment native failure details from H5 result', async () => {
|
||||
const { requestWechatPayment } = wechatPayBridge;
|
||||
globalThis.wx.requestPayment.mockImplementationOnce((options) => {
|
||||
|
||||
@@ -3446,6 +3446,7 @@ function assertWechatPaymentResultBoundaries() {
|
||||
'function logWechatPayFailure(label, _error)',
|
||||
'console.error(`[wechat-pay] ${label}`)',
|
||||
"logWechatPayFailure('parse params failed', error)",
|
||||
"logWechatPayFailure('requestVirtualPayment unavailable')",
|
||||
"logWechatPayFailure('requestVirtualPayment failed', error)",
|
||||
]) {
|
||||
if (!paymentSource.includes(snippet)) {
|
||||
@@ -3456,14 +3457,17 @@ function assertWechatPaymentResultBoundaries() {
|
||||
paymentSource.includes('JSON.stringify({\n errCode') ||
|
||||
paymentSource.includes('String(error.errMsg || error)') ||
|
||||
paymentSource.includes("console.error('[wechat-pay] parse params failed', error)") ||
|
||||
paymentSource.includes("console.error('[wechat-pay] requestVirtualPayment unavailable',") ||
|
||||
paymentSource.includes("console.error('[wechat-pay] requestVirtualPayment failed', error)")
|
||||
) {
|
||||
throw new Error('wechat payment bridge must not expose native payment errors to H5');
|
||||
}
|
||||
for (const snippet of [
|
||||
'maps virtual payment cancel errCode to cancel result',
|
||||
'logs virtual payment unavailable without exposing capability details',
|
||||
'hides ordinary payment native failure details from H5 result',
|
||||
"errorMessage: 'wechat payment unavailable'",
|
||||
"expect(console.error.mock.calls).toContainEqual([\n '[wechat-pay] requestVirtualPayment unavailable',",
|
||||
"expect(console.error).toHaveBeenCalledWith(\n '[wechat-pay] requestVirtualPayment failed'",
|
||||
'expect(console.error.mock.calls.flat()).not.toContain(payError)',
|
||||
]) {
|
||||
|
||||
Reference in New Issue
Block a user