1 parent
98af5890e5
commit
0a6b13da05
7 files changed
+84
-38
No files matched your search
@@ -84,12 +84,6 @@ func validateMailListeners(smtp SMTPSectionConfig, email EmailSectionConfig) err
|
||||
if security != MailSecurityBoth && security != MailSecuritySTARTTLS && security != MailSecurityImplicitTLS {
|
||||
return ErrInvalidRuntimeConfig
|
||||
}
|
||||
if smtpRelayEnabled(smtp.Relay) && security != MailSecurityBoth {
|
||||
relaySecurity := NormalizeMailSecurity(smtp.Relay.Security)
|
||||
if relaySecurity != security {
|
||||
return ErrInvalidSMTP
|
||||
}
|
||||
}
|
||||
for _, port := range []int{
|
||||
smtp.Listener.Port, smtp.Listener.STARTTLSPort, smtp.Listener.TLSPort,
|
||||
email.IMAP.TLSPort, email.POP3.Port, email.POP3.TLSPort,
|
||||
|
||||
@@ -201,6 +201,34 @@ func TestMailListenerValidationRejectsUnknownSecurity(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestMailListenerAndRelaySecurityAreIndependent(t *testing.T) {
|
||||
for _, listenerSecurity := range []string{MailSecurityBoth, MailSecuritySTARTTLS, MailSecurityImplicitTLS} {
|
||||
for _, relaySecurity := range []string{MailSecuritySTARTTLS, MailSecurityImplicitTLS} {
|
||||
t.Run(listenerSecurity+"_"+relaySecurity, func(t *testing.T) {
|
||||
runtime := validRuntimeConfig()
|
||||
runtime.SMTP.Listener.Security = listenerSecurity
|
||||
runtime.SMTP.Relay = SMTPConfig{
|
||||
RelayEnabled: true,
|
||||
RelayHost: "smtp.example.com",
|
||||
RelayPort: 2525,
|
||||
Security: relaySecurity,
|
||||
From: "sender@example.com",
|
||||
FromDomain: "example.com",
|
||||
}
|
||||
if err := ValidateRuntimeConfig(runtime, RuntimeValidationOptions{HasSuperAdmin: true}); err != nil {
|
||||
t.Fatalf("independent relay validation = %v", err)
|
||||
}
|
||||
for _, invalidSecurity := range []string{"", "plain", "unknown"} {
|
||||
runtime.SMTP.Relay.Security = invalidSecurity
|
||||
if err := ValidateRuntimeConfig(runtime, RuntimeValidationOptions{HasSuperAdmin: true}); err == nil {
|
||||
t.Fatalf("insecure relay %q must be rejected", invalidSecurity)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMailListenerValidationAllowsLegacyEmptyAndExplicitBothSecurity(t *testing.T) {
|
||||
runtime := validRuntimeConfig()
|
||||
if err := ValidateRuntimeConfig(runtime, RuntimeValidationOptions{HasSuperAdmin: true}); err != nil {
|
||||
|
||||
Reference in new issue
Block a user