diff options
author | Christopher Speller <crspeller@gmail.com> | 2017-03-13 12:54:22 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-13 12:54:22 -0400 |
commit | c281ee3b61e8ab53ff118866d72618ae8cce582b (patch) | |
tree | 776e7bdf6c8bfbb9a1dee5976496ab065959991f /vendor/gopkg.in/gomail.v2/auth_test.go | |
parent | 3ada7a41a7fb13abef19dd63dc56b720900dbaa9 (diff) | |
download | chat-c281ee3b61e8ab53ff118866d72618ae8cce582b.tar.gz chat-c281ee3b61e8ab53ff118866d72618ae8cce582b.tar.bz2 chat-c281ee3b61e8ab53ff118866d72618ae8cce582b.zip |
Updating server dependancies. Also adding github.com/jaytaylor/html2text and gopkg.in/gomail.v2 (#5748)
Diffstat (limited to 'vendor/gopkg.in/gomail.v2/auth_test.go')
-rw-r--r-- | vendor/gopkg.in/gomail.v2/auth_test.go | 156 |
1 files changed, 156 insertions, 0 deletions
diff --git a/vendor/gopkg.in/gomail.v2/auth_test.go b/vendor/gopkg.in/gomail.v2/auth_test.go new file mode 100644 index 000000000..20b477214 --- /dev/null +++ b/vendor/gopkg.in/gomail.v2/auth_test.go @@ -0,0 +1,156 @@ +package gomail + +import ( + "net/smtp" + "testing" +) + +const ( + testUser = "user" + testPwd = "pwd" + testHost = "smtp.example.com" +) + +var testAuth = &plainAuth{ + username: testUser, + password: testPwd, + host: testHost, +} + +type plainAuthTest struct { + auths []string + challenges []string + tls bool + wantProto string + wantData []string + wantError bool +} + +func TestNoAdvertisement(t *testing.T) { + testPlainAuth(t, &plainAuthTest{ + auths: []string{}, + challenges: []string{"Username:", "Password:"}, + tls: false, + wantProto: "PLAIN", + wantError: true, + }) +} + +func TestNoAdvertisementTLS(t *testing.T) { + testPlainAuth(t, &plainAuthTest{ + auths: []string{}, + challenges: []string{"Username:", "Password:"}, + tls: true, + wantProto: "PLAIN", + wantData: []string{"\x00" + testUser + "\x00" + testPwd}, + }) +} + +func TestPlain(t *testing.T) { + testPlainAuth(t, &plainAuthTest{ + auths: []string{"PLAIN"}, + challenges: []string{"Username:", "Password:"}, + tls: false, + wantProto: "PLAIN", + wantData: []string{"\x00" + testUser + "\x00" + testPwd}, + }) +} + +func TestPlainTLS(t *testing.T) { + testPlainAuth(t, &plainAuthTest{ + auths: []string{"PLAIN"}, + challenges: []string{"Username:", "Password:"}, + tls: true, + wantProto: "PLAIN", + wantData: []string{"\x00" + testUser + "\x00" + testPwd}, + }) +} + +func TestPlainAndLogin(t *testing.T) { + testPlainAuth(t, &plainAuthTest{ + auths: []string{"PLAIN", "LOGIN"}, + challenges: []string{"Username:", "Password:"}, + tls: false, + wantProto: "PLAIN", + wantData: []string{"\x00" + testUser + "\x00" + testPwd}, + }) +} + +func TestPlainAndLoginTLS(t *testing.T) { + testPlainAuth(t, &plainAuthTest{ + auths: []string{"PLAIN", "LOGIN"}, + challenges: []string{"Username:", "Password:"}, + tls: true, + wantProto: "PLAIN", + wantData: []string{"\x00" + testUser + "\x00" + testPwd}, + }) +} + +func TestLogin(t *testing.T) { + testPlainAuth(t, &plainAuthTest{ + auths: []string{"LOGIN"}, + challenges: []string{"Username:", "Password:"}, + tls: false, + wantProto: "LOGIN", + wantData: []string{"", testUser, testPwd}, + }) +} + +func TestLoginTLS(t *testing.T) { + testPlainAuth(t, &plainAuthTest{ + auths: []string{"LOGIN"}, + challenges: []string{"Username:", "Password:"}, + tls: true, + wantProto: "LOGIN", + wantData: []string{"", testUser, testPwd}, + }) +} + +func testPlainAuth(t *testing.T, test *plainAuthTest) { + auth := &plainAuth{ + username: testUser, + password: testPwd, + host: testHost, + } + server := &smtp.ServerInfo{ + Name: testHost, + TLS: test.tls, + Auth: test.auths, + } + proto, toServer, err := auth.Start(server) + if err != nil && !test.wantError { + t.Fatalf("plainAuth.Start(): %v", err) + } + if err != nil && test.wantError { + return + } + if proto != test.wantProto { + t.Errorf("invalid protocol, got %q, want %q", proto, test.wantProto) + } + + i := 0 + got := string(toServer) + if got != test.wantData[i] { + t.Errorf("Invalid response, got %q, want %q", got, test.wantData[i]) + } + + if proto == "PLAIN" { + return + } + + for _, challenge := range test.challenges { + i++ + if i >= len(test.wantData) { + t.Fatalf("unexpected challenge: %q", challenge) + } + + toServer, err = auth.Next([]byte(challenge), true) + if err != nil { + t.Fatalf("plainAuth.Auth(): %v", err) + } + got = string(toServer) + if got != test.wantData[i] { + t.Errorf("Invalid response, got %q, want %q", got, test.wantData[i]) + } + } +} |