mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-15 22:56:48 +00:00
fix(GODT-2627): Properly handle recording of message with Bcc fields
Ensure the SMTP send recorder properly handles the recording of messages which may have the same body hash but have different recipients. E.g.: send the same message twice to 2 different users via Bcc. The send recorder now maintains a list of send requests and waiting for a message to be sent is done one the oldest of the messages.
This commit is contained in:
@ -35,7 +35,7 @@ func TestSendHasher_Insert(t *testing.T) {
|
||||
require.NotEmpty(t, hash1)
|
||||
|
||||
// Simulate successfully sending the message.
|
||||
h.addMessageID(hash1, "abc")
|
||||
h.signalMessageSent(hash1, "abc", nil)
|
||||
|
||||
// Inserting a message with the same hash should return false.
|
||||
_, ok, err = testTryInsert(h, literal1, time.Now().Add(time.Second))
|
||||
@ -59,7 +59,7 @@ func TestSendHasher_Insert_Expired(t *testing.T) {
|
||||
require.NotEmpty(t, hash1)
|
||||
|
||||
// Simulate successfully sending the message.
|
||||
h.addMessageID(hash1, "abc")
|
||||
h.signalMessageSent(hash1, "abc", nil)
|
||||
|
||||
// Wait for the entry to expire.
|
||||
time.Sleep(time.Second)
|
||||
@ -106,7 +106,7 @@ func TestSendHasher_Wait_SendSuccess(t *testing.T) {
|
||||
// Simulate successfully sending the message after half a second.
|
||||
go func() {
|
||||
time.Sleep(time.Millisecond * 500)
|
||||
h.addMessageID(hash, "abc")
|
||||
h.signalMessageSent(hash, "abc", nil)
|
||||
}()
|
||||
|
||||
// Inserting a message with the same hash should fail.
|
||||
@ -127,7 +127,7 @@ func TestSendHasher_Wait_SendFail(t *testing.T) {
|
||||
// Simulate failing to send the message after half a second.
|
||||
go func() {
|
||||
time.Sleep(time.Millisecond * 500)
|
||||
h.removeOnFail(hash)
|
||||
h.removeOnFail(hash, nil)
|
||||
}()
|
||||
|
||||
// Inserting a message with the same hash should succeed because the first message failed to send.
|
||||
@ -163,7 +163,7 @@ func TestSendHasher_HasEntry(t *testing.T) {
|
||||
require.NotEmpty(t, hash)
|
||||
|
||||
// Simulate successfully sending the message.
|
||||
h.addMessageID(hash, "abc")
|
||||
h.signalMessageSent(hash, "abc", nil)
|
||||
|
||||
// The message was already sent; we should find it in the hasher.
|
||||
messageID, ok, err := testHasEntry(h, literal1, time.Now().Add(time.Second))
|
||||
@ -184,7 +184,7 @@ func TestSendHasher_HasEntry_SendSuccess(t *testing.T) {
|
||||
// Simulate successfully sending the message after half a second.
|
||||
go func() {
|
||||
time.Sleep(time.Millisecond * 500)
|
||||
h.addMessageID(hash, "abc")
|
||||
h.signalMessageSent(hash, "abc", nil)
|
||||
}()
|
||||
|
||||
// The message was already sent; we should find it in the hasher.
|
||||
@ -197,7 +197,7 @@ func TestSendHasher_HasEntry_SendSuccess(t *testing.T) {
|
||||
func TestSendHasher_DualAddDoesNotCauseCrash(t *testing.T) {
|
||||
// There may be a rare case where one 2 smtp connections attempt to send the same message, but if the first message
|
||||
// is stuck long enough for it to expire, the second connection will remove it from the list and cause it to be
|
||||
// inserted as a new entry. The two clients end up sending the message twice and calling the `addMessageID` x2,
|
||||
// inserted as a new entry. The two clients end up sending the message twice and calling the `signalMessageSent` x2,
|
||||
// resulting in a crash.
|
||||
h := newSendRecorder(sendEntryExpiry)
|
||||
|
||||
@ -209,8 +209,8 @@ func TestSendHasher_DualAddDoesNotCauseCrash(t *testing.T) {
|
||||
|
||||
// Simulate successfully sending the message. We call this method twice as it possible for multiple SMTP connections
|
||||
// to attempt to send the same message.
|
||||
h.addMessageID(hash, "abc")
|
||||
h.addMessageID(hash, "abc")
|
||||
h.signalMessageSent(hash, "abc", nil)
|
||||
h.signalMessageSent(hash, "abc", nil)
|
||||
|
||||
// The message was already sent; we should find it in the hasher.
|
||||
messageID, ok, err := testHasEntry(h, literal1, time.Now().Add(time.Second))
|
||||
@ -219,6 +219,22 @@ func TestSendHasher_DualAddDoesNotCauseCrash(t *testing.T) {
|
||||
require.Equal(t, "abc", messageID)
|
||||
}
|
||||
|
||||
func TestSendHashed_MessageWithSameHasButDifferentRecipientsIsInserted(t *testing.T) {
|
||||
h := newSendRecorder(sendEntryExpiry)
|
||||
|
||||
// Insert a message into the hasher.
|
||||
hash, ok, err := testTryInsert(h, literal1, time.Now().Add(time.Second), "Receiver <receiver@pm.me>")
|
||||
require.NoError(t, err)
|
||||
require.True(t, ok)
|
||||
require.NotEmpty(t, hash)
|
||||
|
||||
hash2, ok, err := testTryInsert(h, literal1, time.Now().Add(time.Second), "Receiver <receiver@pm.me>", "Receiver2 <receiver2@pm.me>")
|
||||
require.NoError(t, err)
|
||||
require.True(t, ok)
|
||||
require.NotEmpty(t, hash2)
|
||||
require.Equal(t, hash, hash2)
|
||||
}
|
||||
|
||||
func TestSendHasher_HasEntry_SendFail(t *testing.T) {
|
||||
h := newSendRecorder(sendEntryExpiry)
|
||||
|
||||
@ -231,7 +247,7 @@ func TestSendHasher_HasEntry_SendFail(t *testing.T) {
|
||||
// Simulate failing to send the message after half a second.
|
||||
go func() {
|
||||
time.Sleep(time.Millisecond * 500)
|
||||
h.removeOnFail(hash)
|
||||
h.removeOnFail(hash, nil)
|
||||
}()
|
||||
|
||||
// The message failed to send; we should not find it in the hasher.
|
||||
@ -265,7 +281,7 @@ func TestSendHasher_HasEntry_Expired(t *testing.T) {
|
||||
require.NotEmpty(t, hash)
|
||||
|
||||
// Simulate successfully sending the message.
|
||||
h.addMessageID(hash, "abc")
|
||||
h.signalMessageSent(hash, "abc", nil)
|
||||
|
||||
// Wait for the entry to expire.
|
||||
time.Sleep(time.Second)
|
||||
|
||||
Reference in New Issue
Block a user