fix: preserve SMTP PLAIN auth TLS guard
This commit is contained in:
@@ -31,7 +31,7 @@ func (a *smtpAutoAuth) Start(server *smtp.ServerInfo) (string, []byte, error) {
|
|||||||
switch {
|
switch {
|
||||||
case smtpServerSupportsAuth(server, "PLAIN"):
|
case smtpServerSupportsAuth(server, "PLAIN"):
|
||||||
a.mech = "PLAIN"
|
a.mech = "PLAIN"
|
||||||
return "PLAIN", []byte("\x00" + a.username + "\x00" + a.password), nil
|
return smtp.PlainAuth("", a.username, a.password, SMTPServer).Start(server)
|
||||||
case smtpServerSupportsAuth(server, "LOGIN"):
|
case smtpServerSupportsAuth(server, "LOGIN"):
|
||||||
a.mech = "LOGIN"
|
a.mech = "LOGIN"
|
||||||
return "LOGIN", []byte{}, nil
|
return "LOGIN", []byte{}, nil
|
||||||
@@ -44,7 +44,7 @@ func (a *smtpAutoAuth) Start(server *smtp.ServerInfo) (string, []byte, error) {
|
|||||||
return "NTLM", negotiateMessage, nil
|
return "NTLM", negotiateMessage, nil
|
||||||
default:
|
default:
|
||||||
a.mech = "PLAIN"
|
a.mech = "PLAIN"
|
||||||
return "PLAIN", []byte("\x00" + a.username + "\x00" + a.password), nil
|
return smtp.PlainAuth("", a.username, a.password, SMTPServer).Start(server)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
"net"
|
"net"
|
||||||
|
"net/smtp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"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) {
|
func TestNewSMTPClientHonorsExplicitStartTLSWhenPortIs465(t *testing.T) {
|
||||||
server := newFakeSMTPServer(t)
|
server := newFakeSMTPServer(t)
|
||||||
defer server.close()
|
defer server.close()
|
||||||
|
|||||||
Reference in New Issue
Block a user