fix: preserve SMTP PLAIN auth TLS guard

This commit is contained in:
CaIon
2026-06-24 12:50:54 +08:00
parent 2f23a66733
commit cf6ae6fdeb
2 changed files with 34 additions and 2 deletions
+32
View File
@@ -11,6 +11,7 @@ import (
"fmt"
"math/big"
"net"
"net/smtp"
"strconv"
"strings"
"testing"
@@ -348,6 +349,37 @@ func TestSendEmailDoesNotAutoUpgradeWhenStartTLSDisabled(t *testing.T) {
}
}
func TestSMTPPlainAuthRejectsRemotePlaintextConnection(t *testing.T) {
server := newFakeSMTPServerWithSTARTTLSAdvertisement(t, false)
defer server.close()
withSMTPSettings(t)
SMTPServer = "smtp.example.com"
SMTPPort = server.port
SMTPSSLEnabled = false
SMTPStartTLSEnabled = false
SMTPInsecureSkipVerify = false
SMTPForceAuthLogin = false
SMTPAccount = "sender@example.com"
SMTPFrom = "sender@example.com"
SMTPToken = "secret"
conn, err := net.Dial("tcp", fmt.Sprintf("%s:%d", server.host, server.port))
require.NoError(t, err)
client, err := smtp.NewClient(conn, SMTPServer)
require.NoError(t, err)
err = client.Auth(getSMTPAuth())
require.Error(t, err)
require.Contains(t, err.Error(), "unencrypted connection")
select {
case command := <-server.authCommands:
t.Fatalf("unexpected SMTP auth command: %s", command)
default:
}
}
func TestNewSMTPClientHonorsExplicitStartTLSWhenPortIs465(t *testing.T) {
server := newFakeSMTPServer(t)
defer server.close()