补充SMTP中继开关测试夹具
更新测试场景,明确只有显式启用中继时才校验和投递,验证旧配置不再自动启用。
This commit is contained in:
parent
bbad2bcc6b
commit
4b802b5d11
@ -439,6 +439,7 @@ func TestConfigManagerMailSectionAppliesBothPartitionsWithoutMailFile(t *testing
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
runtime.SMTP.Relay = SMTPConfig{
|
runtime.SMTP.Relay = SMTPConfig{
|
||||||
|
RelayEnabled: true,
|
||||||
RelayHost: "smtp.example.com",
|
RelayHost: "smtp.example.com",
|
||||||
RelayPort: 587,
|
RelayPort: 587,
|
||||||
Username: "relay-user",
|
Username: "relay-user",
|
||||||
@ -1046,11 +1047,12 @@ func TestConfigManagerSecretClearRequiresExplicitConfirmation(t *testing.T) {
|
|||||||
root := t.TempDir()
|
root := t.TempDir()
|
||||||
runtime := validRuntimeConfig()
|
runtime := validRuntimeConfig()
|
||||||
runtime.SMTP.Relay = SMTPConfig{
|
runtime.SMTP.Relay = SMTPConfig{
|
||||||
RelayHost: "smtp.example.com",
|
RelayEnabled: true,
|
||||||
RelayPort: 587,
|
RelayHost: "smtp.example.com",
|
||||||
Security: "starttls",
|
RelayPort: 587,
|
||||||
From: "no-reply@example.com",
|
Security: "starttls",
|
||||||
FromDomain: "example.com",
|
From: "no-reply@example.com",
|
||||||
|
FromDomain: "example.com",
|
||||||
}
|
}
|
||||||
writeRuntimeFixture(t, root, runtime)
|
writeRuntimeFixture(t, root, runtime)
|
||||||
options := ConfigLoaderOptions{Validation: RuntimeValidationOptions{HasSuperAdmin: true, Production: true}}
|
options := ConfigLoaderOptions{Validation: RuntimeValidationOptions{HasSuperAdmin: true, Production: true}}
|
||||||
|
|||||||
@ -258,6 +258,7 @@ func TestCurrentSMTPRuntimeSettingsReadsPartitionSnapshot(t *testing.T) {
|
|||||||
|
|
||||||
runtime := validRuntimeConfig()
|
runtime := validRuntimeConfig()
|
||||||
runtime.SMTP.Relay = SMTPConfig{
|
runtime.SMTP.Relay = SMTPConfig{
|
||||||
|
RelayEnabled: true,
|
||||||
RelayHost: "smtp.example.com",
|
RelayHost: "smtp.example.com",
|
||||||
RelayPort: 587,
|
RelayPort: 587,
|
||||||
Security: "starttls",
|
Security: "starttls",
|
||||||
@ -300,6 +301,7 @@ func TestCurrentSMTPRuntimeSettingsOpensPartitionPassword(t *testing.T) {
|
|||||||
}
|
}
|
||||||
runtime := validRuntimeConfig()
|
runtime := validRuntimeConfig()
|
||||||
runtime.SMTP.Relay = SMTPConfig{
|
runtime.SMTP.Relay = SMTPConfig{
|
||||||
|
RelayEnabled: true,
|
||||||
RelayHost: "smtp.example.com",
|
RelayHost: "smtp.example.com",
|
||||||
RelayPort: 465,
|
RelayPort: 465,
|
||||||
Username: "relay-user",
|
Username: "relay-user",
|
||||||
@ -350,7 +352,7 @@ func TestCurrentSMTPRuntimeSettingsFallsBackToLegacyConfig(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
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)
|
t.Fatalf("legacy SMTP settings = %+v, password=%q", got.Relay, got.Password)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -168,10 +168,6 @@ func validateSMTP(smtp SMTPConfig) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func smtpRelayFieldsConfigured(smtp SMTPConfig) bool {
|
|
||||||
return smtp.RelayHost != "" || smtp.Username != "" || smtp.Password.Configured() || smtp.From != ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func smtpRelayConfigured(smtp SMTPConfig) bool {
|
func smtpRelayConfigured(smtp SMTPConfig) bool {
|
||||||
return smtp.RelayEnabled
|
return smtp.RelayEnabled
|
||||||
}
|
}
|
||||||
|
|||||||
@ -195,21 +195,23 @@ func TestValidateSMTPKeepsLoginVerificationIndependentFromRelay(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "partially configured relay",
|
name: "partially configured relay",
|
||||||
smtp: SMTPConfig{
|
smtp: SMTPConfig{
|
||||||
RelayHost: "smtp.example.com",
|
RelayEnabled: true,
|
||||||
RelayPort: 587,
|
RelayHost: "smtp.example.com",
|
||||||
Security: "starttls",
|
RelayPort: 587,
|
||||||
LoginPolicy: "new_device",
|
Security: "starttls",
|
||||||
|
LoginPolicy: "new_device",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "complete relay",
|
name: "complete relay",
|
||||||
smtp: SMTPConfig{
|
smtp: SMTPConfig{
|
||||||
RelayHost: "smtp.example.com",
|
RelayEnabled: true,
|
||||||
RelayPort: 587,
|
RelayHost: "smtp.example.com",
|
||||||
Security: "starttls",
|
RelayPort: 587,
|
||||||
From: "no-reply@example.com",
|
Security: "starttls",
|
||||||
FromDomain: "example.com",
|
From: "no-reply@example.com",
|
||||||
LoginPolicy: "new_device",
|
FromDomain: "example.com",
|
||||||
|
LoginPolicy: "new_device",
|
||||||
},
|
},
|
||||||
valid: true,
|
valid: true,
|
||||||
},
|
},
|
||||||
|
|||||||
@ -43,7 +43,7 @@ func TestVerificationDeliveryDoesNotHidePartialRelayConfiguration(t *testing.T)
|
|||||||
projectCalled := false
|
projectCalled := false
|
||||||
delivery := newVerificationDeliveryWithDependencies(
|
delivery := newVerificationDeliveryWithDependencies(
|
||||||
func() (config.SMTPRuntimeSettings, error) {
|
func() (config.SMTPRuntimeSettings, error) {
|
||||||
return config.SMTPRuntimeSettings{Relay: config.SMTPConfig{RelayHost: "smtp.example.com"}}, nil
|
return config.SMTPRuntimeSettings{Relay: config.SMTPConfig{RelayEnabled: true, RelayHost: "smtp.example.com"}}, nil
|
||||||
},
|
},
|
||||||
func(config.SMTPRuntimeSettings, verification.Challenge, string) error { return expected },
|
func(config.SMTPRuntimeSettings, verification.Challenge, string) error { return expected },
|
||||||
func(verification.Challenge, string) error {
|
func(verification.Challenge, string) error {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user