From feb096f1b13ef98e29ae12d46968fe7936be8b71 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Sun, 12 Jan 2025 13:45:52 +0100 Subject: [PATCH] fix: Update SMTP auth preferences and adjust related tests Removed XOAUTH2 from the preferred SMTPAuthType list. Since XOAUTH2 requires a Bearer token the auto-discovery feature will not work, since it will expect user/password. Updated test cases to reflect these changes, ensuring proper alignment with the revised authentication preferences. This addresses #415 --- client.go | 4 ++-- client_test.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/client.go b/client.go index 830fec4f..60ea8bcb 100644 --- a/client.go +++ b/client.go @@ -1323,10 +1323,10 @@ func (c *Client) authTypeAutoDiscover(supported string, isEnc bool) (SMTPAuthTyp } preferList := []SMTPAuthType{ SMTPAuthSCRAMSHA256PLUS, SMTPAuthSCRAMSHA256, SMTPAuthSCRAMSHA1PLUS, SMTPAuthSCRAMSHA1, - SMTPAuthXOAUTH2, SMTPAuthCramMD5, SMTPAuthPlain, SMTPAuthLogin, + SMTPAuthCramMD5, SMTPAuthPlain, SMTPAuthLogin, } if !isEnc { - preferList = []SMTPAuthType{SMTPAuthSCRAMSHA256, SMTPAuthSCRAMSHA1, SMTPAuthXOAUTH2, SMTPAuthCramMD5} + preferList = []SMTPAuthType{SMTPAuthSCRAMSHA256, SMTPAuthSCRAMSHA1, SMTPAuthCramMD5} } mechs := strings.Split(supported, " ") diff --git a/client_test.go b/client_test.go index 3c32515f..490e9c19 100644 --- a/client_test.go +++ b/client_test.go @@ -2393,7 +2393,7 @@ func TestClient_auth(t *testing.T) { {"PLAIN via AUTODISCOVER", SMTPAuthAutoDiscover}, {"SCRAM-SHA-1 via AUTODISCOVER", SMTPAuthAutoDiscover}, {"SCRAM-SHA-256 via AUTODISCOVER", SMTPAuthAutoDiscover}, - {"XOAUTH2 via AUTODISCOVER", SMTPAuthAutoDiscover}, + {"CRAM-MD5 via AUTODISCOVER", SMTPAuthAutoDiscover}, {"CRAM-MD5", SMTPAuthCramMD5}, {"LOGIN", SMTPAuthLogin}, {"LOGIN-NOENC", SMTPAuthLoginNoEnc}, @@ -2610,7 +2610,7 @@ func TestClient_authTypeAutoDiscover(t *testing.T) { {"LOGIN SCRAM-SHA-256 SCRAM-SHA-1 SCRAM-SHA-256-PLUS SCRAM-SHA-1-PLUS", false, SMTPAuthSCRAMSHA256, false}, {"LOGIN PLAIN SCRAM-SHA-1 SCRAM-SHA-1-PLUS", true, SMTPAuthSCRAMSHA1PLUS, false}, {"LOGIN PLAIN SCRAM-SHA-1 SCRAM-SHA-1-PLUS", false, SMTPAuthSCRAMSHA1, false}, - {"LOGIN XOAUTH2 SCRAM-SHA-1-PLUS", false, SMTPAuthXOAUTH2, false}, + {"LOGIN XOAUTH2 SCRAM-SHA-1 SCRAM-SHA-1-PLUS", false, SMTPAuthSCRAMSHA1, false}, {"PLAIN LOGIN CRAM-MD5", false, SMTPAuthCramMD5, false}, {"CRAM-MD5", false, SMTPAuthCramMD5, false}, {"PLAIN", true, SMTPAuthPlain, false},