@@ -169,11 +169,10 @@ pub async fn ensure_secret_key_exists(context: &Context) -> Result<()> {
169
169
#[ cfg( test) ]
170
170
mod tests {
171
171
use super :: * ;
172
- use crate :: chat;
173
172
use crate :: key:: DcKey ;
174
173
use crate :: message:: { Message , Viewtype } ;
175
174
use crate :: param:: Param ;
176
- use crate :: test_utils:: { bob_keypair, TestContext } ;
175
+ use crate :: test_utils:: { bob_keypair, TestContext , TestContextManager } ;
177
176
178
177
mod ensure_secret_key_exists {
179
178
use super :: * ;
@@ -217,37 +216,35 @@ Sent with my Delta Chat Messenger: https://delta.chat";
217
216
218
217
#[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
219
218
async fn test_encrypted_no_autocrypt ( ) -> anyhow:: Result < ( ) > {
220
- let alice = TestContext :: new_alice ( ) . await ;
221
- let bob = TestContext :: new_bob ( ) . await ;
219
+ let mut tcm = TestContextManager :: new ( ) ;
220
+ let alice = tcm. alice ( ) . await ;
221
+ let bob = tcm. bob ( ) . await ;
222
222
223
223
let chat_alice = alice. create_chat ( & bob) . await . id ;
224
224
let chat_bob = bob. create_chat ( & alice) . await . id ;
225
225
226
226
// Alice sends unencrypted message to Bob
227
227
let mut msg = Message :: new ( Viewtype :: Text ) ;
228
- chat:: prepare_msg ( & alice. ctx , chat_alice, & mut msg) . await ?;
229
- chat:: send_msg ( & alice. ctx , chat_alice, & mut msg) . await ?;
230
- let sent = alice. pop_sent_msg ( ) . await ;
228
+ let sent = alice. send_msg ( chat_alice, & mut msg) . await ;
231
229
232
230
// Bob receives unencrypted message from Alice
233
- let msg = bob. parse_msg ( & sent) . await ;
234
- assert ! ( !msg. was_encrypted ( ) ) ;
231
+ let msg = bob. recv_msg ( & sent) . await ;
232
+ assert ! ( !msg. get_showpadlock ( ) ) ;
235
233
236
- // Parsing a message is enough to update peerstate
237
234
let peerstate_alice = Peerstate :: from_addr ( & bob. ctx , "alice@example.org" )
238
235
. await ?
239
236
. expect ( "no peerstate found in the database" ) ;
240
237
assert_eq ! ( peerstate_alice. prefer_encrypt, EncryptPreference :: Mutual ) ;
241
238
242
- // Bob sends encrypted message to Alice
239
+ // Bob sends empty encrypted message to Alice
243
240
let mut msg = Message :: new ( Viewtype :: Text ) ;
244
- chat:: prepare_msg ( & bob. ctx , chat_bob, & mut msg) . await ?;
245
- chat:: send_msg ( & bob. ctx , chat_bob, & mut msg) . await ?;
246
- let sent = bob. pop_sent_msg ( ) . await ;
241
+ let sent = bob. send_msg ( chat_bob, & mut msg) . await ;
247
242
248
- // Alice receives encrypted message from Bob
249
- let msg = alice. parse_msg ( & sent) . await ;
250
- assert ! ( msg. was_encrypted( ) ) ;
243
+ // Alice receives an empty encrypted message from Bob.
244
+ // This is also a regression test for previously existing bug
245
+ // that resulted in no padlock on encrypted empty messages.
246
+ let msg = alice. recv_msg ( & sent) . await ;
247
+ assert ! ( msg. get_showpadlock( ) ) ;
251
248
252
249
let peerstate_bob = Peerstate :: from_addr ( & alice. ctx , "bob@example.net" )
253
250
. await ?
@@ -259,12 +256,10 @@ Sent with my Delta Chat Messenger: https://delta.chat";
259
256
// Alice sends encrypted message without Autocrypt header.
260
257
let mut msg = Message :: new ( Viewtype :: Text ) ;
261
258
msg. param . set_int ( Param :: SkipAutocrypt , 1 ) ;
262
- chat:: prepare_msg ( & alice. ctx , chat_alice, & mut msg) . await ?;
263
- chat:: send_msg ( & alice. ctx , chat_alice, & mut msg) . await ?;
264
- let sent = alice. pop_sent_msg ( ) . await ;
259
+ let sent = alice. send_msg ( chat_alice, & mut msg) . await ;
265
260
266
- let msg = bob. parse_msg ( & sent) . await ;
267
- assert ! ( msg. was_encrypted ( ) ) ;
261
+ let msg = bob. recv_msg ( & sent) . await ;
262
+ assert ! ( msg. get_showpadlock ( ) ) ;
268
263
let peerstate_alice = Peerstate :: from_addr ( & bob. ctx , "alice@example.org" )
269
264
. await ?
270
265
. expect ( "no peerstate found in the database" ) ;
@@ -273,12 +268,10 @@ Sent with my Delta Chat Messenger: https://delta.chat";
273
268
// Alice sends plaintext message with Autocrypt header.
274
269
let mut msg = Message :: new ( Viewtype :: Text ) ;
275
270
msg. force_plaintext ( ) ;
276
- chat:: prepare_msg ( & alice. ctx , chat_alice, & mut msg) . await ?;
277
- chat:: send_msg ( & alice. ctx , chat_alice, & mut msg) . await ?;
278
- let sent = alice. pop_sent_msg ( ) . await ;
271
+ let sent = alice. send_msg ( chat_alice, & mut msg) . await ;
279
272
280
- let msg = bob. parse_msg ( & sent) . await ;
281
- assert ! ( !msg. was_encrypted ( ) ) ;
273
+ let msg = bob. recv_msg ( & sent) . await ;
274
+ assert ! ( !msg. get_showpadlock ( ) ) ;
282
275
let peerstate_alice = Peerstate :: from_addr ( & bob. ctx , "alice@example.org" )
283
276
. await ?
284
277
. expect ( "no peerstate found in the database" ) ;
@@ -288,12 +281,10 @@ Sent with my Delta Chat Messenger: https://delta.chat";
288
281
let mut msg = Message :: new ( Viewtype :: Text ) ;
289
282
msg. force_plaintext ( ) ;
290
283
msg. param . set_int ( Param :: SkipAutocrypt , 1 ) ;
291
- chat:: prepare_msg ( & alice. ctx , chat_alice, & mut msg) . await ?;
292
- chat:: send_msg ( & alice. ctx , chat_alice, & mut msg) . await ?;
293
- let sent = alice. pop_sent_msg ( ) . await ;
284
+ let sent = alice. send_msg ( chat_alice, & mut msg) . await ;
294
285
295
- let msg = bob. parse_msg ( & sent) . await ;
296
- assert ! ( !msg. was_encrypted ( ) ) ;
286
+ let msg = bob. recv_msg ( & sent) . await ;
287
+ assert ! ( !msg. get_showpadlock ( ) ) ;
297
288
let peerstate_alice = Peerstate :: from_addr ( & bob. ctx , "alice@example.org" )
298
289
. await ?
299
290
. expect ( "no peerstate found in the database" ) ;
0 commit comments