1 parent
d2f14ede7a
commit
cfe4401b70
32 files changed
+893
-318
No files matched your search
@@ -22,7 +22,7 @@ test('基础配置不再展示冗余安全选项与开关,通行密钥由系
|
||||
assert.equal(updated.security.webAuthnRpId, 'mail.old.com')
|
||||
})
|
||||
|
||||
test('七个页面使用分组表单,控件和样式能编译且不再提供 JSON 编辑器', () => {
|
||||
test('配置与安全策略页面使用分组表单,控件和样式能编译且不再提供 JSON 编辑器', () => {
|
||||
const require = createRequire(new URL('../../frontend/package.json', import.meta.url))
|
||||
const { parse, compileScript, compileStyle } = require('@vue/compiler-sfc')
|
||||
for (const name of ['ConfigForm', 'ConfigField', 'ConfigEditor']) {
|
||||
@@ -34,8 +34,13 @@ test('七个页面使用分组表单,控件和样式能编译且不再提供 J
|
||||
assert.deepEqual(compileStyle({ source: css, id: `data-v-${name}`, scoped: true }).errors, [])
|
||||
assert.doesNotMatch(template, /&#x[0-9a-f]+;|type="textarea"|配置 JSON 编辑器/i)
|
||||
}
|
||||
for (const section of ['base', 'smtp', 'imap', 'pop3', 'email', 'ssl', 'plugins']) {
|
||||
const groups = getFieldGroups(section, { plugins: { spam_block: { settings: null } } })
|
||||
const config = { plugins: {
|
||||
spam_block: { settings: null },
|
||||
telegram_push: { settings: null },
|
||||
wechat_push: { settings: null }
|
||||
} }
|
||||
for (const section of ['base', 'mail', 'security_policy', 'ssl', 'plugins', 'spam_block', 'telegram_push', 'wechat_push']) {
|
||||
const groups = getFieldGroups(section, config)
|
||||
assert.ok(groups.length)
|
||||
const keys = groups.flatMap(group => group.fields.map(field => field.path.join('.')))
|
||||
assert.equal(keys.length, new Set(keys).size)
|
||||
@@ -44,17 +49,26 @@ test('七个页面使用分组表单,控件和样式能编译且不再提供 J
|
||||
}
|
||||
})
|
||||
|
||||
test('各协议仅编辑自己的监听端口,邮箱策略没有重复端口输入项', () => {
|
||||
test('邮件服务页面统一编辑六个监听端口,中继和策略字段保持在同一配置分区', () => {
|
||||
const config = { listener: { port: 25, starttlsPort: 587, tlsPort: 465 }, relay: { relayPort: 465 }, imap: { tlsPort: 993 }, pop3: { port: 110, tlsPort: 995 }, policy: { smtpPort: 25, imapPort: 143, pop3Port: 110 } }
|
||||
const text = JSON.stringify(config)
|
||||
assert.equal(updateFormConfig(text, 'email', ['policy', 'smtpPort'], 2525), text)
|
||||
assert.equal(updateFormConfig(text, 'imap', ['pop3', 'port'], 1110), text)
|
||||
assert.equal(updateFormConfig(text, 'pop3', ['imap', 'tlsPort'], 1993), text)
|
||||
const edited = readFormConfig(updateFormConfig(text, 'smtp', ['listener', 'tlsPort'], 2465))
|
||||
const groups = getFieldGroups('mail', config)
|
||||
const keys = groups.flatMap(group => group.fields.map(input => input.path.join('.')))
|
||||
assert.deepEqual(keys.filter(key => /^(listener|imap|pop3)\./.test(key)), [
|
||||
'listener.port', 'listener.starttlsPort', 'listener.tlsPort',
|
||||
'imap.tlsPort', 'pop3.port', 'pop3.tlsPort'
|
||||
])
|
||||
assert.ok(keys.includes('relay.relayHost'))
|
||||
assert.ok(keys.includes('relay.password'))
|
||||
assert.ok(keys.includes('policy.maxMessageBytes'))
|
||||
assert.ok(keys.includes('policy.spamFilterLevel'))
|
||||
assert.ok(!keys.includes('policy.smtpPort'))
|
||||
assert.ok(!keys.includes('policy.imapPort'))
|
||||
assert.ok(!keys.includes('policy.pop3Port'))
|
||||
const edited = readFormConfig(updateFormConfig(text, 'mail', ['listener', 'tlsPort'], 2465))
|
||||
assert.equal(edited.listener.tlsPort, 2465)
|
||||
assert.equal(edited.relay.relayPort, 465)
|
||||
assert.deepEqual(getFieldGroups('email', config).flatMap(group => group.fields).filter(field => /port/i.test(field.path.join('.'))), [])
|
||||
assert.ok(validateFormConfig('smtp', { ...config, listener: { ...config.listener, tlsPort: 587 } })['listener.tlsPort'])
|
||||
assert.ok(validateFormConfig('mail', { ...config, listener: { ...config.listener, tlsPort: 587 } })['listener.tlsPort'])
|
||||
})
|
||||
|
||||
test('三个插件页面只展示和编辑自身字段,完整保留其他插件和未知字段', () => {
|
||||
@@ -119,22 +133,22 @@ test('文本输入的左右留白属于原生输入框,不影响数字、选
|
||||
assert.deepEqual(rules.get('.field-text-input[data-v-caret-test] .el-input__inner'), { 'padding-inline': '11px' })
|
||||
})
|
||||
|
||||
test('分组不显示重复标题和介绍,保留无障碍名称、凭据状态及异常提示', () => {
|
||||
test('分组只显示必要标题和字段错误,删除普通介绍、备注和凭据状态', () => {
|
||||
const template = readFileSync(new URL('ConfigForm/ConfigForm.vue', root), 'utf8')
|
||||
const css = readFileSync(new URL('ConfigForm/ConfigForm.css', root), 'utf8')
|
||||
assert.match(template, /<h4>{{ group.title }}<\/h4>/)
|
||||
assert.match(template, /form-group-heading|form-group-description|group\.description/)
|
||||
assert.match(template, /form-group-heading/)
|
||||
assert.doesNotMatch(template, /form-group-description|group\.description/)
|
||||
assert.doesNotMatch(template, /aria-labelledby/)
|
||||
assert.match(template, /<section\b[^>]*:aria-label="group.title"/)
|
||||
assert.match(template, /v-if="group.secretConfigured !== undefined" class="credential-status"/)
|
||||
assert.match(template, /group.secretConfigured \? '凭据已配置' : '未配置凭据'/)
|
||||
assert.match(template, /v-if="group.note" class="form-group-note" role="note"/)
|
||||
assert.doesNotMatch(template, /credential-status|secretConfigured|form-group-note|group\.note/)
|
||||
assert.match(template, /v-if="!groups.length" class="form-empty"/)
|
||||
assert.match(template, /<ConfigField\b/)
|
||||
for (const binding of ['v-for="field in group.fields"', ':value="getValue(config, field.path)"', ':error="errors[fieldKey(field)]"', ':disabled="disabled"', "emit('change', path, value)"]) {
|
||||
assert.ok(template.includes(binding))
|
||||
}
|
||||
assert.match(css, /form-group-heading|form-group-description/)
|
||||
assert.match(css, /form-group-heading/)
|
||||
assert.doesNotMatch(css, /form-group-description|credential-status|form-group-note/)
|
||||
const formStyle = css.match(/\.config-form\s*\{([^}]+)\}/)?.[1] || ''
|
||||
assert.doesNotMatch(formStyle, /margin-top|padding-top/)
|
||||
assert.match(css, /\.config-form:not\(:first-child\)\s*\{\s*margin-top: 10px;/)
|
||||
@@ -211,10 +225,13 @@ test('开关、数字、空数字和列表保持真实类型,代理 HTTPS 正
|
||||
assert.equal(readFormConfig(text).http.port, null)
|
||||
assert.ok(validateFormConfig('base', readFormConfig(text))['http.port'])
|
||||
for (const value of ['25', 0, -1, 65536, 1.5, null]) {
|
||||
assert.ok(validateFormConfig('imap', { imap: { tlsPort: value } })['imap.tlsPort'])
|
||||
assert.ok(validateFormConfig('mail', { imap: { tlsPort: value } })['imap.tlsPort'])
|
||||
}
|
||||
assert.ok(validateFormConfig('pop3', { imap: { tlsPort: 993 }, pop3: { port: 993, tlsPort: 995 } })['pop3.port'])
|
||||
assert.deepEqual(validateFormConfig('email', { policy: { smtpPort: 25, imapPort: 143, pop3Port: 110 } }), {})
|
||||
assert.ok(validateFormConfig('mail', { imap: { tlsPort: 993 }, pop3: { port: 993, tlsPort: 995 } })['pop3.port'])
|
||||
assert.deepEqual(validateFormConfig('mail', {
|
||||
listener: { port: 25, starttlsPort: 587, tlsPort: 465 },
|
||||
imap: { tlsPort: 993 }, pop3: { port: 110, tlsPort: 995 }, policy: { maxMessageBytes: 0 }
|
||||
}), {})
|
||||
})
|
||||
|
||||
test('域名校验兼容大小写和末尾点,拒绝重复项、空白和路径', () => {
|
||||
@@ -268,25 +285,25 @@ test('SMTP 加密方式自动匹配端口,手动端口和读取过程不改变
|
||||
for (const [security, expectedPort] of [['starttls', 587], ['implicit_tls', 465], ['tls', 465], ['plain', 25]]) {
|
||||
const config = { generation: 9, relay: { relayHost: 'localhost', relayPort: 2525, future: true } }
|
||||
let text = JSON.stringify(config)
|
||||
getFieldGroups('smtp', config)
|
||||
getFieldGroups('mail', config)
|
||||
assert.equal(JSON.stringify(config), text)
|
||||
text = updateFormConfig(text, 'smtp', ['relay', 'security'], security)
|
||||
text = updateFormConfig(text, 'mail', ['relay', 'security'], security)
|
||||
assert.deepEqual(readFormConfig(text), { ...config, relay: { ...config.relay, security, relayPort: expectedPort } })
|
||||
const fields = getFieldGroups('smtp', readFormConfig(text)).flatMap(group => group.fields)
|
||||
const fields = getFieldGroups('mail', readFormConfig(text)).flatMap(group => group.fields)
|
||||
assert.equal(fields.find(field => field.path.at(-1) === 'relayPort').recommendedPort, expectedPort)
|
||||
text = updateFormConfig(text, 'smtp', ['relay', 'relayPort'], 2526)
|
||||
text = updateFormConfig(text, 'mail', ['relay', 'relayPort'], 2526)
|
||||
assert.equal(readFormConfig(text).relay.security, security)
|
||||
text = updateFormConfig(text, 'smtp', ['relay', 'security'], security)
|
||||
text = updateFormConfig(text, 'mail', ['relay', 'security'], security)
|
||||
assert.equal(readFormConfig(text).relay.relayPort, 2526)
|
||||
}
|
||||
const fields = getFieldGroups('smtp', {}).flatMap(group => group.fields)
|
||||
const fields = getFieldGroups('mail', {}).flatMap(group => group.fields)
|
||||
assert.ok(fields.findIndex(field => field.path.at(-1) === 'security') < fields.findIndex(field => field.path.at(-1) === 'relayPort'))
|
||||
const unused = JSON.stringify({ relay: { relayPort: 2525, security: 'starttls' } })
|
||||
assert.equal(readFormConfig(updateFormConfig(unused, 'smtp', ['relay', 'security'], '')).relay.relayPort, 2525)
|
||||
assert.equal(readFormConfig(updateFormConfig(unused, 'mail', ['relay', 'security'], '')).relay.relayPort, 2525)
|
||||
for (const security of ['constructor', '__proto__', 'future']) {
|
||||
const updated = readFormConfig(updateFormConfig(unused, 'smtp', ['relay', 'security'], security))
|
||||
const updated = readFormConfig(updateFormConfig(unused, 'mail', ['relay', 'security'], security))
|
||||
assert.equal(updated.relay.relayPort, 2525)
|
||||
const fields = getFieldGroups('smtp', updated).flatMap(group => group.fields)
|
||||
const fields = getFieldGroups('mail', updated).flatMap(group => group.fields)
|
||||
assert.equal(fields.find(field => field.path.at(-1) === 'relayPort').recommendedPort, undefined)
|
||||
}
|
||||
})
|
||||
@@ -311,17 +328,22 @@ test('内置 HTTPS 自动补全端口,反代禁用内置监听,已有自定
|
||||
})
|
||||
|
||||
test('加密配置校验拦截监听冲突、远程明文和已启用但未选择加密的中继', () => {
|
||||
const listeners = {
|
||||
listener: { port: 25, starttlsPort: 587, tlsPort: 465 },
|
||||
imap: { tlsPort: 993 },
|
||||
pop3: { port: 110, tlsPort: 995 }
|
||||
}
|
||||
for (const port of [80, 0]) {
|
||||
assert.ok(validateFormConfig('base', { http: { port, httpsEnabled: true, httpsPort: 80 } })['http.httpsPort'])
|
||||
}
|
||||
for (const relayHost of ['localhost', 'LOCALHOST', '127.0.0.1', '127.1.2.3', '::1', '0:0:0:0:0:0:0:1']) {
|
||||
assert.deepEqual(validateFormConfig('smtp', { relay: { relayHost, security: 'plain', relayPort: 25 } }), {})
|
||||
assert.deepEqual(validateFormConfig('mail', { ...listeners, relay: { relayHost, security: 'plain', relayPort: 25, from: 'local@example.com', fromDomain: 'example.com' } }), {})
|
||||
}
|
||||
for (const relayHost of ['smtp.example.com', '127.0.0.999', '127.1', '127.0.0.1.evil.com', '192.168.1.1']) {
|
||||
assert.ok(validateFormConfig('smtp', { relay: { relayHost, security: 'plain', relayPort: 25 } })['relay.relayHost'])
|
||||
assert.ok(validateFormConfig('mail', { ...listeners, relay: { relayHost, security: 'plain', relayPort: 25, from: 'sender@example.com', fromDomain: 'example.com' } })['relay.relayHost'])
|
||||
}
|
||||
const errors = validateFormConfig('smtp', { relay: { relayHost: 'smtp.example.com', security: 'starttls', relayPort: 0 } })
|
||||
const errors = validateFormConfig('mail', { ...listeners, relay: { relayHost: 'smtp.example.com', security: 'starttls', relayPort: 0, from: 'sender@example.com', fromDomain: 'example.com' } })
|
||||
assert.ok(errors['relay.relayPort'])
|
||||
assert.deepEqual(validateFormConfig('smtp', { relay: {} }), {})
|
||||
assert.deepEqual(validateFormConfig('smtp', { relay: { security: 'starttls', relayPort: 2525, relayHost: 'smtp.example.com' } }), {})
|
||||
assert.deepEqual(validateFormConfig('mail', { ...listeners, relay: {} }), {})
|
||||
assert.deepEqual(validateFormConfig('mail', { ...listeners, relay: { security: 'starttls', relayPort: 2525, relayHost: 'smtp.example.com', from: 'sender@example.com', fromDomain: 'example.com' } }), {})
|
||||
})
|
||||
@@ -5,7 +5,7 @@ import { compileFunction } from 'node:vm'
|
||||
import { computed, reactive, ref } from './vue.mjs'
|
||||
|
||||
const source = readFileSync(new URL('../../frontend/src/views/components/ConfigSettings/ConfigNavigation.js', import.meta.url), 'utf8')
|
||||
const components = ['BaseConfig', 'SmtpConfig', 'ImapConfig', 'Pop3Config', 'EmailConfig', 'SslConfig', 'PluginsConfig', 'ConfigMaintenance']
|
||||
const components = ['BaseConfig', 'EmailConfig', 'SslConfig', 'PluginsConfig', 'ConfigMaintenance']
|
||||
const createNavigation = compileFunction(
|
||||
source.replace(/^import .*$/gm, '').replace('export function useNavigation', 'function useNavigation') + '\nreturn useNavigation()',
|
||||
['computed', 'nextTick', 'ref', 'useGlobalStatusStore', ...components]
|
||||
@@ -20,8 +20,8 @@ function fixture(capabilities = ['config.read']) {
|
||||
|
||||
test('配置菜单包含三个独立插件三级页面,无权限的维护入口不可打开', async () => {
|
||||
const { page, allowed } = fixture()
|
||||
assert.equal(new Set(page.sectionOptions.value.map(item => item.component)).size, 7)
|
||||
assert.deepEqual(page.sectionOptions.value.map(item => item.value), ['base', 'smtp', 'imap', 'pop3', 'email', 'ssl', 'plugins'])
|
||||
assert.equal(new Set(page.sectionOptions.value.map(item => item.component)).size, 4)
|
||||
assert.deepEqual(page.sectionOptions.value.map(item => item.value), ['base', 'mail', 'ssl', 'plugins'])
|
||||
const children = page.sectionOptions.value.find(item => item.value === 'plugins').children
|
||||
assert.deepEqual(children.map(item => item.value), ['spam_block', 'telegram_push', 'wechat_push'])
|
||||
await page.selectSection('plugins')
|
||||
@@ -61,17 +61,17 @@ test('切页等待离开确认,取消和快速重复点击不会更改页面',
|
||||
let resolve
|
||||
let prompts = 0
|
||||
page.currentPage.value = { beforeLeave: () => { prompts++; return new Promise(done => { resolve = done }) } }
|
||||
const first = page.selectSection('smtp')
|
||||
const first = page.selectSection('mail')
|
||||
await page.selectSection('ssl')
|
||||
assert.equal(prompts, 1)
|
||||
assert.equal(page.selectedSection.value, 'base')
|
||||
resolve(false)
|
||||
await first
|
||||
assert.equal(page.selectedSection.value, 'base')
|
||||
const second = page.selectSection('email')
|
||||
const second = page.selectSection('mail')
|
||||
resolve(true)
|
||||
await second
|
||||
assert.equal(page.selectedSection.value, 'email')
|
||||
assert.equal(page.selectedSection.value, 'mail')
|
||||
assert.equal(page.activePage.value.component.name, 'EmailConfig')
|
||||
})
|
||||
|
||||
|
||||
@@ -45,8 +45,7 @@ test('证书页从状态接口读取生效反代模式,不额外加载基础
|
||||
assert.equal(page.status.tlsMode, 'proxy')
|
||||
assert.deepEqual(requests, ['/api/v1/config/status', '/api/v1/config/ssl'])
|
||||
const template = readFileSync(new URL('../../frontend/src/views/components/ConfigSettings/ConfigEditor/ConfigEditor.vue', import.meta.url), 'utf8')
|
||||
assert.match(template, /v-if="selectedSection === 'ssl' && status.tlsMode === 'proxy'"/)
|
||||
assert.match(template, /Smail 不自动申请或续期 SSL 证书/)
|
||||
assert.doesNotMatch(template, /selectedSection === 'ssl' && status\.tlsMode === 'proxy'|Smail 不自动申请或续期 SSL 证书/)
|
||||
})
|
||||
|
||||
for (const failedRequest of ['/status', '/pending']) {
|
||||
@@ -54,14 +53,22 @@ for (const failedRequest of ['/status', '/pending']) {
|
||||
let pending = null
|
||||
let fail = false
|
||||
let saves = 0
|
||||
const { page } = fixture(() => {}, 'smtp', { http: {
|
||||
const active = {
|
||||
listener: { port: 25, starttlsPort: 587, tlsPort: 465 },
|
||||
relay: {
|
||||
relayHost: 'old.example.com', relayPort: 587, security: 'starttls',
|
||||
from: 'sender@example.com', fromDomain: 'example.com'
|
||||
},
|
||||
imap: { tlsPort: 993 }, pop3: { port: 110, tlsPort: 995 }, policy: {}
|
||||
}
|
||||
const { page } = fixture(() => {}, 'mail', { http: {
|
||||
get: async path => {
|
||||
if (fail && path.endsWith(failedRequest)) throw new Error('模拟读取失败')
|
||||
return { errorNo: 0, data: path.endsWith('/pending') ? pending : path.endsWith('/status') ? { activeGeneration: 1 } : { relay: { relayHost: 'old.example.com' } } }
|
||||
return { errorNo: 0, data: path.endsWith('/pending') ? pending : path.endsWith('/status') ? { activeGeneration: 1 } : active }
|
||||
},
|
||||
put: async (path, body) => {
|
||||
saves++
|
||||
pending = { generation: 2, candidateId: 'pending-recovery', section: 'smtp', sameSession: true, payload: body.payload }
|
||||
pending = { generation: 2, candidateId: 'pending-recovery', section: 'mail', sameSession: true, payload: body.payload }
|
||||
fail = true
|
||||
return { errorNo: 0, data: pending }
|
||||
},
|
||||
@@ -173,7 +180,7 @@ test('状态请求失败后可重试恢复,不保留不可用提示', async ()
|
||||
assert.equal(page.availabilityError.value, '')
|
||||
})
|
||||
|
||||
test('独立页互不覆盖,旧页卸载时清除密码并丢弃较慢响应', async () => {
|
||||
test('独立页互不覆盖,页面卸载时清除密码并丢弃较慢响应', async () => {
|
||||
const base = deferred()
|
||||
const email = deferred()
|
||||
const { page, dispose } = fixture(() => base.promise)
|
||||
@@ -188,11 +195,11 @@ test('独立页互不覆盖,旧页卸载时清除密码并丢弃较慢响应',
|
||||
page.secretValue.value = 'test-only-value'
|
||||
dispose()
|
||||
assert.equal(page.secretValue.value, '')
|
||||
const emailPage = fixture(() => email.promise, 'email').page
|
||||
const emailPage = fixture(() => email.promise, 'mail').page
|
||||
const emailRequest = emailPage.loadSection()
|
||||
email.resolve({ errorNo: 0, data: { policy: { smtpPort: 25 } } })
|
||||
await emailRequest
|
||||
assert.equal(emailPage.currentSection.value.label, '邮箱策略')
|
||||
assert.equal(emailPage.currentSection.value.label, '邮件服务与策略')
|
||||
assert.equal(emailPage.sectionLoading.value, false)
|
||||
base.resolve({ errorNo: 0, data: { database: { type: 'sqlite' } } })
|
||||
await baseRequest
|
||||
@@ -219,34 +226,39 @@ test('同一页重复加载时,过期失败不覆盖最新请求', async () =>
|
||||
assert.deepEqual(JSON.parse(page.editorText.value), { enabled: true })
|
||||
})
|
||||
|
||||
test('七个配置页按需加载,协议页复用正确分区且提供中文说明', async () => {
|
||||
test('配置页按需加载,邮件页和安全策略页共用 mail 分区', async () => {
|
||||
const requests = []
|
||||
for (const key of ['base', 'smtp', 'imap', 'pop3', 'email', 'ssl', 'plugins']) {
|
||||
for (const key of ['base', 'mail', 'security_policy', 'ssl', 'plugins']) {
|
||||
const { page } = fixture(async path => { requests.push(path); return { errorNo: 0, data: {} } }, key)
|
||||
await page.loadAll()
|
||||
assert.equal(page.selectedSection.value, key)
|
||||
assert.match(page.currentSection.value.description, /[\u4e00-\u9fff]/)
|
||||
assert.match(page.currentSection.value.label, /[\u4e00-\u9fff]/)
|
||||
assert.equal(page.secretValue.value, '')
|
||||
assert.equal(page.confirmed.value, false)
|
||||
assert.equal(page.savedGeneration.value, 0)
|
||||
}
|
||||
assert.deepEqual(requests, ['base', 'smtp', 'imap', 'pop3', 'email', 'ssl', 'plugins']
|
||||
.flatMap(key => ['/api/v1/config/status', `/api/v1/config/${['imap', 'pop3'].includes(key) ? 'email' : key}`, ...(key === 'email' ? ['/api/v1/config/smtp'] : [])]))
|
||||
assert.deepEqual(requests, ['base', 'mail', 'security_policy', 'ssl', 'plugins']
|
||||
.flatMap(key => ['/api/v1/config/status', `/api/v1/config/${key === 'security_policy' ? 'mail' : key}`]))
|
||||
})
|
||||
|
||||
for (const key of ['imap', 'pop3']) {
|
||||
test(`${key} 页面验证、保存、候选恢复及应用均使用邮箱分区且保留其他字段`, async () => {
|
||||
for (const key of ['mail', 'security_policy']) {
|
||||
test(`${key} 页面验证、保存、候选恢复及应用均使用 mail 分区且保留未展示字段`, async () => {
|
||||
const requests = []
|
||||
const payloads = []
|
||||
let pending = null
|
||||
let active = { meta: { schema: 1, generation: 1 }, policy: { maxMessageBytes: 1234 }, imap: { tlsPort: 993 }, pop3: { port: 110, tlsPort: 995 } }
|
||||
let active = {
|
||||
meta: { schema: 1, generation: 1 },
|
||||
listener: { port: 25, starttlsPort: 587, tlsPort: 465 },
|
||||
relay: { verificationEnabled: true, loginPolicy: 'new_device' },
|
||||
imap: { tlsPort: 993 }, pop3: { port: 110, tlsPort: 995 },
|
||||
policy: { maxMessageBytes: 1234, spamFilterLevel: 1, externalRecoveryEnabled: true }
|
||||
}
|
||||
const { page } = fixture(() => {}, key, { http: {
|
||||
get: async path => ({ errorNo: 0, data: path.endsWith('/pending') ? pending : path.endsWith('/status') ? { activeGeneration: active.meta.generation } : structuredClone(active) }),
|
||||
put: async (path, body) => {
|
||||
requests.push(path)
|
||||
assert.equal(body.expectedGeneration, 1)
|
||||
assert.deepEqual(body.payload.policy, active.policy)
|
||||
assert.deepEqual(body.payload[key === 'imap' ? 'pop3' : 'imap'], active[key === 'imap' ? 'pop3' : 'imap'])
|
||||
pending = { generation: 2, candidateId: 'mail-candidate', section: 'email', sameSession: true, payload: body.payload }
|
||||
payloads.push(structuredClone(body))
|
||||
pending = { generation: 2, candidateId: 'mail-candidate', section: 'mail', sameSession: true, payload: body.payload }
|
||||
return { errorNo: 0, data: pending }
|
||||
},
|
||||
post: async (path, body) => {
|
||||
@@ -260,48 +272,50 @@ for (const key of ['imap', 'pop3']) {
|
||||
}
|
||||
} })
|
||||
await page.loadAll()
|
||||
page.updateField([key, 'tlsPort'], key === 'imap' ? 1993 : 1995)
|
||||
const path = key === 'mail' ? ['imap', 'tlsPort'] : ['relay', 'loginPolicy']
|
||||
page.updateField(path, key === 'mail' ? 1993 : 'always')
|
||||
await page.validateConfig()
|
||||
await page.saveConfig()
|
||||
await page.refreshPage()
|
||||
assert.equal(page.savedGeneration.value, 2)
|
||||
page.updateField([key, 'tlsPort'], 8888)
|
||||
assert.notEqual(page.formConfig.value[key].tlsPort, 8888)
|
||||
assert.equal(payloads[0].expectedGeneration, 1)
|
||||
assert.deepEqual(payloads[0].payload.listener, active.listener)
|
||||
assert.deepEqual(payloads[0].payload.pop3, active.pop3)
|
||||
if (key === 'security_policy') assert.equal(payloads[0].secretChanges['relay.password'], undefined)
|
||||
if (key === 'security_policy') {
|
||||
await page.refreshPage()
|
||||
assert.equal(page.savedGeneration.value, 2)
|
||||
}
|
||||
page.updateField(path, key === 'mail' ? 8888 : 'off')
|
||||
assert.notEqual(key === 'mail' ? page.formConfig.value.imap.tlsPort : page.formConfig.value.relay.loginPolicy, key === 'mail' ? 8888 : 'off')
|
||||
await page.applyConfig()
|
||||
assert.equal(page.status.activeGeneration, 2)
|
||||
assert.equal(page.savedGeneration.value, 0)
|
||||
assert.deepEqual(requests, ['/api/v1/config/email/validate', '/api/v1/config/email', '/api/v1/config/email/apply'])
|
||||
assert.deepEqual(requests, ['/api/v1/config/mail/validate', '/api/v1/config/mail', '/api/v1/config/mail/apply'])
|
||||
})
|
||||
}
|
||||
|
||||
test('邮箱策略从三种协议配置汇总已应用端口,不能修改或被候选值误导', async () => {
|
||||
const config = { meta: { generation: 3 }, policy: { smtpPort: 25, imapPort: 143, pop3Port: 110 }, imap: { tlsPort: 1993 }, pop3: { port: 1110, tlsPort: 1995 } }
|
||||
const { page } = fixture(() => {}, 'email', { http: { get: async path => ({ errorNo: 0, data:
|
||||
path.endsWith('/status') ? { activeGeneration: 3 } : path.endsWith('/smtp') ? { meta: { generation: 3 }, listener: { port: 2525, starttlsPort: 2587, tlsPort: 2465 }, relay: { relayPort: 9999 } } :
|
||||
path.endsWith('/pending') ? { section: 'email', generation: 4, sameSession: true, payload: { ...config, imap: { tlsPort: 2993 } } } : config
|
||||
}) } })
|
||||
await page.loadAll()
|
||||
assert.deepEqual(page.mailPortSummary.value.flatMap(service => service.ports.map(port => port.value)), [2525, 2587, 2465, 1993, 1110, 1995])
|
||||
assert.equal(page.formConfig.value.imap.tlsPort, 2993)
|
||||
const before = page.editorText.value
|
||||
for (const path of [['policy', 'smtpPort'], ['policy', 'imapPort'], ['imap', 'tlsPort']]) page.updateField(path, 8888)
|
||||
assert.equal(page.editorText.value, before)
|
||||
})
|
||||
|
||||
test('邮箱策略拒绝不同代次的端口汇总,后续加载失败清除旧汇总', async () => {
|
||||
let generation = 2
|
||||
const { page } = fixture(async path => ({ errorNo: 0, data: path.endsWith('/smtp')
|
||||
? { meta: { generation }, listener: { port: 2525 } }
|
||||
: { meta: { generation: 1 }, imap: { tlsPort: 1993 }, pop3: { port: 1110, tlsPort: 1995 } } }), 'email')
|
||||
test('安全策略页只编辑登录验证和账号恢复字段,完整保留邮件监听、中继与邮件策略', async () => {
|
||||
const config = {
|
||||
listener: { port: 25, starttlsPort: 587, tlsPort: 465 },
|
||||
relay: { relayHost: 'smtp.example.com', relayPort: 587, security: 'starttls', verificationEnabled: true, loginPolicy: 'new_device' },
|
||||
imap: { tlsPort: 993 }, pop3: { port: 110, tlsPort: 995 },
|
||||
policy: { maxMessageBytes: 10485760, spamFilterLevel: 2, externalRecoveryEnabled: true }
|
||||
}
|
||||
let request
|
||||
const { page } = fixture(async () => ({ errorNo: 0, data: config }), 'security_policy', {
|
||||
http: { put: async (path, body) => { request = { path, body }; return { errorNo: 0, data: { generation: 2 } } } }
|
||||
})
|
||||
await page.loadSection()
|
||||
assert.match(page.sectionError.value, /代次/)
|
||||
assert.equal(page.mailPortSummary.value, null)
|
||||
generation = 1
|
||||
await page.loadSection()
|
||||
assert.ok(page.mailPortSummary.value)
|
||||
generation = 3
|
||||
await page.loadSection()
|
||||
assert.equal(page.mailPortSummary.value, null)
|
||||
page.updateField(['relay', 'loginPolicy'], 'always')
|
||||
page.updateField(['listener', 'port'], 2525)
|
||||
await page.saveConfig()
|
||||
assert.equal(request.path, '/api/v1/config/mail')
|
||||
assert.equal(request.body.payload.listener.port, 25)
|
||||
assert.equal(request.body.payload.relay.loginPolicy, 'always')
|
||||
assert.deepEqual(request.body.payload.imap, config.imap)
|
||||
assert.deepEqual(request.body.payload.pop3, config.pop3)
|
||||
assert.equal(request.body.payload.policy.maxMessageBytes, config.policy.maxMessageBytes)
|
||||
assert.deepEqual(request.body.secretChanges, {})
|
||||
})
|
||||
|
||||
test('迁移预览票据返回模板,迁移执行取消时不发送写入请求', async () => {
|
||||
@@ -382,7 +396,7 @@ test('独立页模板可编译,编辑器不再连接维护面板且权限绑
|
||||
assert.ok(maintenance.includes(`pageKey === '${key}' && ${capability}`))
|
||||
}
|
||||
assert.match(maintenance, /v-if="canExportAudit"/)
|
||||
for (const name of ['BaseConfig', 'SmtpConfig', 'ImapConfig', 'Pop3Config', 'EmailConfig', 'SslConfig', 'PluginsConfig', 'ConfigMaintenance', 'MailPortSummary']) {
|
||||
for (const name of ['BaseConfig', 'EmailConfig', 'SslConfig', 'PluginsConfig', 'ConfigMaintenance']) {
|
||||
const page = readFileSync(new URL(`${name}/${name}.vue`, root), 'utf8')
|
||||
const { descriptor, errors } = parse(page)
|
||||
assert.deepEqual(errors, [])
|
||||
@@ -416,9 +430,9 @@ test('配置编辑区移除填写标题、说明与重复标签,保留主标
|
||||
assert.doesNotMatch(template, /'填写配置'|'查看配置'|按分组填写内容|当前页面的脱敏配置内容|panel-heading|selected-section-label/)
|
||||
assert.doesNotMatch(css, /selected-section-label/)
|
||||
assert.match(template, /<h3 id="config-page-title">{{ currentSection.label }}/)
|
||||
assert.match(template, /v-if="selectedSection === 'ssl' && status.tlsMode === 'proxy'"[^>]*role="note"/)
|
||||
assert.doesNotMatch(template, /selectedSection === 'ssl' && status\.tlsMode === 'proxy'|role="note"/)
|
||||
assert.match(template, /v-if="sectionError"[\s\S]*?:title="sectionError"/)
|
||||
assert.match(template, /id="config-sensitive-hint"/)
|
||||
assert.doesNotMatch(template, /config-sensitive-hint|sensitiveHint/)
|
||||
assert.match(template, /v-if="secretField" class="secret-editor"/)
|
||||
assert.match(template, /v-if="validationResult"[^>]*role="status"/)
|
||||
})
|
||||
@@ -426,7 +440,7 @@ test('配置编辑区移除填写标题、说明与重复标签,保留主标
|
||||
test('离开、刷新和正在执行的变更受保护,取消时保留编辑内容', async () => {
|
||||
let cancel = true
|
||||
let prompts = 0
|
||||
const { page } = fixture(async () => ({ errorNo: 0, data: {} }), 'smtp', {
|
||||
const { page } = fixture(async () => ({ errorNo: 0, data: {} }), 'mail', {
|
||||
confirm: async () => { prompts++; if (cancel) throw 'cancel' }
|
||||
})
|
||||
await page.loadAll()
|
||||
@@ -461,7 +475,7 @@ test('标题合并配置状态,保留刷新保护和降级提示,不再渲
|
||||
const header = template.match(/<header[\s\S]*?<\/header>/)?.[0] || ''
|
||||
assert.match(header, /aria-labelledby="config-page-title"/)
|
||||
assert.match(header, /<h3 id="config-page-title">{{ currentSection.label }}/)
|
||||
assert.match(header, /<span class="sr-only">运行状态:<\/span>{{ stateLabel }}/)
|
||||
assert.doesNotMatch(header, /stateLabel|运行状态|state-tag/)
|
||||
assert.match(header, /v-for="issue in status.degradedReasons \|\| \[\]"/)
|
||||
assert.match(header, /v-if="!loading && !availabilityError"/)
|
||||
assert.match(header, /:disabled="!!working \|\| sectionLoading \|\| loading"/)
|
||||
@@ -497,16 +511,24 @@ test('只读账号不得发送配置写入请求或读取无权限维护数据',
|
||||
assert.deepEqual(requests, ['/api/v1/config/status'])
|
||||
})
|
||||
|
||||
test('独立页保持验证、保存、应用端点和代次协议,敏感值不串页', async () => {
|
||||
test('邮件页保持验证、保存、应用端点和代次协议,中继密码只作为 secretChanges 发送', async () => {
|
||||
const requests = []
|
||||
let pending = null
|
||||
const { page } = fixture(async path => ({ errorNo: 0, data: path.endsWith('/status') ? { activeGeneration: 8 } : { relayPasswordStatus: 'configured' } }), 'smtp', {
|
||||
const active = {
|
||||
listener: { port: 25, starttlsPort: 587, tlsPort: 465 },
|
||||
relay: {
|
||||
relayHost: 'smtp.example.com', relayPort: 587, security: 'starttls',
|
||||
from: 'sender@example.com', fromDomain: 'example.com'
|
||||
},
|
||||
imap: { tlsPort: 993 }, pop3: { port: 110, tlsPort: 995 }, policy: {}
|
||||
}
|
||||
const { page } = fixture(async path => ({ errorNo: 0, data: path.endsWith('/status') ? { activeGeneration: 8 } : active }), 'mail', {
|
||||
http: {
|
||||
get: async path => ({ errorNo: 0, data: path.endsWith('/pending') ? pending : path.endsWith('/status') ? { activeGeneration: 8 } : { relayPasswordStatus: 'configured' } }),
|
||||
get: async path => ({ errorNo: 0, data: path.endsWith('/pending') ? pending : path.endsWith('/status') ? { activeGeneration: 8 } : active }),
|
||||
post: async (path, body) => { requests.push({ path, body }); if (path.endsWith('/apply')) pending = null; return { errorNo: 0, data: { valid: true } } },
|
||||
put: async (path, body) => {
|
||||
requests.push({ path, body })
|
||||
pending = { generation: 9, candidateId: 'candidate-9', section: 'smtp', sameSession: true, payload: {} }
|
||||
pending = { generation: 9, candidateId: 'candidate-9', section: 'mail', sameSession: true, payload: body.payload }
|
||||
return { errorNo: 0, data: pending }
|
||||
}
|
||||
}
|
||||
@@ -518,9 +540,10 @@ test('独立页保持验证、保存、应用端点和代次协议,敏感值
|
||||
await page.saveConfig()
|
||||
assert.equal(page.savedGeneration.value, 9)
|
||||
await page.applyConfig()
|
||||
assert.deepEqual(requests.map(item => item.path), ['/api/v1/config/smtp/validate', '/api/v1/config/smtp', '/api/v1/config/smtp/apply'])
|
||||
assert.deepEqual(requests.map(item => item.path), ['/api/v1/config/mail/validate', '/api/v1/config/mail', '/api/v1/config/mail/apply'])
|
||||
assert.equal(requests[0].body.expectedGeneration, 8)
|
||||
assert.deepEqual(requests[0].body.payload, {})
|
||||
assert.equal(requests[0].body.payload.relay.password, undefined)
|
||||
assert.deepEqual(requests[0].body.payload.listener, active.listener)
|
||||
assert.deepEqual(requests[0].body.secretChanges, { 'relay.password': { operation: 'replace', value: { plaintext: 'test-only-value' } } })
|
||||
assert.deepEqual(requests[0].body.confirmation, { confirmed: true, method: 'recent_auth' })
|
||||
assert.deepEqual(requests[2].body, { generation: 9, candidateId: 'candidate-9' })
|
||||
@@ -530,7 +553,11 @@ test('独立页保持验证、保存、应用端点和代次协议,敏感值
|
||||
})
|
||||
|
||||
test('可视化编辑按权限和工作状态保护,编辑会清除过期确认及候选代次', async () => {
|
||||
const { page, dispose } = fixture(async () => ({ errorNo: 0, data: { relay: { relayHost: 'smtp.example.com' } } }), 'smtp')
|
||||
const config = {
|
||||
listener: { port: 25, starttlsPort: 587, tlsPort: 465 },
|
||||
relay: { relayHost: 'smtp.example.com' }, imap: { tlsPort: 993 }, pop3: { port: 110, tlsPort: 995 }, policy: {}
|
||||
}
|
||||
const { page, dispose } = fixture(async () => ({ errorNo: 0, data: config }), 'mail')
|
||||
await page.loadAll()
|
||||
const original = page.editorText.value
|
||||
for (const state of ['loading', 'sectionLoading', 'working', 'sectionError']) {
|
||||
@@ -541,7 +568,7 @@ test('可视化编辑按权限和工作状态保护,编辑会清除过期确
|
||||
assert.equal(page.secretValue.value, '')
|
||||
page[state].value = false
|
||||
}
|
||||
const readonly = fixture(async () => ({ errorNo: 0, data: {} }), 'smtp', { hasCapability: () => false }).page
|
||||
const readonly = fixture(async () => ({ errorNo: 0, data: {} }), 'mail', { hasCapability: () => false }).page
|
||||
readonly.updateField(['relay', 'relayHost'], 'blocked.example.com')
|
||||
assert.equal(readonly.editorText.value, '')
|
||||
page.savedGeneration.value = 8
|
||||
@@ -562,7 +589,15 @@ test('可视化编辑按权限和工作状态保护,编辑会清除过期确
|
||||
|
||||
test('前端无效字段阻止网络请求,修正字段后同步清除错误', async () => {
|
||||
const requests = []
|
||||
const { page } = fixture(async () => ({ errorNo: 0, data: { imap: { tlsPort: 993 } } }), 'imap', {
|
||||
const config = {
|
||||
listener: { port: 25, starttlsPort: 587, tlsPort: 465 },
|
||||
relay: {
|
||||
relayHost: 'smtp.example.com', relayPort: 587, security: 'starttls',
|
||||
from: 'sender@example.com', fromDomain: 'example.com'
|
||||
},
|
||||
imap: { tlsPort: 993 }, pop3: { port: 110, tlsPort: 995 }, policy: {}
|
||||
}
|
||||
const { page } = fixture(async () => ({ errorNo: 0, data: config }), 'mail', {
|
||||
http: { post: async path => { requests.push(path); return { errorNo: 0, data: { valid: true } } } }
|
||||
})
|
||||
await page.loadAll()
|
||||
@@ -574,7 +609,7 @@ test('前端无效字段阻止网络请求,修正字段后同步清除错误',
|
||||
page.updateField(['imap', 'tlsPort'], 1993)
|
||||
assert.deepEqual(page.formErrors.value, {})
|
||||
await page.validateConfig()
|
||||
assert.deepEqual(requests, ['/api/v1/config/email/validate'])
|
||||
assert.deepEqual(requests, ['/api/v1/config/mail/validate'])
|
||||
})
|
||||
|
||||
test('插件读取状态字段不传回严格解析接口,未展示字段和权限仍保留', async () => {
|
||||
@@ -614,7 +649,15 @@ test('SQLite 不显示或发送密码,网络数据库和中继密码留空保
|
||||
assert.deepEqual(request.secretChanges, type === 'sqlite' ? {} : { 'database.password': { operation: 'replace', value: { plaintext: ' test-only-value ' } } })
|
||||
}
|
||||
let request
|
||||
const { page } = fixture(async () => ({ errorNo: 0, data: {} }), 'smtp', {
|
||||
const mail = {
|
||||
listener: { port: 25, starttlsPort: 587, tlsPort: 465 },
|
||||
relay: {
|
||||
relayHost: 'smtp.example.com', relayPort: 587, security: 'starttls',
|
||||
from: 'sender@example.com', fromDomain: 'example.com'
|
||||
},
|
||||
imap: { tlsPort: 993 }, pop3: { port: 110, tlsPort: 995 }, policy: {}
|
||||
}
|
||||
const { page } = fixture(async () => ({ errorNo: 0, data: mail }), 'mail', {
|
||||
http: { post: async (path, body) => { request = body; return { errorNo: 0, data: { valid: true } } } }
|
||||
})
|
||||
await page.loadSection()
|
||||
@@ -644,7 +687,7 @@ test('基础配置保存完整保留隐藏的额外访问主机、数据库和
|
||||
|
||||
test('保存后更改密码或填写内容不能应用旧候选', async () => {
|
||||
const requests = []
|
||||
const { page } = fixture(async () => ({ errorNo: 0, data: {} }), 'smtp', {
|
||||
const { page } = fixture(async () => ({ errorNo: 0, data: {} }), 'mail', {
|
||||
http: {
|
||||
put: async () => ({ errorNo: 0, data: { generation: 8 } }),
|
||||
post: async path => { requests.push(path); return { errorNo: 0 } }
|
||||
@@ -662,19 +705,24 @@ test('保存后更改密码或填写内容不能应用旧候选', async () => {
|
||||
assert.deepEqual(requests, [])
|
||||
})
|
||||
|
||||
test('共用邮箱分区的候选明确提示其他页面的改动,忽略代次与字段顺序', async () => {
|
||||
const active = { meta: { generation: 1 }, imap: { tlsPort: 993 }, pop3: { port: 110, tlsPort: 995 }, policy: { maxMessageBytes: 1234 } }
|
||||
for (const key of ['imap', 'pop3', 'email']) {
|
||||
const { page } = fixture(async path => ({ errorNo: 0, data: path.endsWith('/smtp') ? { meta: { generation: 1 }, listener: {} } : active }), key)
|
||||
test('邮件页与安全策略页共享候选并明确提示改动范围,忽略代次与字段顺序', async () => {
|
||||
const active = {
|
||||
meta: { generation: 1 }, listener: { port: 25, starttlsPort: 587, tlsPort: 465 },
|
||||
relay: { verificationEnabled: true, loginPolicy: 'new_device' },
|
||||
imap: { tlsPort: 993 }, pop3: { port: 110, tlsPort: 995 },
|
||||
policy: { maxMessageBytes: 1234, externalRecoveryEnabled: true }
|
||||
}
|
||||
for (const key of ['mail', 'security_policy']) {
|
||||
const { page } = fixture(async () => ({ errorNo: 0, data: active }), key)
|
||||
await page.loadSection()
|
||||
page.pendingCandidate.value = { section: 'email', payload: { ...active, meta: { generation: 2 }, pop3: { tlsPort: 995, port: 110 } } }
|
||||
assert.match(page.pendingScopeHint.value, /协议端口和邮箱策略未变化/)
|
||||
page.pendingCandidate.value = { section: 'mail', payload: { ...active, meta: { generation: 2 }, pop3: { tlsPort: 995, port: 110 } } }
|
||||
assert.match(page.pendingScopeHint.value, /邮件服务与安全策略未变化/)
|
||||
page.pendingCandidate.value.payload = { ...active, pop3: { port: 1110, tlsPort: 1995 }, policy: { maxMessageBytes: 5678 } }
|
||||
assert.match(page.pendingScopeHint.value, /本次候选涉及:POP3 配置、邮箱策略。/)
|
||||
assert.match(page.pendingScopeHint.value, /请逐页核对;应用时会一起生效/)
|
||||
assert.match(page.pendingScopeHint.value, /本次候选涉及:POP3 监听、邮件与账号策略。/)
|
||||
assert.match(page.pendingScopeHint.value, /邮件服务页和安全策略页共用一个候选配置/)
|
||||
page.pendingCandidate.value = { section: 'smtp' }
|
||||
assert.equal(page.pendingScopeHint.value, '')
|
||||
page.pendingCandidate.value = { section: 'email' }
|
||||
page.pendingCandidate.value = { section: 'mail' }
|
||||
assert.match(page.pendingScopeHint.value, /候选内容尚未完整读取/)
|
||||
}
|
||||
const template = readFileSync(new URL('../../frontend/src/views/components/ConfigSettings/ConfigEditor/ConfigEditor.vue', import.meta.url), 'utf8')
|
||||
|
||||
Reference in new issue
Block a user