From 2bd950469a963b7afaa47bf0093d6d0552bb172e Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Tue, 22 Oct 2024 15:44:40 +0200 Subject: [PATCH] Add 'skipTLS' parameter to auth functions in tests Updated PlainAuth and LoginAuth calls in smtp_test.go and example_test.go to include a 'skipTLS' boolean parameter. This ensures consistent function signatures throughout the test cases and examples. --- smtp/example_test.go | 4 ++-- smtp/smtp_test.go | 42 +++++++++++++++++++++++++++++------------- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/smtp/example_test.go b/smtp/example_test.go index 0445dfc..f0c4cdd 100644 --- a/smtp/example_test.go +++ b/smtp/example_test.go @@ -67,7 +67,7 @@ var ( func ExamplePlainAuth() { // hostname is used by PlainAuth to validate the TLS certificate. hostname := "mail.example.com" - auth := smtp.PlainAuth("", "user@example.com", "password", hostname) + auth := smtp.PlainAuth("", "user@example.com", "password", hostname, false) err := smtp.SendMail(hostname+":25", auth, from, recipients, msg) if err != nil { @@ -77,7 +77,7 @@ func ExamplePlainAuth() { func ExampleSendMail() { // Set up authentication information. - auth := smtp.PlainAuth("", "user@example.com", "password", "mail.example.com") + auth := smtp.PlainAuth("", "user@example.com", "password", "mail.example.com", false) // Connect to the server, authenticate, set the sender and recipient, // and send the email all in one step. diff --git a/smtp/smtp_test.go b/smtp/smtp_test.go index c0e7197..50243ef 100644 --- a/smtp/smtp_test.go +++ b/smtp/smtp_test.go @@ -50,7 +50,7 @@ type authTest struct { var authTests = []authTest{ { - PlainAuth("", "user", "pass", "testserver"), + PlainAuth("", "user", "pass", "testserver", false), []string{}, "PLAIN", []string{"\x00user\x00pass"}, @@ -58,7 +58,15 @@ var authTests = []authTest{ false, }, { - PlainAuth("foo", "bar", "baz", "testserver"), + PlainAuth("", "user", "pass", "testserver", true), + []string{}, + "PLAIN", + []string{"\x00user\x00pass"}, + []bool{false, false}, + false, + }, + { + PlainAuth("foo", "bar", "baz", "testserver", false), []string{}, "PLAIN", []string{"foo\x00bar\x00baz"}, @@ -66,7 +74,7 @@ var authTests = []authTest{ false, }, { - PlainAuth("foo", "bar", "baz", "testserver"), + PlainAuth("foo", "bar", "baz", "testserver", false), []string{"foo"}, "PLAIN", []string{"foo\x00bar\x00baz", ""}, @@ -74,7 +82,7 @@ var authTests = []authTest{ false, }, { - LoginAuth("user", "pass", "testserver"), + LoginAuth("user", "pass", "testserver", false), []string{"Username:", "Password:"}, "LOGIN", []string{"", "user", "pass"}, @@ -82,7 +90,15 @@ var authTests = []authTest{ false, }, { - LoginAuth("user", "pass", "testserver"), + LoginAuth("user", "pass", "testserver", true), + []string{"Username:", "Password:"}, + "LOGIN", + []string{"", "user", "pass"}, + []bool{false, false}, + false, + }, + { + LoginAuth("user", "pass", "testserver", false), []string{"User Name\x00", "Password\x00"}, "LOGIN", []string{"", "user", "pass"}, @@ -90,7 +106,7 @@ var authTests = []authTest{ false, }, { - LoginAuth("user", "pass", "testserver"), + LoginAuth("user", "pass", "testserver", false), []string{"Invalid", "Invalid:"}, "LOGIN", []string{"", "user", "pass"}, @@ -98,7 +114,7 @@ var authTests = []authTest{ false, }, { - LoginAuth("user", "pass", "testserver"), + LoginAuth("user", "pass", "testserver", false), []string{"Invalid", "Invalid:", "Too many"}, "LOGIN", []string{"", "user", "pass", ""}, @@ -237,7 +253,7 @@ func TestAuthPlain(t *testing.T) { }, } for i, tt := range tests { - auth := PlainAuth("foo", "bar", "baz", tt.authName) + auth := PlainAuth("foo", "bar", "baz", tt.authName, false) _, _, err := auth.Start(tt.server) got := "" if err != nil { @@ -283,7 +299,7 @@ func TestAuthLogin(t *testing.T) { }, } for i, tt := range tests { - auth := LoginAuth("foo", "bar", tt.authName) + auth := LoginAuth("foo", "bar", tt.authName, false) _, _, err := auth.Start(tt.server) got := "" if err != nil { @@ -707,7 +723,7 @@ func TestBasic(t *testing.T) { // fake TLS so authentication won't complain c.tls = true c.serverName = "smtp.google.com" - if err := c.Auth(PlainAuth("", "user", "pass", "smtp.google.com")); err != nil { + if err := c.Auth(PlainAuth("", "user", "pass", "smtp.google.com", false)); err != nil { t.Fatalf("AUTH failed: %s", err) } @@ -1278,7 +1294,7 @@ func TestHello(t *testing.T) { case 3: c.tls = true c.serverName = "smtp.google.com" - err = c.Auth(PlainAuth("", "user", "pass", "smtp.google.com")) + err = c.Auth(PlainAuth("", "user", "pass", "smtp.google.com", false)) case 4: err = c.Mail("test@example.com") case 5: @@ -1523,7 +1539,7 @@ func TestSendMailWithAuth(t *testing.T) { } }() - err = SendMail(l.Addr().String(), PlainAuth("", "user", "pass", "smtp.google.com"), "test@example.com", []string{"other@example.com"}, []byte(strings.Replace(`From: test@example.com + err = SendMail(l.Addr().String(), PlainAuth("", "user", "pass", "smtp.google.com", false), "test@example.com", []string{"other@example.com"}, []byte(strings.Replace(`From: test@example.com To: other@example.com Subject: SendMail test @@ -1558,7 +1574,7 @@ func TestAuthFailed(t *testing.T) { c.tls = true c.serverName = "smtp.google.com" - err = c.Auth(PlainAuth("", "user", "pass", "smtp.google.com")) + err = c.Auth(PlainAuth("", "user", "pass", "smtp.google.com", false)) if err == nil { t.Error("Auth: expected error; got none")