修复审查发现的认证配置邮件协议及前端问题
补齐安全运行时清理、配置候选恢复、泛域名证书事务提交、邮件副本与协议边界、插件隐私和安装回滚回归,并更新修复状态及待验收清单。
This commit is contained in:
1 parent
addfcea1cd
commit
6f79441585
71 files changed
+2853
-664
No files matched your search
@@ -20,7 +20,10 @@ function fixture(get, pageKey = 'base', options = {}) {
|
||||
let dispose = () => {}
|
||||
const page = createPageWithKey(computed, () => {}, reactive, ref,
|
||||
{ error: message => messages.push(message), warning: message => messages.push(message), success: () => {} },
|
||||
{ confirm: options.confirm || (async () => {}) }, { get, ...options.http },
|
||||
{ confirm: options.confirm || (async () => {}) }, {
|
||||
get: path => path.endsWith('/pending') && !options.pendingGet ? Promise.resolve({ errorNo: 0, data: null }) : get(path),
|
||||
...options.http
|
||||
},
|
||||
() => ({ hasCapability: options.hasCapability || (() => true) }), pageKey, callback => { dispose = callback })
|
||||
return { page, messages, dispose: () => dispose() }
|
||||
}
|
||||
@@ -32,6 +35,51 @@ function deferred() {
|
||||
return { promise, resolve, reject }
|
||||
}
|
||||
|
||||
for (const failedRequest of ['/status', '/pending']) {
|
||||
test(`候选保存成功后 ${failedRequest} 读取失败不能重新保存,刷新后可恢复或取消`, async () => {
|
||||
let pending = null
|
||||
let fail = false
|
||||
let saves = 0
|
||||
const { page } = fixture(() => {}, 'smtp', { 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' } } }
|
||||
},
|
||||
put: async (path, body) => {
|
||||
saves++
|
||||
pending = { generation: 2, candidateId: 'pending-recovery', section: 'smtp', sameSession: true, payload: body.payload }
|
||||
fail = true
|
||||
return { errorNo: 0, data: pending }
|
||||
},
|
||||
post: async (path, body) => {
|
||||
assert.equal(body.candidateId, 'pending-recovery')
|
||||
if (body.action === 'resume') pending.sameSession = true
|
||||
if (body.action === 'cancel') pending = null
|
||||
return { errorNo: 0 }
|
||||
}
|
||||
} })
|
||||
await page.loadAll()
|
||||
page.updateField(['relay', 'relayHost'], 'new.example.com')
|
||||
await page.saveConfig()
|
||||
assert.equal(saves, 1)
|
||||
page.updateField(['relay', 'relayHost'], 'blocked.example.com')
|
||||
await page.saveConfig()
|
||||
assert.equal(saves, 1)
|
||||
assert.equal(page.formConfig.value.relay.relayHost, 'new.example.com')
|
||||
fail = false
|
||||
pending.sameSession = false
|
||||
await page.refreshPage()
|
||||
assert.equal(page.savedGeneration.value, 0)
|
||||
assert.equal(page.pendingCandidate.value.candidateId, 'pending-recovery')
|
||||
await page.managePending('resume')
|
||||
assert.equal(page.savedGeneration.value, 2)
|
||||
await page.managePending('cancel')
|
||||
assert.equal(page.pendingCandidate.value, null)
|
||||
page.updateField(['relay', 'relayHost'], 'editable.example.com')
|
||||
assert.equal(page.formConfig.value.relay.relayHost, 'editable.example.com')
|
||||
})
|
||||
}
|
||||
|
||||
test('旧版配置仅请求状态,不并发请求分区、备份和审计', async () => {
|
||||
const requests = []
|
||||
const { page, messages } = fixture(async path => {
|
||||
@@ -341,10 +389,16 @@ test('只读账号不得发送配置写入请求或读取无权限维护数据',
|
||||
|
||||
test('独立页保持验证、保存、应用端点和代次协议,敏感值不串页', async () => {
|
||||
const requests = []
|
||||
let pending = null
|
||||
const { page } = fixture(async path => ({ errorNo: 0, data: path.endsWith('/status') ? { activeGeneration: 8 } : { relayPasswordStatus: 'configured' } }), 'smtp', {
|
||||
http: {
|
||||
post: async (path, body) => { requests.push({ path, body }); return { errorNo: 0, data: { valid: true } } },
|
||||
put: async (path, body) => { requests.push({ path, body }); return { errorNo: 0, data: { generation: 9 } } }
|
||||
get: async path => ({ errorNo: 0, data: path.endsWith('/pending') ? pending : path.endsWith('/status') ? { activeGeneration: 8 } : { relayPasswordStatus: 'configured' } }),
|
||||
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: {} }
|
||||
return { errorNo: 0, data: pending }
|
||||
}
|
||||
}
|
||||
})
|
||||
await page.loadAll()
|
||||
@@ -359,7 +413,7 @@ test('独立页保持验证、保存、应用端点和代次协议,敏感值
|
||||
assert.deepEqual(requests[0].body.payload, {})
|
||||
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 })
|
||||
assert.deepEqual(requests[2].body, { generation: 9, candidateId: 'candidate-9' })
|
||||
assert.equal(page.secretValue.value, '')
|
||||
assert.equal(page.confirmed.value, false)
|
||||
assert.equal(page.savedGeneration.value, 0)
|
||||
@@ -381,6 +435,9 @@ test('可视化编辑按权限和工作状态保护,编辑会清除过期确
|
||||
readonly.updateField(['relay', 'relayHost'], 'blocked.example.com')
|
||||
assert.equal(readonly.editorText.value, '')
|
||||
page.savedGeneration.value = 8
|
||||
page.updateField(['relay', 'relayHost'], 'blocked.example.com')
|
||||
assert.equal(page.editorText.value, original)
|
||||
page.savedGeneration.value = 0
|
||||
page.confirmed.value = true
|
||||
page.validationResult.value = { valid: true }
|
||||
page.updateField(['relay', 'relayHost'], 'new.example.com')
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { compileFunction } from 'node:vm'
|
||||
import { createRequire } from 'node:module'
|
||||
import { computed, reactive, ref } from './vue.mjs'
|
||||
|
||||
const root = new URL('../../frontend/src/views/components/PluginSettings/', import.meta.url)
|
||||
const source = readFileSync(new URL('TelegramSettings/TelegramSettings.js', root), 'utf8')
|
||||
const create = compileFunction(source.replace(/^import .*$/gm, '').replace('export function ', 'function ') + '\nreturn useTelegramSettings()',
|
||||
['computed', 'onMounted', 'onBeforeUnmount', 'reactive', 'ref', 'ElMessage', 'http'])
|
||||
|
||||
test('Telegram 原生设置保留版本、限制用户字段,不依赖插件 iframe', async () => {
|
||||
const requests = []
|
||||
let conflict = false
|
||||
const page = create(computed, () => {}, () => {}, reactive, ref, { success() {} }, {
|
||||
get: async url => ({ errorNo: 0, data: url.endsWith('/bot') ? { username: 'smail_test_bot', botLink: 'javascript:alert(1)' }
|
||||
: { version: 7, settings: { chatId: '123', sendAttachments: false, secret: '不得传回' } } }),
|
||||
put: async (url, body) => {
|
||||
requests.push({ url, body })
|
||||
return conflict ? { errorNo: 400, errorMsg: '配置已被其他操作更新,请刷新后重试' }
|
||||
: { errorNo: 0, data: { version: 8, settings: body.settings } }
|
||||
},
|
||||
post: async (url, body) => { requests.push({ url, body }); return { errorNo: 0 } }
|
||||
})
|
||||
await page.load()
|
||||
assert.equal(page.ready.value, true)
|
||||
assert.equal(page.botLink.value, 'https://t.me/smail_test_bot')
|
||||
page.settings.sendAttachments = true
|
||||
await page.submit('save')
|
||||
assert.equal(requests[0].body.version, 7)
|
||||
assert.deepEqual(Object.keys(requests[0].body.settings).sort(), ['chatId', 'disableLinkPreview', 'sendAttachments', 'showContent', 'spoilerContent'])
|
||||
assert.equal(page.version.value, 8)
|
||||
await page.submit('test')
|
||||
assert.equal(requests[1].url, '/api/v1/plugin/settings/telegram_push/test')
|
||||
assert.equal(page.version.value, 8)
|
||||
conflict = true
|
||||
await page.submit('save')
|
||||
assert.match(page.errorMessage.value, /刷新/)
|
||||
assert.equal(page.version.value, 8)
|
||||
const count = requests.length
|
||||
page.settings.chatId = 'invalid'
|
||||
await page.submit('test')
|
||||
assert.equal(requests.length, count)
|
||||
})
|
||||
|
||||
test('Telegram 首次读取失败禁止覆盖存量设置,机器人故障不影响停用', async () => {
|
||||
let fail = true
|
||||
const page = create(computed, () => {}, () => {}, reactive, ref, { success() {} }, {
|
||||
get: async url => {
|
||||
if (fail || url.endsWith('/bot')) throw new Error('模拟离线')
|
||||
return { errorNo: 0, data: { version: 0, settings: {} } }
|
||||
},
|
||||
put: async () => assert.fail('读取失败后不能保存')
|
||||
})
|
||||
await page.load()
|
||||
await page.submit('save')
|
||||
assert.equal(page.ready.value, false)
|
||||
fail = false
|
||||
await page.load()
|
||||
assert.equal(page.ready.value, true)
|
||||
assert.equal(page.botLink.value, '')
|
||||
})
|
||||
|
||||
test('Telegram 模板独立编译,其他插件继续保持 sandbox 隔离', () => {
|
||||
const require = createRequire(new URL('../../frontend/package.json', import.meta.url))
|
||||
const { parse, compileScript, compileStyle } = require('@vue/compiler-sfc')
|
||||
const parent = readFileSync(new URL('PluginSettings.vue', root), 'utf8')
|
||||
assert.match(parent, /TelegramSettings v-else-if="entry.logicalID === 'telegram_push'"/)
|
||||
assert.match(parent, /sandbox="allow-scripts"/)
|
||||
assert.doesNotMatch(parent, /allow-same-origin/)
|
||||
const { descriptor, errors } = parse(readFileSync(new URL('TelegramSettings/TelegramSettings.vue', root), 'utf8'))
|
||||
assert.deepEqual(errors, [])
|
||||
assert.doesNotThrow(() => compileScript(descriptor, { id: 'telegram-settings', inlineTemplate: true }))
|
||||
assert.deepEqual(compileStyle({ source: readFileSync(new URL('TelegramSettings/TelegramSettings.css', root), 'utf8'), id: 'telegram-settings', scoped: true }).errors, [])
|
||||
assert.doesNotMatch(source, /window\.parent|parent\.document|postMessage|localStorage/)
|
||||
})
|
||||
Reference in new issue
Block a user