Commit 787588f9 by 张立顺

fix(auth): 开发环境跳过美团报告授权

1 parent 1da2a209
......@@ -12,6 +12,7 @@ import { Http } from 'glsx-common'
import { Notify } from 'vant'
import { ssoApi } from '@/api'
import store from '@/store'
import { shouldRequireWwAuth } from './wwAuth'
const state = {
showWindow: false,
......@@ -21,9 +22,6 @@ const state = {
import router from '@/router'
const EVECTION_AUTH_PATHS = ['/department', '/personage', '/company']
const APPROVAL_AUTH_PATHS = ['/orderApproval', '/accountApproval']
function saveUrlParams() {
const { corpId, agentId, phone, name, id, orderCode, uuid } = util.getQuery()
if (phone) util.setLocalStorage('ww_params_phone', phone)
......@@ -40,12 +38,11 @@ function saveUrlParams() {
}
function needWwAuth(href) {
const pushId = util.getQuery('pushId')
const isEvectionPath = EVECTION_AUTH_PATHS.some(keyword => href.includes(keyword))
const isApprovalPath = APPROVAL_AUTH_PATHS.some(keyword => href.includes(keyword))
if (isEvectionPath && pushId && pushId * 1 > 744) return true
if (isApprovalPath) return true
return false
return shouldRequireWwAuth({
href,
hostname: window.location.hostname,
pushId: util.getQuery('pushId')
})
}
async function handleWwLogin({ commit }) {
......
const DEVELOPMENT_HOSTNAME = 'scrm.dev.glsx.com.cn'
const EVECTION_AUTH_PATHS = ['/evection/department', '/evection/personage', '/evection/company']
const APPROVAL_AUTH_PATHS = ['/orderapproval', '/accountapproval']
function getHashRoutePath(href) {
const hashIndex = href.indexOf('#')
if (hashIndex === -1) return ''
let routePath = href.slice(hashIndex + 1).split('?')[0].toLowerCase()
if (routePath && !routePath.startsWith('/')) routePath = `/${routePath}`
if (routePath.length > 1) routePath = routePath.replace(/\/+$/, '')
return routePath
}
function shouldRequireWwAuth({ href = '', hostname = '', pushId } = {}) {
const routePath = getHashRoutePath(href)
const isEvectionPath = EVECTION_AUTH_PATHS.includes(routePath)
const isApprovalPath = APPROVAL_AUTH_PATHS.includes(routePath)
if (isApprovalPath) return true
if (isEvectionPath && hostname === DEVELOPMENT_HOSTNAME) return false
if (isEvectionPath && pushId && pushId * 1 > 744) return true
return false
}
module.exports = {
shouldRequireWwAuth
}
const assert = require('assert')
let shouldRequireWwAuth
try {
const wwAuth = require('../src/store/modules/wwAuth')
shouldRequireWwAuth = wwAuth.shouldRequireWwAuth
} catch (error) {
if (error.code !== 'MODULE_NOT_FOUND' || !error.message.includes('wwAuth')) {
throw error
}
}
assert.strictEqual(
typeof shouldRequireWwAuth,
'function',
'wwAuth should expose an authorization decision function'
)
const companyHref = 'http://scrm.dev.glsx.com.cn/wx-notification/#/evection/company'
assert.strictEqual(
shouldRequireWwAuth({
href: companyHref,
hostname: 'scrm.dev.glsx.com.cn',
pushId: '745'
}),
false,
'Meituan reports on the development host should skip WeCom authorization'
)
for (const reportPath of ['personage', 'department', 'company']) {
assert.strictEqual(
shouldRequireWwAuth({
href: `http://scrm.dev.glsx.com.cn/wx-notification/#/evection/${reportPath}`,
hostname: 'scrm.dev.glsx.com.cn',
pushId: '999'
}),
false
)
}
for (const hostname of ['scrm.test.glsx.com.cn', 'scrm.glsx.com.cn']) {
assert.strictEqual(
shouldRequireWwAuth({
href: `https://${hostname}/wx-notification/#/evection/company`,
hostname,
pushId: '745'
}),
true,
`${hostname} should retain the existing authorization rule`
)
}
assert.strictEqual(
shouldRequireWwAuth({
href: 'http://scrm.dev.glsx.com.cn/wx-notification/#/orderApproval',
hostname: 'scrm.dev.glsx.com.cn'
}),
true,
'the development-host bypass should not apply to approval pages'
)
for (const approvalHref of [
'http://scrm.dev.glsx.com.cn/wx-notification/#/orderApproval?return=/company',
'http://scrm.dev.glsx.com.cn/wx-notification/#/accountApproval?from=/personage',
'http://scrm.dev.glsx.com.cn/wx-notification/#/orderApproval/',
'http://scrm.dev.glsx.com.cn/wx-notification/#/accountApproval///',
'http://scrm.dev.glsx.com.cn/wx-notification/#/OrderApproval'
]) {
assert.strictEqual(
shouldRequireWwAuth({
href: approvalHref,
hostname: 'scrm.dev.glsx.com.cn',
pushId: '999'
}),
true,
'approval pages must remain protected when query values contain report path names'
)
}
for (const reportHref of [
'https://scrm.test.glsx.com.cn/wx-notification/#/evection/company/',
'https://scrm.test.glsx.com.cn/wx-notification/#/EVECTION/COMPANY'
]) {
assert.strictEqual(
shouldRequireWwAuth({
href: reportHref,
hostname: 'scrm.test.glsx.com.cn',
pushId: '999'
}),
true,
'Router-equivalent report paths must retain authorization outside development'
)
}
for (const nonReportHref of [
'http://scrm.dev.glsx.com.cn/wx-notification/#/evection/company-preview',
'http://scrm.dev.glsx.com.cn/wx-notification/#/unrelated?next=/department'
]) {
assert.strictEqual(
shouldRequireWwAuth({
href: nonReportHref,
hostname: 'scrm.dev.glsx.com.cn',
pushId: '999'
}),
false,
'only exact Meituan report routes should participate in the report authorization rule'
)
}
assert.strictEqual(
shouldRequireWwAuth({
href: companyHref,
hostname: 'scrm.dev.glsx.com.cn.evil.example',
pushId: '745'
}),
true,
'the bypass must require an exact hostname match'
)
assert.strictEqual(
shouldRequireWwAuth({
href: 'https://scrm.test.glsx.com.cn/wx-notification/#/evection/company',
hostname: 'scrm.test.glsx.com.cn',
pushId: '624'
}),
false,
'legacy report links should keep the existing pushId compatibility behavior'
)
console.log('wwAuth tests passed')
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!