From 820d1c25d82a145dead93470677bcda4cf33f9a4 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Wed, 11 Jan 2023 20:35:22 +0100 Subject: [PATCH] Fork net/smpt into go-mail Implemented negative check for AuthLogin Auth method --- smtp/smtp_test.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/smtp/smtp_test.go b/smtp/smtp_test.go index ecdfcd1..f8866a7 100644 --- a/smtp/smtp_test.go +++ b/smtp/smtp_test.go @@ -34,6 +34,7 @@ type authTest struct { challenges []string name string responses []string + sf []bool } var authTests = []authTest{ @@ -42,24 +43,28 @@ var authTests = []authTest{ []string{}, "PLAIN", []string{"\x00user\x00pass"}, + []bool{false, false}, }, { PlainAuth("foo", "bar", "baz", "testserver"), []string{}, "PLAIN", []string{"foo\x00bar\x00baz"}, + []bool{false, false}, }, { LoginAuth("user", "pass", "testserver"), - []string{"Username:", "Password:"}, + []string{"Username:", "Password:", "Invalid:"}, "LOGIN", []string{"", "user", "pass", ""}, + []bool{false, false, true}, }, { CRAMMD5Auth("user", "pass"), []string{"<123456.1322876914@testserver>"}, "CRAM-MD5", []string{"", "user 287eb355114cf5c471c26a875f1ca4ae"}, + []bool{false, false}, }, } @@ -79,8 +84,9 @@ testLoop: for j := range test.challenges { challenge := []byte(test.challenges[j]) expected := []byte(test.responses[j+1]) + sf := test.sf[j] resp, err := test.auth.Next(challenge, true) - if err != nil { + if err != nil && !sf { t.Errorf("#%d error: %s", i, err) continue testLoop } @@ -157,7 +163,7 @@ func TestAuthLogin(t *testing.T) { // NOT OK on non-localhost, even if server says PLAIN is OK. // (We don't know that the server is the real server.) authName: "servername", - server: &ServerInfo{Name: "servername", Auth: []string{"PLAIN"}}, + server: &ServerInfo{Name: "servername", Auth: []string{"LOGIN"}}, err: "unencrypted connection", }, {