From 55081fa59b7bb671f8d633b4b5c006b2b94bfb96 Mon Sep 17 00:00:00 2001 From: Gjorgji Slamkov Date: Fri, 23 Jun 2023 06:45:31 +0000 Subject: [PATCH] test(GODT-2636): Add step for sending from EML --- tests/bdd_test.go | 1 + tests/features/imap/message/import.feature | 6 +- tests/features/smtp/send/html.feature | 31 +++++++++ tests/features/smtp/send/plain_att.feature | 31 +++++++++ tests/smtp_test.go | 57 ++++++++++----- .../html/foreign_ascii_subject_body.eml | 15 ++++ .../{ => plain}/text_plain_latin1.eml | 0 .../plain/text_plain_multiple_attachments.eml | 69 +++++++++++++++++++ .../{ => plain}/text_plain_unknown_latin1.eml | 0 .../{ => plain}/text_plain_wrong_latin1.eml | 0 10 files changed, 189 insertions(+), 21 deletions(-) create mode 100644 tests/testdata/html/foreign_ascii_subject_body.eml rename tests/testdata/{ => plain}/text_plain_latin1.eml (100%) create mode 100644 tests/testdata/plain/text_plain_multiple_attachments.eml rename tests/testdata/{ => plain}/text_plain_unknown_latin1.eml (100%) rename tests/testdata/{ => plain}/text_plain_wrong_latin1.eml (100%) diff --git a/tests/bdd_test.go b/tests/bdd_test.go index d0edb003..b9a814c7 100644 --- a/tests/bdd_test.go +++ b/tests/bdd_test.go @@ -246,6 +246,7 @@ func TestFeatures(testingT *testing.T) { ctx.Step(`^SMTP client "([^"]*)" sends DATA:$`, s.smtpClientSendsData) ctx.Step(`^SMTP client "([^"]*)" sends RSET$`, s.smtpClientSendsReset) ctx.Step(`^SMTP client "([^"]*)" sends the following message from "([^"]*)" to "([^"]*)":$`, s.smtpClientSendsTheFollowingMessageFromTo) + ctx.Step(`^SMTP client "([^"]*)" sends the following EML "([^"]*)" from "([^"]*)" to "([^"]*)"$`, s.smtpClientSendsTheFollowingEmlFromTo) ctx.Step(`^SMTP client "([^"]*)" logs out$`, s.smtpClientLogsOut) // ==== TELEMETRY ==== diff --git a/tests/features/imap/message/import.feature b/tests/features/imap/message/import.feature index c6da3e7b..f264287b 100644 --- a/tests/features/imap/message/import.feature +++ b/tests/features/imap/message/import.feature @@ -73,7 +73,7 @@ Feature: IMAP import messages # The message is imported as UTF-8 and the content type is determined at build time. Scenario: Import message as latin1 without content type - When IMAP client "1" appends "text_plain_unknown_latin1.eml" to "INBOX" + When IMAP client "1" appends "plain/text_plain_unknown_latin1.eml" to "INBOX" Then it succeeds And IMAP client "1" eventually sees the following messages in "INBOX": | from | to | body | @@ -81,7 +81,7 @@ Feature: IMAP import messages # The message is imported and the body is converted to UTF-8. Scenario: Import message as latin1 with content type - When IMAP client "1" appends "text_plain_latin1.eml" to "INBOX" + When IMAP client "1" appends "plain/text_plain_latin1.eml" to "INBOX" Then it succeeds And IMAP client "1" eventually sees the following messages in "INBOX": | from | to | body | @@ -89,7 +89,7 @@ Feature: IMAP import messages # The message is imported anad the body is wrongly converted (body is corrupted). Scenario: Import message as latin1 with wrong content type - When IMAP client "1" appends "text_plain_wrong_latin1.eml" to "INBOX" + When IMAP client "1" appends "plain/text_plain_wrong_latin1.eml" to "INBOX" Then it succeeds And IMAP client "1" eventually sees the following messages in "INBOX": | from | to | diff --git a/tests/features/smtp/send/html.feature b/tests/features/smtp/send/html.feature index 5f2d28ea..99455030 100644 --- a/tests/features/smtp/send/html.feature +++ b/tests/features/smtp/send/html.feature @@ -343,3 +343,34 @@ Feature: SMTP sending of plain messages } } """ + + Scenario: HTML message with Foreign/Nonascii chars in Subject and Body + When there exists an account with username "bridgetest" and password "password" + And the user logs in with username "bridgetest" and password "password" + And user "bridgetest" connects and authenticates SMTP client "1" + And SMTP client "1" sends the following EML "html/foreign_ascii_subject_body.eml" from "bridgetest@proton.local" to "pm.bridge.qa@gmail.com" + Then it succeeds + When user "bridgetest" connects and authenticates IMAP client "1" + Then IMAP client "1" eventually sees the following messages in "Sent": + | from | to | subject | + | bridgetest@proton.local | pm.bridge.qa@gmail.com | Subjεέςτ ¶ Ä È | + And the body in the "POST" request to "/mail/v4/messages" is: + """ + { + "Message": { + "Subject": "Subjεέςτ ¶ Ä È", + "Sender": { + "Name": "Bridge Test" + }, + "ToList": [ + { + "Address": "pm.bridge.qa@gmail.com", + "Name": "External Bridge" + } + ], + "CCList": [], + "BCCList": [], + "MIMEType": "text/html" + } + } + """ diff --git a/tests/features/smtp/send/plain_att.feature b/tests/features/smtp/send/plain_att.feature index 009e6d8c..63a48442 100644 --- a/tests/features/smtp/send/plain_att.feature +++ b/tests/features/smtp/send/plain_att.feature @@ -193,3 +193,34 @@ Feature: SMTP sending of plain messages } } """ + + Scenario: Basic message with multiple different attachments to internal account + When there exists an account with username "bridgetest" and password "password" + And the user logs in with username "bridgetest" and password "password" + And user "bridgetest" connects and authenticates SMTP client "1" + And SMTP client "1" sends the following EML "plain/text_plain_multiple_attachments.eml" from "bridgetest@proton.local" to "internalbridgetest@proton.local" + Then it succeeds + When user "bridgetest" connects and authenticates IMAP client "1" + Then IMAP client "1" eventually sees the following messages in "Sent": + | from | to | subject | + | bridgetest@proton.local | internalbridgetest@proton.local | Plain with multiple different attachments | + And the body in the "POST" request to "/mail/v4/messages" is: + """ + { + "Message": { + "Subject": "Plain with multiple different attachments", + "Sender": { + "Name": "Bridge Test" + }, + "ToList": [ + { + "Address": "internalbridgetest@proton.local", + "Name": "Internal Bridge" + } + ], + "CCList": [], + "BCCList": [], + "MIMEType": "text/plain" + } + } + """ diff --git a/tests/smtp_test.go b/tests/smtp_test.go index 430b83af..c5d48f66 100644 --- a/tests/smtp_test.go +++ b/tests/smtp_test.go @@ -20,6 +20,8 @@ package tests import ( "fmt" "net/smtp" + "os" + "path/filepath" "strings" "github.com/ProtonMail/proton-bridge/v3/internal/constants" @@ -132,28 +134,24 @@ func (s *scenario) smtpClientSendsReset(clientID string) error { func (s *scenario) smtpClientSendsTheFollowingMessageFromTo(clientID, from, to string, message *godog.DocString) error { _, client := s.t.getSMTPClient(clientID) - s.t.pushError(func() error { - if err := client.Mail(from); err != nil { - return err - } + if err := clientSend(client, from, to, message.Content); err != nil { + s.t.pushError(err) + } - for _, to := range strings.Split(to, ", ") { - if err := client.Rcpt(to); err != nil { - return err - } - } + return nil +} - wc, err := client.Data() - if err != nil { - return err - } +func (s *scenario) smtpClientSendsTheFollowingEmlFromTo(clientID, file, from, to string) error { + _, client := s.t.getSMTPClient(clientID) - if _, err := wc.Write([]byte(message.Content)); err != nil { - return err - } + b, err := os.ReadFile(filepath.Join("testdata", file)) + if err != nil { + return err + } - return wc.Close() - }()) + if err := clientSend(client, from, to, string(b)); err != nil { + s.t.pushError(err) + } return nil } @@ -165,3 +163,26 @@ func (s *scenario) smtpClientLogsOut(clientID string) error { return nil } + +func clientSend(client *smtp.Client, from, to, message string) error { + if err := client.Mail(from); err != nil { + return err + } + + for _, to := range strings.Split(to, ", ") { + if err := client.Rcpt(to); err != nil { + return err + } + } + + wc, err := client.Data() + if err != nil { + return err + } + + if _, err := wc.Write([]byte(message)); err != nil { + return err + } + + return wc.Close() +} diff --git a/tests/testdata/html/foreign_ascii_subject_body.eml b/tests/testdata/html/foreign_ascii_subject_body.eml new file mode 100644 index 00000000..113bfd57 --- /dev/null +++ b/tests/testdata/html/foreign_ascii_subject_body.eml @@ -0,0 +1,15 @@ +From: Bridge Test +To: External Bridge +Subject: =?UTF-8?B?U3Vias61zq3Pgs+EIMK2IMOEIMOI?= +Content-Type: text/html; charset=UTF-8 +Content-Transfer-Encoding: 8bit + + + + + + + + Subjεέςτ ¶ Ä È + + diff --git a/tests/testdata/text_plain_latin1.eml b/tests/testdata/plain/text_plain_latin1.eml similarity index 100% rename from tests/testdata/text_plain_latin1.eml rename to tests/testdata/plain/text_plain_latin1.eml diff --git a/tests/testdata/plain/text_plain_multiple_attachments.eml b/tests/testdata/plain/text_plain_multiple_attachments.eml new file mode 100644 index 00000000..f4b1bb3c --- /dev/null +++ b/tests/testdata/plain/text_plain_multiple_attachments.eml @@ -0,0 +1,69 @@ +From: Bridge Test +To: Internal Bridge +Subject: Plain with multiple different attachments +Content-Type: multipart/mixed; boundary="bc5bd30245232f31b6c976adcd59bb0069c9b13f986f9e40c2571bb80aa16606" + +--bc5bd30245232f31b6c976adcd59bb0069c9b13f986f9e40c2571bb80aa16606 +Content-Type: text/plain; charset=UTF-8; format=flowed +Content-Transfer-Encoding: 7bit + +Body of plain text message with multiple attachments + +--bc5bd30245232f31b6c976adcd59bb0069c9b13f986f9e40c2571bb80aa16606 +Content-Type: application/zip; name="PINProtected.zip" +Content-Disposition: attachment; filename="PINProtected.zip" +Content-Transfer-Encoding: base64 + +UEsDBBQACAAIAHhlwVYAAAAAAAAAABADAAAMACAAbWVzc2FnZTIudHh0VVQNAAdkdnhk7nZ4 +AABQSwUGAAAAAAIAAgC/AAAAewMAAAAA + +--bc5bd30245232f31b6c976adcd59bb0069c9b13f986f9e40c2571bb80aa16606 +Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document; name="test.docx" +Content-Disposition: attachment; filename="test.docx" +Content-Transfer-Encoding: base64 + +UEsDBBQABgAIAAAAIQDfpNJsWgEAACAFAAATAAgCW0NvbnRlbnRfVHlwZXNdLnhtbCCiBAIo +AAAAgB4AAHdvcmQvc3R5bGVzLnhtbFBLBQYAAAAACwALAMECAADXKQAAAAA= + +--bc5bd30245232f31b6c976adcd59bb0069c9b13f986f9e40c2571bb80aa16606 +Content-Type: application/pdf; name="test.pdf" +Content-Disposition: attachment; filename="test.pdf" +Content-Transfer-Encoding: base64 + +JVBERi0xLjUKJeLjz9MKNyAwIG9iago8PAovVHlwZSAvRm9udERlc2NyaXB0b3IKL0ZvbnRO +MjM0NAolJUVPRgo= + +--bc5bd30245232f31b6c976adcd59bb0069c9b13f986f9e40c2571bb80aa16606 +Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; name="test.xlsx" +Content-Disposition: attachment; filename="test.xlsx" +Content-Transfer-Encoding: base64 + +UEsDBBQABgAIAAAAIQBi7p1oXgEAAJAEAAATAAgCW0NvbnRlbnRfVHlwZXNdLnhtbCCiBAIo +AAoACgCAAgAAexwAAAAA + +--bc5bd30245232f31b6c976adcd59bb0069c9b13f986f9e40c2571bb80aa16606 +Content-Type: text/xml; charset=UTF-8; name="testxml.xml" +Content-Disposition: attachment; filename="testxml.xml" +Content-Transfer-Encoding: base64 + +PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPCFET0NUWVBFIHN1aXRl +VUtUZXN0Ii8+CiAgICAgICAgPC9jbGFzc2VzPgogICAgPC90ZXN0PgoKPC9zdWl0ZT4= + +--bc5bd30245232f31b6c976adcd59bb0069c9b13f986f9e40c2571bb80aa16606 +Content-Type: text/plain; charset=UTF-8; name="update.txt" +Content-Disposition: attachment; filename="update.txt" +Content-Transfer-Encoding: base64 + +DQpHb2NlQERFU0tUT1AtQ0dONkZENiBNSU5HVzY0IC9jL1Byb2dyYW0gRmlsZXMvUHJvdG9u +NFdqRUw5WkplbnJZcUZucXVvSFBEa0w5VWZFeTA0VlBYRkViVERWLVlQaS1BSWc9PSINCg== + +--bc5bd30245232f31b6c976adcd59bb0069c9b13f986f9e40c2571bb80aa16606 +Content-Type: text/calendar; charset=UTF-8; name="=?UTF-8?B?6YCZ5piv5ryi5a2X55qE5LiA5YCL5L6L5a2QLmljcw==?=" +Content-Disposition: attachment; filename*0*=UTF-8''%E9%80%99%E6%98%AF%E6%BC%A2%E5%AD%97%E7%9A%84%E4%B8%80; filename*1*=%E5%80%8B%E4%BE%8B%E5%AD%90%2E%69%63%73 +Content-Transfer-Encoding: base64 + +QkVHSU46VkNBTEVOREFSCk1FVEhPRDpQVUJMSVNIClZFUlNJT046Mi4wClgtV1ItQ0FMTkFN +RDpWQUxBUk0KRU5EOlZFVkVOVApFTkQ6VkNBTEVOREFSCg== + +--bc5bd30245232f31b6c976adcd59bb0069c9b13f986f9e40c2571bb80aa16606-- + diff --git a/tests/testdata/text_plain_unknown_latin1.eml b/tests/testdata/plain/text_plain_unknown_latin1.eml similarity index 100% rename from tests/testdata/text_plain_unknown_latin1.eml rename to tests/testdata/plain/text_plain_unknown_latin1.eml diff --git a/tests/testdata/text_plain_wrong_latin1.eml b/tests/testdata/plain/text_plain_wrong_latin1.eml similarity index 100% rename from tests/testdata/text_plain_wrong_latin1.eml rename to tests/testdata/plain/text_plain_wrong_latin1.eml