补充SMTP中继开关测试夹具

更新测试场景,明确只有显式启用中继时才校验和投递,验证旧配置不再自动启用。
This commit is contained in:
xuans committed 2026-10-06 00:32:43 +08:00
1 parent 81bb792ba7
commit 833aac2fbb
5 files changed
+23 -21

No files matched your search

+7 -5
View File
@@ -439,6 +439,7 @@ func TestConfigManagerMailSectionAppliesBothPartitionsWithoutMailFile(t *testing
t.Fatal(err)
}
runtime.SMTP.Relay = SMTPConfig{
RelayEnabled: true,
RelayHost: "smtp.example.com",
RelayPort: 587,
Username: "relay-user",
@@ -1046,11 +1047,12 @@ func TestConfigManagerSecretClearRequiresExplicitConfirmation(t *testing.T) {
root := t.TempDir()
runtime := validRuntimeConfig()
runtime.SMTP.Relay = SMTPConfig{
RelayHost: "smtp.example.com",
RelayPort: 587,
Security: "starttls",
From: "no-reply@example.com",
FromDomain: "example.com",
RelayEnabled: true,
RelayHost: "smtp.example.com",
RelayPort: 587,
Security: "starttls",
From: "no-reply@example.com",
FromDomain: "example.com",
}
writeRuntimeFixture(t, root, runtime)
options := ConfigLoaderOptions{Validation: RuntimeValidationOptions{HasSuperAdmin: true, Production: true}}
+3 -1
View File
@@ -258,6 +258,7 @@ func TestCurrentSMTPRuntimeSettingsReadsPartitionSnapshot(t *testing.T) {
runtime := validRuntimeConfig()
runtime.SMTP.Relay = SMTPConfig{
RelayEnabled: true,
RelayHost: "smtp.example.com",
RelayPort: 587,
Security: "starttls",
@@ -300,6 +301,7 @@ func TestCurrentSMTPRuntimeSettingsOpensPartitionPassword(t *testing.T) {
}
runtime := validRuntimeConfig()
runtime.SMTP.Relay = SMTPConfig{
RelayEnabled: true,
RelayHost: "smtp.example.com",
RelayPort: 465,
Username: "relay-user",
@@ -350,7 +352,7 @@ func TestCurrentSMTPRuntimeSettingsFallsBackToLegacyConfig(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if got.Password != "relay-password" || got.Relay.Username != "relay-user" || got.Relay.From != "no-reply@example.com" {
if got.Password != "relay-password" || got.Relay.RelayEnabled || got.Relay.Username != "relay-user" || got.Relay.From != "no-reply@example.com" {
t.Fatalf("legacy SMTP settings = %+v, password=%q", got.Relay, got.Password)
}
}
-4
View File
@@ -168,10 +168,6 @@ func validateSMTP(smtp SMTPConfig) error {
return nil
}
func smtpRelayFieldsConfigured(smtp SMTPConfig) bool {
return smtp.RelayHost != "" || smtp.Username != "" || smtp.Password.Configured() || smtp.From != ""
}
func smtpRelayConfigured(smtp SMTPConfig) bool {
return smtp.RelayEnabled
}
+12 -10
View File
@@ -195,21 +195,23 @@ func TestValidateSMTPKeepsLoginVerificationIndependentFromRelay(t *testing.T) {
{
name: "partially configured relay",
smtp: SMTPConfig{
RelayHost: "smtp.example.com",
RelayPort: 587,
Security: "starttls",
LoginPolicy: "new_device",
RelayEnabled: true,
RelayHost: "smtp.example.com",
RelayPort: 587,
Security: "starttls",
LoginPolicy: "new_device",
},
},
{
name: "complete relay",
smtp: SMTPConfig{
RelayHost: "smtp.example.com",
RelayPort: 587,
Security: "starttls",
From: "no-reply@example.com",
FromDomain: "example.com",
LoginPolicy: "new_device",
RelayEnabled: true,
RelayHost: "smtp.example.com",
RelayPort: 587,
Security: "starttls",
From: "no-reply@example.com",
FromDomain: "example.com",
LoginPolicy: "new_device",
},
valid: true,
},