wwAuth.test.cjs
3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
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')