diff options
author | Carlos Tadeu Panato Junior <ctadeu@gmail.com> | 2018-03-01 12:58:35 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-01 12:58:35 +0100 |
commit | 4b5541db46d75182a7a83b1361ed785b401b9118 (patch) | |
tree | 2f2a8f985f9e88770c253196e6d8313ac3a102cf /utils/mail_test.go | |
parent | 6e024c45b50d31c20eb0d509263d3e0f888847de (diff) | |
download | chat-4b5541db46d75182a7a83b1361ed785b401b9118.tar.gz chat-4b5541db46d75182a7a83b1361ed785b401b9118.tar.bz2 chat-4b5541db46d75182a7a83b1361ed785b401b9118.zip |
[PLT-8024] Support LOGIN authentication method for SMTP (#8140)
* [PLT-8024] Support LOGIN authentication method for SMTP
* added initial unit tests
Diffstat (limited to 'utils/mail_test.go')
-rw-r--r-- | utils/mail_test.go | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/utils/mail_test.go b/utils/mail_test.go index 068c90c60..31a4f8996 100644 --- a/utils/mail_test.go +++ b/utils/mail_test.go @@ -7,6 +7,9 @@ import ( "strings" "testing" + "net/smtp" + + "github.com/mattermost/mattermost-server/model" "github.com/stretchr/testify/require" ) @@ -169,3 +172,64 @@ func TestSendMailUsingConfig(t *testing.T) { } } }*/ + +func TestAuthMethods(t *testing.T) { + config := model.Config{ + EmailSettings: model.EmailSettings{ + EnableSMTPAuth: model.NewBool(false), + SMTPUsername: "test", + SMTPPassword: "fakepass", + SMTPServer: "fakeserver", + SMTPPort: "25", + }, + } + + auth := &authChooser{Config: &config} + tests := []struct { + desc string + server *smtp.ServerInfo + err string + }{ + { + desc: "auth PLAIN success", + server: &smtp.ServerInfo{Name: "fakeserver:25", Auth: []string{"PLAIN"}, TLS: true}, + }, + { + desc: "auth PLAIN unencrypted connection fail", + server: &smtp.ServerInfo{Name: "fakeserver:25", Auth: []string{"PLAIN"}, TLS: false}, + err: "unencrypted connection", + }, + { + desc: "auth PLAIN wrong host name", + server: &smtp.ServerInfo{Name: "wrongServer:999", Auth: []string{"PLAIN"}, TLS: true}, + err: "wrong host name", + }, + { + desc: "auth LOGIN success", + server: &smtp.ServerInfo{Name: "fakeserver:25", Auth: []string{"LOGIN"}, TLS: true}, + }, + { + desc: "auth LOGIN unencrypted connection fail", + server: &smtp.ServerInfo{Name: "wrongServer:999", Auth: []string{"LOGIN"}, TLS: true}, + err: "wrong host name", + }, + { + desc: "auth LOGIN wrong host name", + server: &smtp.ServerInfo{Name: "fakeserver:25", Auth: []string{"LOGIN"}, TLS: false}, + err: "unencrypted connection", + }, + } + + for i, test := range tests { + t.Run(test.desc, func(t *testing.T) { + _, _, err := auth.Start(test.server) + got := "" + if err != nil { + got = err.Error() + } + if got != test.err { + t.Errorf("%d. got error = %q; want %q", i, got, test.err) + } + }) + } +} |