From 7504df6a6e42437d566c4b0c49951e4b37a8d90b Mon Sep 17 00:00:00 2001 From: Ian Kent Date: Sun, 23 Nov 2014 15:50:49 +0000 Subject: [PATCH] Remove old tests, fix import --- MailHog-UI/main.go | 2 +- MailHog/auth_test.go | 151 ---------------------------------------- MailHog/main_test.go | 126 ---------------------------------- MailHog/mime_test.go | 159 ------------------------------------------- 4 files changed, 1 insertion(+), 437 deletions(-) delete mode 100644 MailHog/auth_test.go delete mode 100644 MailHog/main_test.go delete mode 100644 MailHog/mime_test.go diff --git a/MailHog-UI/main.go b/MailHog-UI/main.go index 8c3cebc..de7b396 100644 --- a/MailHog-UI/main.go +++ b/MailHog-UI/main.go @@ -6,7 +6,7 @@ import ( "github.com/ian-kent/Go-MailHog/MailHog-Server/config" "github.com/ian-kent/Go-MailHog/MailHog-UI/assets" - "github.com/ian-kent/Go-MailHog/MailHog-UI/http/web" + "github.com/ian-kent/Go-MailHog/MailHog-UI/web" "github.com/ian-kent/Go-MailHog/http" "github.com/ian-kent/go-log/log" gotcha "github.com/ian-kent/gotcha/app" diff --git a/MailHog/auth_test.go b/MailHog/auth_test.go deleted file mode 100644 index 5f787b4..0000000 --- a/MailHog/auth_test.go +++ /dev/null @@ -1,151 +0,0 @@ -package main - -import ( - "github.com/stretchr/testify/assert" - "net" - "testing" -) - -// FIXME requires a running instance of MailHog -// FIXME clean up tests, repeated conn.Read(buf) is a mess - -func TestBasicSMTPAuth(t *testing.T) { - buf := make([]byte, 1024) - - // Open a connection - conn, err := net.Dial("tcp", "127.0.0.1:1025") - assert.Nil(t, err) - - // Read the greeting - n, err := conn.Read(buf) - assert.Nil(t, err) - assert.Equal(t, string(buf[0:n]), "220 mailhog.example ESMTP Go-MailHog\n") - - // Send EHLO - _, err = conn.Write([]byte("EHLO localhost\r\n")) - assert.Nil(t, err) - - // Read the response - n, err = conn.Read(buf) - assert.Nil(t, err) - assert.Equal(t, string(buf[0:n]), "250-Hello localhost\n") - n, err = conn.Read(buf) - assert.Nil(t, err) - assert.Equal(t, string(buf[0:n]), "250-PIPELINING\n") - n, err = conn.Read(buf) - assert.Nil(t, err) - assert.Equal(t, string(buf[0:n]), "250 AUTH EXTERNAL CRAM-MD5 LOGIN PLAIN\n") - - // Send AUTH - _, err = conn.Write([]byte("AUTH EXTERNAL =\r\n")) - assert.Nil(t, err) - - // Read the response - n, err = conn.Read(buf) - assert.Nil(t, err) - assert.Equal(t, string(buf[0:n]), "235 Authentication successful\n") - - // Send RSET and EHLO - _, err = conn.Write([]byte("RSET\r\n")) - n, err = conn.Read(buf) - _, err = conn.Write([]byte("EHLO localhost\r\n")) - n, err = conn.Read(buf) - n, err = conn.Read(buf) - n, err = conn.Read(buf) - - // Send AUTH - _, err = conn.Write([]byte("AUTH PLAIN foobar\r\n")) - assert.Nil(t, err) - - // Read the response - n, err = conn.Read(buf) - assert.Nil(t, err) - assert.Equal(t, string(buf[0:n]), "235 Authentication successful\n") - - // Send RSET and EHLO - _, err = conn.Write([]byte("RSET\r\n")) - n, err = conn.Read(buf) - _, err = conn.Write([]byte("EHLO localhost\r\n")) - n, err = conn.Read(buf) - n, err = conn.Read(buf) - n, err = conn.Read(buf) - - // Send AUTH - _, err = conn.Write([]byte("AUTH PLAIN\r\n")) - assert.Nil(t, err) - - // Read the response - n, err = conn.Read(buf) - assert.Nil(t, err) - assert.Equal(t, string(buf[0:n]), "334 \n") - - // Send AUTH - _, err = conn.Write([]byte("foobar\r\n")) - assert.Nil(t, err) - - // Read the response - n, err = conn.Read(buf) - assert.Nil(t, err) - assert.Equal(t, string(buf[0:n]), "235 Authentication successful\n") - - // Send RSET and EHLO - _, err = conn.Write([]byte("RSET\r\n")) - n, err = conn.Read(buf) - _, err = conn.Write([]byte("EHLO localhost\r\n")) - n, err = conn.Read(buf) - n, err = conn.Read(buf) - n, err = conn.Read(buf) - - // Send AUTH - _, err = conn.Write([]byte("AUTH LOGIN\r\n")) - assert.Nil(t, err) - - // Read the response - n, err = conn.Read(buf) - assert.Nil(t, err) - assert.Equal(t, string(buf[0:n]), "334 VXNlcm5hbWU6\n") - - // Send AUTH - _, err = conn.Write([]byte("foobar\r\n")) - assert.Nil(t, err) - - // Read the response - n, err = conn.Read(buf) - assert.Nil(t, err) - assert.Equal(t, string(buf[0:n]), "334 UGFzc3dvcmQ6\n") - - // Send AUTH - _, err = conn.Write([]byte("foobar\r\n")) - assert.Nil(t, err) - - // Read the response - n, err = conn.Read(buf) - assert.Nil(t, err) - assert.Equal(t, string(buf[0:n]), "235 Authentication successful\n") - - // Send RSET and EHLO - _, err = conn.Write([]byte("RSET\r\n")) - n, err = conn.Read(buf) - _, err = conn.Write([]byte("EHLO localhost\r\n")) - n, err = conn.Read(buf) - n, err = conn.Read(buf) - n, err = conn.Read(buf) - - // Send AUTH - _, err = conn.Write([]byte("AUTH CRAM-MD5\r\n")) - assert.Nil(t, err) - - // Read the response - n, err = conn.Read(buf) - assert.Nil(t, err) - assert.Equal(t, string(buf[0:n]), "334 PDQxOTI5NDIzNDEuMTI4Mjg0NzJAc291cmNlZm91ci5hbmRyZXcuY211LmVkdT4=\n") - - // Send AUTH - _, err = conn.Write([]byte("foobar\r\n")) - assert.Nil(t, err) - - // Read the response - n, err = conn.Read(buf) - assert.Nil(t, err) - assert.Equal(t, string(buf[0:n]), "235 Authentication successful\n") -} diff --git a/MailHog/main_test.go b/MailHog/main_test.go deleted file mode 100644 index 8c8b459..0000000 --- a/MailHog/main_test.go +++ /dev/null @@ -1,126 +0,0 @@ -package main - -import ( - "net" - "regexp" - "strings" - "testing" - - "github.com/ian-kent/Go-MailHog/config" - "github.com/ian-kent/Go-MailHog/storage" - "github.com/stretchr/testify/assert" -) - -// FIXME requires a running instance of MailHog - -func TestBasicHappyPath(t *testing.T) { - buf := make([]byte, 1024) - - // Open a connection - conn, err := net.Dial("tcp", "127.0.0.1:1025") - assert.Nil(t, err) - - // Read the greeting - n, err := conn.Read(buf) - assert.Nil(t, err) - assert.Equal(t, string(buf[0:n]), "220 mailhog.example ESMTP Go-MailHog\n") - - // Send EHLO - _, err = conn.Write([]byte("EHLO localhost\r\n")) - assert.Nil(t, err) - - // Read the response - n, err = conn.Read(buf) - assert.Nil(t, err) - assert.Equal(t, string(buf[0:n]), "250-Hello localhost\n") - n, err = conn.Read(buf) - assert.Nil(t, err) - assert.Equal(t, string(buf[0:n]), "250-PIPELINING\n") - n, err = conn.Read(buf) - assert.Nil(t, err) - assert.Equal(t, string(buf[0:n]), "250 AUTH EXTERNAL CRAM-MD5 LOGIN PLAIN\n") - - // Send MAIL - _, err = conn.Write([]byte("MAIL From:\r\n")) - assert.Nil(t, err) - - // Read the response - n, err = conn.Read(buf) - assert.Nil(t, err) - assert.Equal(t, string(buf[0:n]), "250 Sender nobody@mailhog.example ok\n") - - // Send RCPT - _, err = conn.Write([]byte("RCPT To:\r\n")) - assert.Nil(t, err) - - // Read the response - n, err = conn.Read(buf) - assert.Nil(t, err) - assert.Equal(t, string(buf[0:n]), "250 Recipient someone@mailhog.example ok\n") - - // Send DATA - _, err = conn.Write([]byte("DATA\r\n")) - assert.Nil(t, err) - - // Read the response - n, err = conn.Read(buf) - assert.Nil(t, err) - assert.Equal(t, string(buf[0:n]), "354 End data with .\n") - - // Send the message - content := "Content-Type: text/plain\r\n" - content += "Content-Length: 220\r\n" - content += "From: Nobody \r\n" - content += "To: Someone \r\n" - content += "Subject: Example message\r\n" - content += "\r\n" - content += "Hi there :)\r\n" - content += ".\r\n" - _, err = conn.Write([]byte(content)) - assert.Nil(t, err) - - // Read the response - n, err = conn.Read(buf) - assert.Nil(t, err) - r, _ := regexp.Compile("250 Ok: queued as ([0-9a-f]+)\n") - match := r.FindStringSubmatch(string(buf[0:n])) - assert.NotNil(t, match) - - // Send QUIT - _, err = conn.Write([]byte("QUIT\r\n")) - assert.Nil(t, err) - - // Read the response - n, err = conn.Read(buf) - assert.Nil(t, err) - assert.Equal(t, string(buf[0:n]), "221 Bye\n") - - s := storage.CreateMongoDB(config.DefaultConfig()) - message, err := s.Load(match[1]) - assert.Nil(t, err) - assert.NotNil(t, message) - - assert.Equal(t, message.From.Domain, "mailhog.example", "sender domain is mailhog.example") - assert.Equal(t, message.From.Mailbox, "nobody", "sender mailbox is nobody") - assert.Equal(t, message.From.Params, "", "sender params is empty") - assert.Equal(t, len(message.From.Relays), 0, "sender has no relays") - - assert.Equal(t, len(message.To), 1, "message has 1 recipient") - - assert.Equal(t, message.To[0].Domain, "mailhog.example", "recipient domain is mailhog.example") - assert.Equal(t, message.To[0].Mailbox, "someone", "recipient mailbox is someone") - assert.Equal(t, message.To[0].Params, "", "recipient params is empty") - assert.Equal(t, len(message.To[0].Relays), 0, "recipient has no relays") - - assert.Equal(t, len(message.Content.Headers), 8, "message has 7 headers") - assert.Equal(t, message.Content.Headers["Content-Type"], []string{"text/plain"}, "Content-Type header is text/plain") - assert.Equal(t, message.Content.Headers["Subject"], []string{"Example message"}, "Subject header is Example message") - assert.Equal(t, message.Content.Headers["Content-Length"], []string{"220"}, "Content-Length is 220") - assert.Equal(t, message.Content.Headers["To"], []string{"Someone "}, "To is Someone ") - assert.Equal(t, message.Content.Headers["From"], []string{"Nobody "}, "From is Nobody ") - assert.True(t, strings.HasPrefix(message.Content.Headers["Received"][0], "from localhost by mailhog.example (Go-MailHog)\r\n id "+match[1]+"@mailhog.example; "), "Received header is correct") - assert.Equal(t, message.Content.Headers["Return-Path"], []string{""}, "Return-Path is ") - assert.Equal(t, message.Content.Headers["Message-ID"], []string{match[1] + "@mailhog.example"}, "Message-ID is "+match[1]+"@mailhog.example") - - assert.Equal(t, message.Content.Body, "Hi there :)", "message has correct body") -} diff --git a/MailHog/mime_test.go b/MailHog/mime_test.go deleted file mode 100644 index 456dca4..0000000 --- a/MailHog/mime_test.go +++ /dev/null @@ -1,159 +0,0 @@ -package main - -import ( - "github.com/ian-kent/Go-MailHog/mailhog/config" - "github.com/ian-kent/Go-MailHog/mailhog/storage" - "github.com/stretchr/testify/assert" - "net" - "regexp" - "strings" - "testing" -) - -// FIXME requires a running instance of MailHog - -func TestBasicMIMEHappyPath(t *testing.T) { - buf := make([]byte, 1024) - - // Open a connection - conn, err := net.Dial("tcp", "127.0.0.1:1025") - assert.Nil(t, err) - - // Read the greeting - n, err := conn.Read(buf) - assert.Nil(t, err) - assert.Equal(t, string(buf[0:n]), "220 mailhog.example ESMTP Go-MailHog\n") - - // Send EHLO - _, err = conn.Write([]byte("EHLO localhost\r\n")) - assert.Nil(t, err) - - // Read the response - n, err = conn.Read(buf) - assert.Nil(t, err) - assert.Equal(t, string(buf[0:n]), "250-Hello localhost\n") - n, err = conn.Read(buf) - assert.Nil(t, err) - assert.Equal(t, string(buf[0:n]), "250-PIPELINING\n") - n, err = conn.Read(buf) - assert.Nil(t, err) - assert.Equal(t, string(buf[0:n]), "250 AUTH EXTERNAL CRAM-MD5 LOGIN PLAIN\n") - - // Send MAIL - _, err = conn.Write([]byte("MAIL From:\r\n")) - assert.Nil(t, err) - - // Read the response - n, err = conn.Read(buf) - assert.Nil(t, err) - assert.Equal(t, string(buf[0:n]), "250 Sender nobody@mailhog.example ok\n") - - // Send RCPT - _, err = conn.Write([]byte("RCPT To:\r\n")) - assert.Nil(t, err) - - // Read the response - n, err = conn.Read(buf) - assert.Nil(t, err) - assert.Equal(t, string(buf[0:n]), "250 Recipient someone@mailhog.example ok\n") - - // Send DATA - _, err = conn.Write([]byte("DATA\r\n")) - assert.Nil(t, err) - - // Read the response - n, err = conn.Read(buf) - assert.Nil(t, err) - assert.Equal(t, string(buf[0:n]), "354 End data with .\n") - - // Send the message - content := "Content-Type: multipart/alternative; boundary=\"--mailhog-test-boundary\"\r\n" - content += "Content-Length: 220\r\n" - content += "From: Nobody \r\n" - content += "To: Someone \r\n" - content += "Subject: Example message\r\n" - content += "MIME-Version: 1.0\r\n" - content += "\r\n" - content += "----mailhog-test-boundary\r\n" - content += "Content-Type: text/plain\r\n" - content += "\r\n" - content += "Hi there :)\r\n" - content += "----mailhog-test-boundary\r\n" - content += "Content-Type: text/html\r\n" - content += "\r\n" - content += "\r\n" - content += " \r\n" - content += " Example message\r\n" - content += " \r\n" - content += " \r\n" - content += "

\r\n" - content += " Hi there :)\r\n" - content += "

\r\n" - content += " \r\n" - content += "\r\n" - content += "----mailhog-test-boundary\r\n" - content += ".\r\n" - _, err = conn.Write([]byte(content)) - assert.Nil(t, err) - - // Read the response - n, err = conn.Read(buf) - assert.Nil(t, err) - r, _ := regexp.Compile("250 Ok: queued as ([0-9a-f]+)\n") - match := r.FindStringSubmatch(string(buf[0:n])) - assert.NotNil(t, match) - - // Send QUIT - _, err = conn.Write([]byte("QUIT\r\n")) - assert.Nil(t, err) - - // Read the response - n, err = conn.Read(buf) - assert.Nil(t, err) - assert.Equal(t, string(buf[0:n]), "221 Bye\n") - - s := storage.CreateMongoDB(config.DefaultConfig()) - message, err := s.Load(match[1]) - assert.Nil(t, err) - assert.NotNil(t, message) - - assert.Equal(t, message.From.Domain, "mailhog.example", "sender domain is mailhog.example") - assert.Equal(t, message.From.Mailbox, "nobody", "sender mailbox is nobody") - assert.Equal(t, message.From.Params, "", "sender params is empty") - assert.Equal(t, len(message.From.Relays), 0, "sender has no relays") - - assert.Equal(t, len(message.To), 1, "message has 1 recipient") - - assert.Equal(t, message.To[0].Domain, "mailhog.example", "recipient domain is mailhog.example") - assert.Equal(t, message.To[0].Mailbox, "someone", "recipient mailbox is someone") - assert.Equal(t, message.To[0].Params, "", "recipient params is empty") - assert.Equal(t, len(message.To[0].Relays), 0, "recipient has no relays") - - assert.Equal(t, len(message.Content.Headers), 9, "message has 7 headers") - assert.Equal(t, message.Content.Headers["Content-Type"], []string{"multipart/alternative; boundary=\"--mailhog-test-boundary\""}, "Content-Type header is multipart/alternative; boundary=\"--mailhog-test-boundary\"") - assert.Equal(t, message.Content.Headers["Subject"], []string{"Example message"}, "Subject header is Example message") - assert.Equal(t, message.Content.Headers["Content-Length"], []string{"220"}, "Content-Length is 220") - assert.Equal(t, message.Content.Headers["To"], []string{"Someone "}, "To is Someone ") - assert.Equal(t, message.Content.Headers["From"], []string{"Nobody "}, "From is Nobody ") - assert.True(t, strings.HasPrefix(message.Content.Headers["Received"][0], "from localhost by mailhog.example (Go-MailHog)\r\n id "+match[1]+"@mailhog.example; "), "Received header is correct") - assert.Equal(t, message.Content.Headers["Return-Path"], []string{""}, "Return-Path is ") - assert.Equal(t, message.Content.Headers["Message-ID"], []string{match[1] + "@mailhog.example"}, "Message-ID is "+match[1]+"@mailhog.example") - - expected := "----mailhog-test-boundary\r\nContent-Type: text/plain\r\n\r\nHi there :)\r\n----mailhog-test-boundary\r\nContent-Type: text/html\r\n\r\n\r\n \r\n Example message\r\n \r\n \r\n

\r\n Hi there :)\r\n

\r\n \r\n\r\n----mailhog-test-boundary" - assert.Equal(t, message.Content.Body, expected, "message has correct body") - - assert.NotNil(t, message.MIME) - assert.Equal(t, len(message.MIME.Parts), 2) - - plain := message.MIME.Parts[0] - assert.NotNil(t, plain) - assert.Equal(t, plain.Headers["Content-Type"], []string{"text/plain"}, "Content-Type header is text/plain") - assert.Equal(t, plain.Body, "Hi there :)", "plain text body is correct") - - html := message.MIME.Parts[1] - assert.NotNil(t, html) - assert.Equal(t, html.Headers["Content-Type"], []string{"text/html"}, "Content-Type header is text/html") - expected = "\r\n \r\n Example message\r\n \r\n \r\n

\r\n Hi there :)\r\n

\r\n \r\n" - assert.Equal(t, html.Body, expected, "html body is correct") - -}