锁定微信登录失败提示

微信登录和绑手机号失败不再向页面透出原生或后端错误细节

微信 web-view auth 测试覆盖登录失败和绑手机号失败稳定提示

native shell 总门禁反查微信 auth 失败边界
This commit is contained in:
2026-06-20 13:26:45 +08:00
parent c49bccc269
commit f641d2b25f
3 changed files with 119 additions and 24 deletions
+52
View File
@@ -113,6 +113,7 @@ function loadCommonJsModule(
describe('mini-program web-view auth page', () => {
beforeEach(() => {
vi.clearAllMocks();
vi.spyOn(console, 'error').mockImplementation(() => {});
});
test('默认进入时不预登录,直接打开未登录 web-view', async () => {
@@ -303,4 +304,55 @@ describe('mini-program web-view auth page', () => {
expect(page.data.loading).toBe(false);
expect(page.data.phoneBindingRequired).toBe(true);
});
test('微信登录失败不向页面透出原生错误', async () => {
const wxMock = createWxMock();
const loginError = { errMsg: 'login:fail private native detail' };
wxMock.login.mockImplementation(({ fail }) => {
fail(loginError);
});
const page = loadWebViewPage(wxMock);
await page.onLoad({ authAction: 'login', returnTo: 'previous' });
expect(page.data.errorMessage).toBe('微信登录失败,请稍后重试。');
expect(console.error).toHaveBeenCalledWith(
'[web-view] wx.login failed',
loginError,
);
expect(page.data.phoneBindingRequired).toBe(false);
});
test('绑定手机号失败不向页面透出后端错误体', async () => {
const wxMock = createWxMock();
const page = loadWebViewPage(wxMock);
page.data.authResult = {
token: 'jwt-pending-wechat',
bindingStatus: 'pending_bind_phone',
};
wxMock.request.mockImplementation(({ success }) => {
success({
statusCode: 500,
data: {
error: {
message: 'private backend detail',
},
},
});
});
await page.handleGetPhoneNumber({
detail: {
code: 'wechat-phone-code',
},
});
expect(page.data.errorMessage).toBe('绑定手机号失败,请稍后重试。');
expect(console.error).toHaveBeenCalledWith(
'[web-view] mini program bind phone failed',
expect.objectContaining({
statusCode: 500,
}),
);
});
});