锁定微信手机号授权取消提示
微信手机号授权取消不再向页面透出原生错误细节 微信认证测试覆盖手机号授权取消稳定提示 native shell 总门禁反查手机号授权取消边界
This commit is contained in:
@@ -26,6 +26,7 @@ const PAY_RESULT_RECHECK_DELAY_MS = 120;
|
||||
const WEB_VIEW_SHARE_TITLE = '陶泥儿';
|
||||
const WECHAT_LOGIN_UNAVAILABLE_MESSAGE = '微信登录失败,请稍后重试。';
|
||||
const WECHAT_BIND_PHONE_UNAVAILABLE_MESSAGE = '绑定手机号失败,请稍后重试。';
|
||||
const WECHAT_BIND_PHONE_AUTH_REQUIRED_MESSAGE = '需要授权手机号后才能完成绑定。';
|
||||
|
||||
function showWebViewShareMenu() {
|
||||
if (typeof wx.showShareMenu !== 'function') {
|
||||
@@ -593,8 +594,9 @@ function createWechatWebViewPage() {
|
||||
|
||||
const detail = event.detail || {};
|
||||
if (!detail.code) {
|
||||
console.error('[web-view] bind phone auth declined', detail);
|
||||
this.setData({
|
||||
errorMessage: detail.errMsg || '需要授权手机号后才能完成绑定。',
|
||||
errorMessage: WECHAT_BIND_PHONE_AUTH_REQUIRED_MESSAGE,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1955,11 +1955,14 @@ function assertWechatAuthFailureBoundaries() {
|
||||
for (const snippet of [
|
||||
"WECHAT_LOGIN_UNAVAILABLE_MESSAGE = '微信登录失败,请稍后重试。'",
|
||||
"WECHAT_BIND_PHONE_UNAVAILABLE_MESSAGE = '绑定手机号失败,请稍后重试。'",
|
||||
"WECHAT_BIND_PHONE_AUTH_REQUIRED_MESSAGE = '需要授权手机号后才能完成绑定。'",
|
||||
"console.error('[web-view] wx.login failed', error)",
|
||||
"console.error('[web-view] mini program login request failed', error)",
|
||||
"console.error('[web-view] mini program bind phone failed', response)",
|
||||
"console.error('[web-view] bind phone auth declined', detail)",
|
||||
'errorMessage: WECHAT_LOGIN_UNAVAILABLE_MESSAGE',
|
||||
'errorMessage: WECHAT_BIND_PHONE_UNAVAILABLE_MESSAGE',
|
||||
'errorMessage: WECHAT_BIND_PHONE_AUTH_REQUIRED_MESSAGE',
|
||||
]) {
|
||||
if (!webViewShellSource.includes(snippet)) {
|
||||
throw new Error(`wechat auth shell must include ${snippet}`);
|
||||
@@ -1970,6 +1973,7 @@ function assertWechatAuthFailureBoundaries() {
|
||||
"reject(new Error(error.errMsg || '微信登录请求失败'))",
|
||||
"reject(new Error(error.errMsg || '绑定手机号请求失败'))",
|
||||
"error && error.message ? error.message : '微信登录失败,请稍后重试。'",
|
||||
"detail.errMsg || '需要授权手机号后才能完成绑定。'",
|
||||
'response.data.error.message',
|
||||
]) {
|
||||
if (webViewShellSource.includes(forbiddenSnippet)) {
|
||||
@@ -1979,8 +1983,10 @@ function assertWechatAuthFailureBoundaries() {
|
||||
for (const snippet of [
|
||||
'微信登录失败不向页面透出原生错误',
|
||||
'绑定手机号失败不向页面透出后端错误体',
|
||||
'拒绝手机号授权不向页面透出微信原生错误',
|
||||
"expect(page.data.errorMessage).toBe('微信登录失败,请稍后重试。')",
|
||||
"expect(page.data.errorMessage).toBe('绑定手机号失败,请稍后重试。')",
|
||||
"expect(page.data.errorMessage).toBe('需要授权手机号后才能完成绑定。')",
|
||||
]) {
|
||||
if (!authTestSource.includes(snippet)) {
|
||||
throw new Error(`wechat auth boundary test must include ${snippet}`);
|
||||
|
||||
@@ -26,6 +26,9 @@ type MiniProgramPage = {
|
||||
onShareTimeline: () => Record<string, unknown>;
|
||||
onShow: () => void;
|
||||
consumePayResult: () => void;
|
||||
handleGetPhoneNumber: (event: {
|
||||
detail?: Record<string, unknown>;
|
||||
}) => Promise<void>;
|
||||
};
|
||||
|
||||
function createWxMock() {
|
||||
@@ -355,4 +358,27 @@ describe('mini-program web-view auth page', () => {
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
test('拒绝手机号授权不向页面透出微信原生错误', async () => {
|
||||
const wxMock = createWxMock();
|
||||
const page = loadWebViewPage(wxMock);
|
||||
page.data.authResult = {
|
||||
token: 'jwt-pending-wechat',
|
||||
bindingStatus: 'pending_bind_phone',
|
||||
};
|
||||
const authDeclined = {
|
||||
errMsg: 'getPhoneNumber:fail private native detail',
|
||||
};
|
||||
|
||||
await page.handleGetPhoneNumber({
|
||||
detail: authDeclined,
|
||||
});
|
||||
|
||||
expect(page.data.errorMessage).toBe('需要授权手机号后才能完成绑定。');
|
||||
expect(page.data.errorMessage).not.toContain('private native detail');
|
||||
expect(console.error).toHaveBeenCalledWith(
|
||||
'[web-view] bind phone auth declined',
|
||||
authDeclined,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user