保存统一Web域名恢复入口接手基线
Security Checks / security (push) Waiting to run

This commit is contained in:
xuans committed 2026-09-16 19:17:55 +08:00
1 parent 74493f0d5b
commit 606861822b
18 files changed
+129 -90

No files matched your search

+6 -11
View File
@@ -278,23 +278,18 @@ test('域名校验兼容大小写和末尾点,拒绝重复项、空白和路
const valid = { database: { type: 'sqlite' }, domains: { primary: 'Example.com.', web: 'mail.example.com', accepted: ['example.com'] } }
assert.deepEqual(validateFormConfig('base', valid), {})
const fields = getFieldGroups('base', valid).flatMap(group => group.fields)
const recovery = fields.find(field => field.path.join('.') === 'domains.adminRecovery')
assert.ok(recovery)
assert.match(recovery.hint, /不开放公网重置页面/)
assert.deepEqual(validateFormConfig('base', { ...valid, domains: { ...valid.domains, adminRecovery: '' } }), {})
assert.deepEqual(validateFormConfig('base', { ...valid, domains: { ...valid.domains, adminRecovery: 'recovery.example.com' } }), {})
assert.equal(fields.some(field => field.path.join('.') === 'domains.adminRecovery'), false)
for (const accepted of [[], ['example.com', 'Example.com.'], [''], [' https://example.com'], ['other.example.com'], 'example.com', [null]]) {
assert.ok(validateFormConfig('base', { ...valid, domains: { ...valid.domains, accepted } })['domains.accepted'])
}
for (const primary of ['https://example.com', 'example.com/path', 'bad..com', '-bad.com', '127.0.0.1', '例子.com']) {
assert.ok(validateFormConfig('base', { ...valid, domains: { ...valid.domains, primary } })['domains.primary'])
}
for (const adminRecovery of ['https://example.com', 'example.com/path', 'bad..com', '-bad.com', '127.0.0.1', '例子.com', ' recovery.example.com']) {
assert.ok(validateFormConfig('base', { ...valid, domains: { ...valid.domains, adminRecovery } })['domains.adminRecovery'])
}
const text = JSON.stringify({ ...valid, domains: { ...valid.domains, accepted: ['example.com'], accessHosts: ['192.0.2.10'], adminRecovery: '' } })
const updated = readFormConfig(updateFormConfig(text, 'base', ['domains', 'adminRecovery'], 'recovery.example.com'))
assert.equal(updated.domains.adminRecovery, 'recovery.example.com')
const text = JSON.stringify({ ...valid, domains: { ...valid.domains, accepted: ['example.com'], accessHosts: ['192.0.2.10'], adminRecovery: 'legacy.example.com' } })
const unchanged = updateFormConfig(text, 'base', ['domains', 'adminRecovery'], 'recovery.example.com')
assert.equal(unchanged, text)
const updated = readFormConfig(unchanged)
assert.equal(updated.domains.adminRecovery, 'legacy.example.com')
assert.deepEqual(updated.domains.accepted, ['example.com'])
assert.deepEqual(updated.domains.accessHosts, ['192.0.2.10'])
})
+2 -1
View File
@@ -45,7 +45,8 @@ test('前端入口按需加载 Element Plus,并延迟设置页和写信编辑
test('开发服务器将匿名恢复入口和接口安全转发到后端', async () => {
const vite = await read('frontend/vite.config.js')
assert.match(vite, /"\/public-password-recovery": developmentBackendProxy\(backendUrl, backendOrigin\)/)
assert.match(vite, /"\/rest\/api\/recovery": developmentBackendProxy\(backendUrl, publicRecoveryOrigin\)/)
assert.match(vite, /"\/rest\/api\/recovery": developmentBackendProxy\(backendUrl, backendOrigin\)/)
assert.doesNotMatch(vite, /publicRecoveryOrigin|mailOrigin/)
})
test('开发启动必须固定运行配置根目录并集中保存日志', async () => {
+2 -3
View File
@@ -21,7 +21,6 @@ test('开发配置只从模拟部署目录读取且不返回凭据字段', async
await writeFile(path.join(root, 'ssl/private.key'), 'key', { mode: 0o600 })
const runtime = readDevelopmentRuntime(root)
assert.equal(runtime.origin, 'https://mail.example.test')
assert.equal(runtime.mailOrigin, 'https://mail.example.test')
assert.equal(runtime.generation, 9)
assert.equal(runtime.privateKeyPath, path.join(root, 'ssl/private.key'))
assert.equal(JSON.stringify(runtime).includes('not-exported'), false)
@@ -32,7 +31,7 @@ test('开发配置只从模拟部署目录读取且不返回凭据字段', async
assert.throws(() => readDevelopmentRuntime(root), /事务尚未完成/)
})
test('开发运行配置单独保留主邮件域名供匿名恢复接口校验', async () => {
test('开发恢复接口与页面统一使用 Web 域名', async () => {
const root = await mkdtemp(path.join(os.tmpdir(), 'smail-runtime-recovery-domain-'))
await mkdir(path.join(root, 'config'))
await mkdir(path.join(root, 'ssl'))
@@ -49,7 +48,7 @@ test('开发运行配置单独保留主邮件域名供匿名恢复接口校验',
const runtime = readDevelopmentRuntime(root)
assert.equal(runtime.origin, 'https://web.example.test')
assert.equal(runtime.mailOrigin, 'https://mail.example.test')
assert.equal('mailOrigin' in runtime, false)
})
test('源码指纹检测编辑且忽略编译嵌入目录', async () => {