fix(email): derive SMTP auth from credentials

This commit is contained in:
2026-09-04 13:24:26 +08:00
parent 13fda31e37
commit dda343e398
4 changed files with 67 additions and 29 deletions
@@ -9,6 +9,7 @@ const read = (file) => fs.readFileSync(path.join(root, file), 'utf8')
const templates = read('src/Settings/MailTemplates.php')
const mail = read('src/Settings/Mail.php')
const notifications = read('src/Settings/MailNotifications.php')
const coreHooks = read('inc/core-hooks/part-2.php')
const globalController = read('src/Admin/GlobalController.php')
const userController = read('src/Admin/UserController.php')
const settings = read('src/Settings/Settings.php')
@@ -37,11 +38,28 @@ test('email templates and SMTP use one aksrt_settings schema', () => {
assert.match(templates, /'option_key'\s*=>\s*'aksrt_settings'/)
assert.match(templates, /'mail_passwd'.*'secret'\s*=>\s*true/)
assert.match(mail, /Settings::get_all\(\)/)
assert.match(mail, /'auth'\s*=>\s*\$username\s*!==\s*''\s*&&\s*\$password\s*!==\s*''/)
assert.doesNotMatch(templates, /mail_smtpauth/)
assert.doesNotMatch(mail, /mail_smtpauth/)
assert.doesNotMatch(settings, /aksrt_mail_smtp/)
assert.doesNotMatch(globalController, /aksrt_mail_config|\/settings\/mail'/)
assert.doesNotMatch(userController, /aksrt_mail_templates|mail-templates/)
})
test('SMTP authentication and failures use the canonical mail service', () => {
assert.match(coreHooks, /\$phpmailer->SMTPAuth\s*=\s*!empty\(\$mail\['auth'\]\)\s*&&\s*!empty\(\$mail\['username'\]\)/)
assert.match(mail, /add_action\('wp_mail_failed',\s*\$capture_failure\)/)
assert.match(mail, /remove_action\('wp_mail_failed',\s*\$capture_failure\)/)
assert.match(mail, /error_log\('\[AKSRT\] SMTP 测试失败:'/)
assert.match(globalController, /详细原因已写入服务器错误日志/)
})
test('canonical mail service contains no obsolete catalog or placeholder branches', () => {
assert.doesNotMatch(mail, /public static function events\s*\(/)
assert.doesNotMatch(mail, /replace_placeholders\([^\n]+,\s*false\)/)
assert.doesNotMatch(mail, /replace_placeholders\(string \$value, array \$placeholders, bool \$html\)/)
})
test('only the canonical mail service calls wp_mail', () => {
const phpFiles = []
const walk = (dir) => {