Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion src/receive_imf/receive_imf_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3284,7 +3284,8 @@ async fn test_blocked_contact_creates_group() -> Result<()> {

let sent = bob.send_text(group_id, "Heyho, I'm a spammer!").await;
let rcvd = alice.recv_msg(&sent).await;
// Alice blocked Bob, so she shouldn't get the message
// Alice blocked Bob, so she shouldn't be notified.
assert_eq!(rcvd.state, MessageState::InSeen);
assert_eq!(rcvd.chat_blocked, Blocked::Yes);

// Fiona didn't block Bob, though, so she gets the message
Expand Down Expand Up @@ -5117,6 +5118,7 @@ async fn test_recv_outgoing_msg_before_securejoin() -> Result<()> {
tcm.execute_securejoin(bob, a0).await;
let chat_id_a0_bob = a0.create_chat_id(bob).await;
let sent_msg = a0.send_text(chat_id_a0_bob, "Hi").await;
bob.recv_msg(&sent_msg).await;
let msg_a1 = a1.recv_msg(&sent_msg).await;
assert!(msg_a1.get_showpadlock());
let chat_a1 = Chat::load_from_db(a1, msg_a1.chat_id).await?;
Expand All @@ -5132,6 +5134,7 @@ async fn test_recv_outgoing_msg_before_securejoin() -> Result<()> {
);

let sent_msg = a0.send_text(chat_id_a0_bob, "Hi again").await;
bob.recv_msg(&sent_msg).await;
let msg_a1 = a1.recv_msg(&sent_msg).await;
assert!(msg_a1.get_showpadlock());
assert_eq!(msg_a1.chat_id, chat_a1.id);
Expand All @@ -5140,6 +5143,45 @@ async fn test_recv_outgoing_msg_before_securejoin() -> Result<()> {
chat_a1.why_cant_send(a1).await?,
Some(CantSendReason::NotAMember)
);

let msg_a1 = tcm.send_recv(bob, a1, "Hi back").await;
assert!(msg_a1.get_showpadlock());
let chat_a1 = Chat::load_from_db(a1, msg_a1.chat_id).await?;
assert_eq!(chat_a1.typ, Chattype::Single);
assert!(chat_a1.is_encrypted(a1).await?);
// Weird, but fine, anyway the bigger problem is the conversation split into two chats.
assert_eq!(
chat_a1.why_cant_send(a1).await?,
Some(CantSendReason::ContactRequest)
);
Ok(())
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_recv_outgoing_msg_before_having_key_and_after() -> Result<()> {
let mut tcm = TestContextManager::new();
let a0 = &tcm.alice().await;
let a1 = &tcm.alice().await;
let bob = &tcm.bob().await;

tcm.execute_securejoin(bob, a0).await;
let chat_id_a0_bob = a0.create_chat_id(bob).await;
let sent_msg = a0.send_text(chat_id_a0_bob, "Hi").await;
let msg_a1 = a1.recv_msg(&sent_msg).await;
assert!(msg_a1.get_showpadlock());
let chat_a1 = Chat::load_from_db(a1, msg_a1.chat_id).await?;
assert_eq!(chat_a1.typ, Chattype::Group);
assert!(!chat_a1.is_encrypted(a1).await?);

// Device a1 somehow learns Bob's key and creates the corresponding chat. However, this doesn't
// help currently because we only look up key contacts by address in a particular chat and the
// new chat isn't referenced by the received message. This should be fixed by sending and
// receiving Intended Recipient Fingerprint subpackets.
a1.create_chat_id(bob).await;
let sent_msg = a0.send_text(chat_id_a0_bob, "Hi again").await;
let msg_a1 = a1.recv_msg(&sent_msg).await;
assert!(msg_a1.get_showpadlock());
assert_eq!(msg_a1.chat_id, chat_a1.id);
Ok(())
}

Expand Down