移除基础配置代理网段和数据库只读展示
Security Checks / security (push) Waiting to run

This commit is contained in:
xuans committed 2026-09-06 15:00:49 +08:00
1 parent 3bc5ab0c31
commit 0b441a2ed7
3 files changed
+52 -7

No files matched your search

+32
View File
@@ -69,6 +69,38 @@ test('单字段更新完整保留内部数据,锁定字段和污染路径无
assert.equal({}.polluted, undefined)
})
test('基础配置隐藏代理网段和数据库只读信息,不留下空分组且保留内部值', () => {
for (const type of ['sqlite', 'mysql', 'postgresql']) {
for (const tlsMode of ['direct', 'proxy']) {
const config = {
database: { type, localRef: 'preserved.db', name: 'smail', host: 'db.example.com', port: type === 'postgresql' ? 5432 : 3306, username: 'smail', password: null },
http: { tlsMode, port: 8080, trustedProxyCidrs: ['127.0.0.1/32', '192.0.2.10/32'] },
security: { externalEmailEnabled: false, webAuthnEnabled: false }
}
const text = JSON.stringify(config)
const groups = getFieldGroups('base', config)
const keys = groups.flatMap(item => item.fields.map(input => input.path.join('.')))
const hidden = ['database.type', 'database.localRef', 'http.trustedProxyCidrs']
assert.ok(groups.every(item => item.fields.length > 0))
assert.ok(hidden.every(key => !keys.includes(key)))
assert.equal(groups.some(item => item.id === 'database'), type !== 'sqlite')
for (const key of hidden) {
assert.equal(updateFormConfig(text, 'base', key.split('.'), 'changed'), text)
}
for (const key of ['security.externalEmailEnabled', 'security.webAuthnEnabled']) {
assert.ok(keys.includes(key))
}
const updated = readFormConfig(updateFormConfig(text, 'base', ['http', 'port'], 9080))
assert.deepEqual(updated, { ...config, http: { ...config.http, port: 9080 } })
if (type !== 'sqlite') {
for (const key of ['database.name', 'database.host', 'database.port', 'database.username']) {
assert.ok(keys.includes(key))
}
}
}
}
})
test('开关、数字、空数字和列表保持真实类型,代理 HTTPS 正确联动', () => {
const modeField = getFieldGroups('base', {}).flatMap(group => group.fields).find(field => field.path.join('.') === 'http.tlsMode')
assert.match(modeField.hint, /不自动申请或续期 SSL 证书/)
+19
View File
@@ -557,6 +557,25 @@ test('SQLite 不显示或发送密码,网络数据库和中继密码留空保
assert.equal(request.secretChanges['relay.password'].value.plaintext, ' smtp-test-only ')
})
test('基础配置保存完整保留隐藏的数据库和代理信任配置', async () => {
const config = {
database: { type: 'sqlite', localRef: 'preserved.db' },
domains: { primary: 'example.com', web: 'mail.example.com', accepted: ['example.com'] },
http: { tlsMode: 'proxy', port: 8080, httpsEnabled: false, trustedProxyCidrs: ['127.0.0.1/32', '192.0.2.10/32'] },
security: { externalEmailEnabled: false, webAuthnEnabled: false }
}
let request
const { page } = fixture(async () => ({ errorNo: 0, data: config }), 'base', {
http: { put: async (path, body) => { request = { path, body }; return { errorNo: 0, data: { generation: 2 } } } }
})
await page.loadSection()
page.updateField(['http', 'port'], 9080)
await page.saveConfig()
assert.equal(request.path, '/api/v1/config/base')
assert.deepEqual(request.body.payload, { ...config, http: { ...config.http, port: 9080 } })
assert.deepEqual(request.body.secretChanges, {})
})
test('保存后更改密码或填写内容不能应用旧候选', async () => {
const requests = []
const { page } = fixture(async () => ({ errorNo: 0, data: {} }), 'smtp', {