From 219400de8daf4777d9e8ca3e26c967333f83dcb4 Mon Sep 17 00:00:00 2001 From: Romain Le Jeune Date: Thu, 2 Feb 2023 15:25:27 +0000 Subject: [PATCH] test(GODT-2298): add integration test for In-Reply-To header use cases. --- tests/ctx_helper_test.go | 2 + tests/features/smtp/send/bcc.feature | 1 + .../smtp/send/embedded_message.feature | 1 + .../smtp/send/one_account_to_another.feature | 4 + tests/features/smtp/send/same_message.feature | 2 + tests/features/smtp/send/send_reply.feature | 153 ++++++++++++++++++ tests/types_test.go | 23 ++- 7 files changed, 185 insertions(+), 1 deletion(-) create mode 100644 tests/features/smtp/send/send_reply.feature diff --git a/tests/ctx_helper_test.go b/tests/ctx_helper_test.go index 510c7309..4bf0103c 100644 --- a/tests/ctx_helper_test.go +++ b/tests/ctx_helper_test.go @@ -20,6 +20,7 @@ package tests import ( "context" "fmt" + "os" "runtime" "github.com/ProtonMail/go-proton-api" @@ -33,6 +34,7 @@ func (t *testCtx) withProton(fn func(*proton.Manager) error) error { proton.WithHostURL(t.api.GetHostURL()), proton.WithTransport(proton.InsecureTransport()), proton.WithAppVersion(t.api.GetAppVersion()), + proton.WithDebug(os.Getenv("FEATURE_API_DEBUG") != ""), ) defer m.Close() diff --git a/tests/features/smtp/send/bcc.feature b/tests/features/smtp/send/bcc.feature index ec8d41e6..a41f60da 100644 --- a/tests/features/smtp/send/bcc.feature +++ b/tests/features/smtp/send/bcc.feature @@ -45,6 +45,7 @@ Feature: SMTP with bcc """ + @long-black Scenario: Send message only to bcc When SMTP client "1" sends the following message from "[user:user]@[domain]" to "[user:bcc]@[domain]": """ diff --git a/tests/features/smtp/send/embedded_message.feature b/tests/features/smtp/send/embedded_message.feature index 38154a39..3ab685c9 100644 --- a/tests/features/smtp/send/embedded_message.feature +++ b/tests/features/smtp/send/embedded_message.feature @@ -7,6 +7,7 @@ Feature: SMTP sending embedded message And the user logs in with username "[user:to]" and password "password" And user "[user:user]" connects and authenticates SMTP client "1" + @long-black Scenario: Send it When SMTP client "1" sends the following message from "[user:user]@[domain]" to "[user:to]@[domain]": """ diff --git a/tests/features/smtp/send/one_account_to_another.feature b/tests/features/smtp/send/one_account_to_another.feature index 08d1a53a..62e20587 100644 --- a/tests/features/smtp/send/one_account_to_another.feature +++ b/tests/features/smtp/send/one_account_to_another.feature @@ -6,6 +6,8 @@ Feature: SMTP sending two messages And the user logs in with username "[user:user]" and password "password" And the user logs in with username "[user:recp]" and password "password" + + @long-black Scenario: Send from one account to the other When user "[user:user]" connects and authenticates SMTP client "1" And SMTP client "1" sends the following message from "[user:user]@[domain]" to "[user:recp]@[domain]": @@ -60,6 +62,8 @@ Feature: SMTP sending two messages | from | to | subject | body | | [user:user]@[domain] | [user:recp]@[domain] | One account to the other | hello | + + @long-black Scenario: Send from one account to the other with attachments When user "[user:user]" connects and authenticates SMTP client "1" And SMTP client "1" sends the following message from "[user:user]@[domain]" to "[user:recp]@[domain]": diff --git a/tests/features/smtp/send/same_message.feature b/tests/features/smtp/send/same_message.feature index dddb810b..394b28d3 100644 --- a/tests/features/smtp/send/same_message.feature +++ b/tests/features/smtp/send/same_message.feature @@ -16,6 +16,7 @@ Feature: SMTP sending the same message twice """ And it succeeds + @long-black Scenario: The exact same message is not sent twice When SMTP client "1" sends the following message from "[user:user]@[domain]" to "[user:to]@[domain]": """ @@ -36,6 +37,7 @@ Feature: SMTP sending the same message twice | [user:user]@[domain] | [user:to]@[domain] | Hello | World | + @long-black Scenario: Slight change means different message and is sent twice When SMTP client "1" sends the following message from "[user:user]@[domain]" to "[user:to]@[domain]": """ diff --git a/tests/features/smtp/send/send_reply.feature b/tests/features/smtp/send/send_reply.feature new file mode 100644 index 00000000..47f9acf4 --- /dev/null +++ b/tests/features/smtp/send/send_reply.feature @@ -0,0 +1,153 @@ +Feature: SMTP send reply + + Background: + Given there exists an account with username "[user:user1]" and password "password" + And there exists an account with username "[user:user2]" and password "password" + And bridge starts + And the user logs in with username "[user:user1]" and password "password" + And user "[user:user1]" connects and authenticates SMTP client "1" + And user "[user:user1]" connects and authenticates IMAP client "1" + And user "[user:user1]" finishes syncing + + @long-black + Scenario: Reply with In-Reply-To but no References + # User1 send the initial message. + When SMTP client "1" sends the following message from "[user:user1]@[domain]" to "[user:user2]@[domain]": + """ + From: Bridge Test <[user:user1]@[domain]> + To: Internal Bridge <[user:user2]@[domain]> + Subject: Please Reply + Message-ID: + + hello + + """ + Then it succeeds + Then IMAP client "1" eventually sees the following messages in "Sent": + | from | to | subject | message-id | + | [user:user1]@[domain] | [user:user2]@[domain] | Please Reply | | + # login user2. + And the user logs in with username "[user:user2]" and password "password" + And user "[user:user2]" connects and authenticates IMAP client "2" + And user "[user:user2]" connects and authenticates SMTP client "2" + And user "[user:user2]" finishes syncing + # User2 receive the message. + Then IMAP client "2" eventually sees the following messages in "INBOX": + | from | subject | message-id | + | [user:user1]@[domain] | Please Reply | | + # User2 reply to it. + When SMTP client "2" sends the following message from "[user:user2]@[domain]" to "[user:user1]@[domain]": + """ + From: Internal Bridge <[user:user2]@[domain]> + To: Bridge Test <[user:user1]@[domain]> + Content-Type: text/plain + Subject: FW - Please Reply + In-Reply-To: + + Heya + + """ + Then it succeeds + Then IMAP client "2" eventually sees the following messages in "Sent": + | from | to | subject | in-reply-to | references | + | [user:user2]@[domain] | [user:user1]@[domain] | FW - Please Reply | | | + # User1 receive the reply.| + And IMAP client "1" eventually sees the following messages in "INBOX": + | from | subject | body | in-reply-to | references | + | [user:user2]@[domain] | FW - Please Reply | Heya | | | + + @long-black + Scenario: Reply with References but no In-Reply-To + # User1 send the initial message. + When SMTP client "1" sends the following message from "[user:user1]@[domain]" to "[user:user2]@[domain]": + """ + From: Bridge Test <[user:user1]@[domain]> + To: Internal Bridge <[user:user2]@[domain]> + Subject: Please Reply + Message-ID: + + hello + + """ + Then it succeeds + Then IMAP client "1" eventually sees the following messages in "Sent": + | from | to | subject | message-id | + | [user:user1]@[domain] | [user:user2]@[domain] | Please Reply | | + # login user2. + And the user logs in with username "[user:user2]" and password "password" + And user "[user:user2]" connects and authenticates IMAP client "2" + And user "[user:user2]" connects and authenticates SMTP client "2" + And user "[user:user2]" finishes syncing + # User2 receive the message. + Then IMAP client "2" eventually sees the following messages in "INBOX": + | from | subject | message-id | + | [user:user1]@[domain] | Please Reply | | + # User2 reply to it. + When SMTP client "2" sends the following message from "[user:user2]@[domain]" to "[user:user1]@[domain]": + """ + From: Internal Bridge <[user:user2]@[domain]> + To: Bridge Test <[user:user1]@[domain]> + Content-Type: text/plain + Subject: FW - Please Reply + References: + + Heya + + """ + Then it succeeds + Then IMAP client "2" eventually sees the following messages in "Sent": + | from | to | subject | in-reply-to | references | + | [user:user2]@[domain] | [user:user1]@[domain] | FW - Please Reply | | | + # User1 receive the reply.| + And IMAP client "1" eventually sees the following messages in "INBOX": + | from | subject | body | in-reply-to | references | + | [user:user2]@[domain] | FW - Please Reply | Heya | | | + + + @long-black + Scenario: Reply with both References and In-Reply-To + # User1 send the initial message. + When SMTP client "1" sends the following message from "[user:user1]@[domain]" to "[user:user2]@[domain]": + """ + From: Bridge Test <[user:user1]@[domain]> + To: Internal Bridge <[user:user2]@[domain]> + Subject: Please Reply + Message-ID: + + hello + + """ + Then it succeeds + Then IMAP client "1" eventually sees the following messages in "Sent": + | from | to | subject | message-id | + | [user:user1]@[domain] | [user:user2]@[domain] | Please Reply | | + # login user2. + And the user logs in with username "[user:user2]" and password "password" + And user "[user:user2]" connects and authenticates IMAP client "2" + And user "[user:user2]" connects and authenticates SMTP client "2" + And user "[user:user2]" finishes syncing + # User2 receive the message. + Then IMAP client "2" eventually sees the following messages in "INBOX": + | from | subject | message-id | + | [user:user1]@[domain] | Please Reply | | + # User2 reply to it. + When SMTP client "2" sends the following message from "[user:user2]@[domain]" to "[user:user1]@[domain]": + """ + From: Internal Bridge <[user:user2]@[domain]> + To: Bridge Test <[user:user1]@[domain]> + Content-Type: text/plain + Subject: FW - Please Reply + In-Reply-To: + References: + + Heya + + """ + Then it succeeds + Then IMAP client "2" eventually sees the following messages in "Sent": + | from | to | subject | in-reply-to | references | + | [user:user2]@[domain] | [user:user1]@[domain] | FW - Please Reply | | | + # User1 receive the reply.| + And IMAP client "1" eventually sees the following messages in "INBOX": + | from | subject | body | in-reply-to | references | + | [user:user2]@[domain] | FW - Please Reply | Heya | | | \ No newline at end of file diff --git a/tests/types_test.go b/tests/types_test.go index dfb8eb7d..c59b13dc 100644 --- a/tests/types_test.go +++ b/tests/types_test.go @@ -21,6 +21,7 @@ import ( "bytes" "fmt" "io" + "os" "reflect" "strconv" "strings" @@ -49,6 +50,9 @@ type Message struct { Unread bool `bdd:"unread"` Deleted bool `bdd:"deleted"` + + InReplyTo string `bdd:"in-reply-to"` + References string `bdd:"references"` } func (msg Message) Build() []byte { @@ -74,6 +78,14 @@ func (msg Message) Build() []byte { b = append(b, "Subject: "+msg.Subject+"\r\n"...) } + if msg.InReplyTo != "" { + b = append(b, "In-Reply-To: "+msg.InReplyTo+"\r\n"...) + } + + if msg.References != "" { + b = append(b, "References: "+msg.References+"\r\n"...) + } + if msg.Date != "" { date, err := time.Parse(time.RFC822, msg.Date) if err != nil { @@ -125,6 +137,9 @@ func newMessageFromIMAP(msg *imap.Message) Message { Unread: !slices.Contains(msg.Flags, imap.SeenFlag), Deleted: slices.Contains(msg.Flags, imap.DeletedFlag), Date: msg.Envelope.Date.Format(time.RFC822Z), + InReplyTo: msg.Envelope.InReplyTo, + // Go-imap only supports in-reply-to so we have to mimic other client by using it as references. + References: msg.Envelope.InReplyTo, } if len(msg.Envelope.From) > 0 { @@ -195,7 +210,13 @@ func matchMailboxes(have, want []Mailbox) error { func eventually(condition func() error) error { ch := make(chan error, 1) - timer := time.NewTimer(30 * time.Second) + var timerDuration = 30 * time.Second + // Extend to 5min for live API. + if hostURL := os.Getenv("FEATURE_TEST_HOST_URL"); hostURL != "" { + timerDuration = 600 * time.Second + } + + timer := time.NewTimer(timerDuration) defer timer.Stop() ticker := time.NewTicker(100 * time.Millisecond)