@@ -11,6 +11,7 @@ use crate::message::{Message, MessengerMessage, delete_msgs};
1111use crate :: mimeparser:: { self , MimeMessage } ;
1212use crate :: receive_imf:: receive_imf;
1313use crate :: securejoin:: { get_securejoin_qr, join_securejoin} ;
14+ use crate :: test_utils;
1415use crate :: test_utils:: {
1516 AVATAR_64x64_BYTES , AVATAR_64x64_DEDUPLICATED , E2EE_INFO_MSGS , TestContext , TestContextManager ,
1617 TimeShiftFalsePositiveNote , sync,
@@ -1049,6 +1050,7 @@ async fn chatlist_len(ctx: &Context, listflags: usize) -> usize {
10491050async fn test_archive ( ) {
10501051 // create two chats
10511052 let t = TestContext :: new_alice ( ) . await ;
1053+
10521054 let mut msg = Message :: new_text ( "foo" . to_string ( ) ) ;
10531055 let msg_id = add_device_msg ( & t, None , Some ( & mut msg) ) . await . unwrap ( ) ;
10541056 let chat_id1 = message:: Message :: load_from_db ( & t, msg_id)
@@ -1159,42 +1161,47 @@ async fn test_archive() {
11591161
11601162#[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
11611163async fn test_unarchive_if_muted ( ) -> Result < ( ) > {
1162- let t = TestContext :: new_alice ( ) . await ;
1164+ let mut tcm = TestContextManager :: new ( ) ;
1165+ let t = & tcm. alice ( ) . await ;
1166+ let bob = & tcm. bob ( ) . await ;
11631167
1164- async fn msg_from_bob ( t : & TestContext , num : u32 ) -> Result < ( ) > {
1165- receive_imf (
1166- t,
1168+ let msg_from_bob = async |num : u32 | {
1169+ let encrypted_message = test_utils:: encrypt_raw_message (
1170+ bob,
1171+ & [ t] ,
11671172 format ! (
1168- "From: bob@example.net\n \
1169- To: alice@example.org\n \
1170- Message-ID: <{num}@example.org>\n \
1171- Chat-Version: 1.0\n \
1172- Date: Sun, 22 Mar 2022 19:37:57 +0000\n \
1173- \n \
1174- hello\n "
1173+ "From: bob@example.net\r \ n\
1174+ To: alice@example.org\r \n \
1175+ Message-ID: <{num}@example.org>\r \n \
1176+ Chat-Version: 1.0\r \n \
1177+ Date: Sun, 22 Mar 2022 19:37:57 +0000\r \n \
1178+ \r \n \
1179+ hello\r \n "
11751180 )
11761181 . as_bytes ( ) ,
1177- false ,
11781182 )
1179- . await ?;
1180- Ok ( ( ) )
1181- }
1183+ . await
1184+ . unwrap ( ) ;
1185+ receive_imf ( t, encrypted_message. as_bytes ( ) , false )
1186+ . await
1187+ . unwrap ( ) ;
1188+ } ;
11821189
1183- msg_from_bob ( & t , 1 ) . await ? ;
1190+ msg_from_bob ( 1 ) . await ;
11841191 let chat_id = t. get_last_msg ( ) . await . get_chat_id ( ) ;
1185- chat_id. accept ( & t) . await ?;
1186- chat_id. set_visibility ( & t, ChatVisibility :: Archived ) . await ?;
1187- assert_eq ! ( get_archived_cnt( & t) . await ?, 1 ) ;
1192+ chat_id. accept ( t) . await ?;
1193+ chat_id. set_visibility ( t, ChatVisibility :: Archived ) . await ?;
1194+ assert_eq ! ( get_archived_cnt( t) . await ?, 1 ) ;
11881195
11891196 // not muted chat is unarchived on receiving a message
1190- msg_from_bob ( & t , 2 ) . await ? ;
1191- assert_eq ! ( get_archived_cnt( & t) . await ?, 0 ) ;
1197+ msg_from_bob ( 2 ) . await ;
1198+ assert_eq ! ( get_archived_cnt( t) . await ?, 0 ) ;
11921199
11931200 // forever muted chat is not unarchived on receiving a message
11941201 chat_id. set_visibility ( & t, ChatVisibility :: Archived ) . await ?;
1195- set_muted ( & t, chat_id, MuteDuration :: Forever ) . await ?;
1196- msg_from_bob ( & t , 3 ) . await ? ;
1197- assert_eq ! ( get_archived_cnt( & t) . await ?, 1 ) ;
1202+ set_muted ( t, chat_id, MuteDuration :: Forever ) . await ?;
1203+ msg_from_bob ( 3 ) . await ;
1204+ assert_eq ! ( get_archived_cnt( t) . await ?, 1 ) ;
11981205
11991206 // otherwise muted chat is not unarchived on receiving a message
12001207 set_muted (
@@ -1207,7 +1214,7 @@ async fn test_unarchive_if_muted() -> Result<()> {
12071214 ) ,
12081215 )
12091216 . await ?;
1210- msg_from_bob ( & t , 4 ) . await ? ;
1217+ msg_from_bob ( 4 ) . await ;
12111218 assert_eq ! ( get_archived_cnt( & t) . await ?, 1 ) ;
12121219
12131220 // expired mute will unarchive the chat
@@ -1221,20 +1228,20 @@ async fn test_unarchive_if_muted() -> Result<()> {
12211228 ) ,
12221229 )
12231230 . await ?;
1224- msg_from_bob ( & t , 5 ) . await ? ;
1225- assert_eq ! ( get_archived_cnt( & t) . await ?, 0 ) ;
1231+ msg_from_bob ( 5 ) . await ;
1232+ assert_eq ! ( get_archived_cnt( t) . await ?, 0 ) ;
12261233
12271234 // no unarchiving on sending to muted chat or on adding info messages to muted chat
1228- chat_id. set_visibility ( & t, ChatVisibility :: Archived ) . await ?;
1229- set_muted ( & t, chat_id, MuteDuration :: Forever ) . await ?;
1230- send_text_msg ( & t, chat_id, "out" . to_string ( ) ) . await ?;
1231- add_info_msg ( & t, chat_id, "info" ) . await ?;
1232- assert_eq ! ( get_archived_cnt( & t) . await ?, 1 ) ;
1235+ chat_id. set_visibility ( t, ChatVisibility :: Archived ) . await ?;
1236+ set_muted ( t, chat_id, MuteDuration :: Forever ) . await ?;
1237+ send_text_msg ( t, chat_id, "out" . to_string ( ) ) . await ?;
1238+ add_info_msg ( t, chat_id, "info" ) . await ?;
1239+ assert_eq ! ( get_archived_cnt( t) . await ?, 1 ) ;
12331240
12341241 // finally, unarchive on sending to not muted chat
1235- set_muted ( & t, chat_id, MuteDuration :: NotMuted ) . await ?;
1236- send_text_msg ( & t, chat_id, "out2" . to_string ( ) ) . await ?;
1237- assert_eq ! ( get_archived_cnt( & t) . await ?, 0 ) ;
1242+ set_muted ( t, chat_id, MuteDuration :: NotMuted ) . await ?;
1243+ send_text_msg ( t, chat_id, "out2" . to_string ( ) ) . await ?;
1244+ assert_eq ! ( get_archived_cnt( t) . await ?, 0 ) ;
12381245
12391246 Ok ( ( ) )
12401247}
@@ -1381,6 +1388,9 @@ async fn test_markfresh_chat() -> Result<()> {
13811388async fn test_archive_fresh_msgs ( ) -> Result < ( ) > {
13821389 let t = TestContext :: new_alice ( ) . await ;
13831390
1391+ // FIXME: use encrypted messages
1392+ t. set_config ( Config :: ProcessUnencrypted , Some ( "1" ) ) . await ?;
1393+
13841394 async fn msg_from ( t : & TestContext , name : & str , num : u32 ) -> Result < ( ) > {
13851395 receive_imf (
13861396 t,
@@ -1873,52 +1883,46 @@ async fn test_lookup_self_by_contact_id() {
18731883
18741884#[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
18751885async fn test_marknoticed_chat ( ) -> Result < ( ) > {
1876- let t = TestContext :: new_alice ( ) . await ;
1877- let chat = t. create_chat_with_contact ( "bob" , "bob@example.org" ) . await ;
1886+ let mut tcm = TestContextManager :: new ( ) ;
1887+ let alice = & tcm. alice ( ) . await ;
1888+ let bob = & tcm. bob ( ) . await ;
1889+ let chat = alice. create_chat ( bob) . await ;
18781890
1879- receive_imf (
1880- & t,
1881- b"From: bob@example.org\n \
1882- To: alice@example.org\n \
1883- Message-ID: <1@example.org>\n \
1884- Chat-Version: 1.0\n \
1885- Date: Fri, 23 Apr 2021 10:00:57 +0000\n \
1886- \n \
1887- hello\n ",
1888- false ,
1889- )
1890- . await ?;
1891+ let bob_chat_id = bob. create_chat_id ( alice) . await ;
1892+ let sent = bob. send_text ( bob_chat_id, "hello" ) . await ;
1893+ alice. recv_msg ( & sent) . await ;
18911894
1892- let chats = Chatlist :: try_load ( & t , 0 , None , None ) . await ?;
1895+ let chats = Chatlist :: try_load ( alice , 0 , None , None ) . await ?;
18931896 assert_eq ! ( chats. len( ) , 1 ) ;
18941897 assert_eq ! ( chats. get_chat_id( 0 ) ?, chat. id) ;
1895- assert_eq ! ( chat. id. get_fresh_msg_cnt( & t ) . await ?, 1 ) ;
1896- assert_eq ! ( t . get_fresh_msgs( ) . await ?. len( ) , 1 ) ;
1898+ assert_eq ! ( chat. id. get_fresh_msg_cnt( alice ) . await ?, 1 ) ;
1899+ assert_eq ! ( alice . get_fresh_msgs( ) . await ?. len( ) , 1 ) ;
18971900
1898- let msgs = get_chat_msgs ( & t , chat. id ) . await ?;
1899- assert_eq ! ( msgs. len( ) , 1 ) ;
1900- let msg_id = match msgs. first ( ) . unwrap ( ) {
1901+ let msgs = get_chat_msgs ( alice , chat. id ) . await ?;
1902+ assert_eq ! ( msgs. len( ) , 2 ) ;
1903+ let msg_id = match msgs. last ( ) . unwrap ( ) {
19011904 ChatItem :: Message { msg_id } => * msg_id,
19021905 _ => MsgId :: new_unset ( ) ,
19031906 } ;
1904- let msg = message:: Message :: load_from_db ( & t , msg_id) . await ?;
1907+ let msg = message:: Message :: load_from_db ( alice , msg_id) . await ?;
19051908 assert_eq ! ( msg. state, MessageState :: InFresh ) ;
19061909
1907- marknoticed_chat ( & t , chat. id ) . await ?;
1910+ marknoticed_chat ( alice , chat. id ) . await ?;
19081911
1909- let chats = Chatlist :: try_load ( & t , 0 , None , None ) . await ?;
1912+ let chats = Chatlist :: try_load ( alice , 0 , None , None ) . await ?;
19101913 assert_eq ! ( chats. len( ) , 1 ) ;
1911- let msg = message:: Message :: load_from_db ( & t , msg_id) . await ?;
1914+ let msg = message:: Message :: load_from_db ( alice , msg_id) . await ?;
19121915 assert_eq ! ( msg. state, MessageState :: InNoticed ) ;
1913- assert_eq ! ( chat. id. get_fresh_msg_cnt( & t ) . await ?, 0 ) ;
1914- assert_eq ! ( t . get_fresh_msgs( ) . await ?. len( ) , 0 ) ;
1916+ assert_eq ! ( chat. id. get_fresh_msg_cnt( alice ) . await ?, 0 ) ;
1917+ assert_eq ! ( alice . get_fresh_msgs( ) . await ?. len( ) , 0 ) ;
19151918
19161919 Ok ( ( ) )
19171920}
19181921
19191922#[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
19201923async fn test_contact_request_fresh_messages ( ) -> Result < ( ) > {
19211924 let t = TestContext :: new_alice ( ) . await ;
1925+ t. set_config ( Config :: ProcessUnencrypted , Some ( "1" ) ) . await ?;
19221926
19231927 let chats = Chatlist :: try_load ( & t, 0 , None , None ) . await ?;
19241928 assert_eq ! ( chats. len( ) , 0 ) ;
@@ -1970,47 +1974,53 @@ async fn test_contact_request_fresh_messages() -> Result<()> {
19701974
19711975#[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
19721976async fn test_contact_request_archive ( ) -> Result < ( ) > {
1973- let t = TestContext :: new_alice ( ) . await ;
1977+ let mut tcm = TestContextManager :: new ( ) ;
1978+ let alice = & tcm. alice ( ) . await ;
1979+ let bob = & tcm. bob ( ) . await ;
19741980
1975- receive_imf (
1976- & t,
1977- b"From: bob@example.org\n \
1978- To: alice@example.org\n \
1979- Message-ID: <2@example.org>\n \
1980- Chat-Version: 1.0\n \
1981- Date: Sun, 22 Mar 2021 19:37:57 +0000\n \
1982- \n \
1983- hello\n ",
1984- false ,
1985- )
1986- . await ?;
1981+ let bob_chat_id = bob. create_chat_id ( alice) . await ;
1982+ let bob_sent_text = bob. send_text ( bob_chat_id, "hello" ) . await ;
1983+ alice. recv_msg ( & bob_sent_text) . await ;
19871984
1988- let chats = Chatlist :: try_load ( & t , 0 , None , None ) . await ?;
1985+ let chats = Chatlist :: try_load ( alice , 0 , None , None ) . await ?;
19891986 assert_eq ! ( chats. len( ) , 1 ) ;
19901987 let chat_id = chats. get_chat_id ( 0 ) ?;
1991- assert ! ( Chat :: load_from_db( & t, chat_id) . await ?. is_contact_request( ) ) ;
1992- assert_eq ! ( get_archived_cnt( & t) . await ?, 0 ) ;
1988+ assert ! (
1989+ Chat :: load_from_db( alice, chat_id)
1990+ . await ?
1991+ . is_contact_request( )
1992+ ) ;
1993+ assert_eq ! ( get_archived_cnt( alice) . await ?, 0 ) ;
19931994
19941995 // archive request without accepting or blocking
1995- chat_id. set_visibility ( & t, ChatVisibility :: Archived ) . await ?;
1996+ chat_id
1997+ . set_visibility ( alice, ChatVisibility :: Archived )
1998+ . await ?;
19961999
1997- let chats = Chatlist :: try_load ( & t , 0 , None , None ) . await ?;
2000+ let chats = Chatlist :: try_load ( alice , 0 , None , None ) . await ?;
19982001 assert_eq ! ( chats. len( ) , 1 ) ;
19992002 let chat_id = chats. get_chat_id ( 0 ) ?;
20002003 assert ! ( chat_id. is_archived_link( ) ) ;
2001- assert_eq ! ( get_archived_cnt( & t ) . await ?, 1 ) ;
2004+ assert_eq ! ( get_archived_cnt( alice ) . await ?, 1 ) ;
20022005
2003- let chats = Chatlist :: try_load ( & t , DC_GCL_ARCHIVED_ONLY , None , None ) . await ?;
2006+ let chats = Chatlist :: try_load ( alice , DC_GCL_ARCHIVED_ONLY , None , None ) . await ?;
20042007 assert_eq ! ( chats. len( ) , 1 ) ;
20052008 let chat_id = chats. get_chat_id ( 0 ) ?;
2006- assert ! ( Chat :: load_from_db( & t, chat_id) . await ?. is_contact_request( ) ) ;
2009+ assert ! (
2010+ Chat :: load_from_db( alice, chat_id)
2011+ . await ?
2012+ . is_contact_request( )
2013+ ) ;
20072014
20082015 Ok ( ( ) )
20092016}
20102017
20112018#[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
20122019async fn test_classic_email_chat ( ) -> Result < ( ) > {
20132020 let alice = TestContext :: new_alice ( ) . await ;
2021+ alice
2022+ . set_config ( Config :: ProcessUnencrypted , Some ( "1" ) )
2023+ . await ?;
20142024
20152025 // Alice receives a classic (non-chat) message from Bob.
20162026 receive_imf (
@@ -4695,10 +4705,12 @@ async fn test_sync_delete_chat() -> Result<()> {
46954705
46964706#[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
46974707async fn test_sync_adhoc_grp ( ) -> Result < ( ) > {
4698- let alice0 = & TestContext :: new_alice ( ) . await ;
4699- let alice1 = & TestContext :: new_alice ( ) . await ;
4708+ let mut tcm = TestContextManager :: new ( ) ;
4709+ let alice0 = & tcm. alice ( ) . await ;
4710+ let alice1 = & tcm. alice ( ) . await ;
47004711 for a in [ alice0, alice1] {
47014712 a. set_config_bool ( Config :: SyncMsgs , true ) . await ?;
4713+ a. set_config_bool ( Config :: ProcessUnencrypted , true ) . await ?;
47024714 }
47034715
47044716 let mut chat_ids = Vec :: new ( ) ;
@@ -6070,6 +6082,9 @@ async fn test_no_key_contacts_in_adhoc_chats() -> Result<()> {
60706082 let alice = & tcm. alice ( ) . await ;
60716083 let bob = & tcm. bob ( ) . await ;
60726084 let charlie = & tcm. charlie ( ) . await ;
6085+ alice
6086+ . set_config_bool ( Config :: ProcessUnencrypted , true )
6087+ . await ?;
60736088
60746089 let chat_id = receive_imf (
60756090 alice,
0 commit comments