Skip to content

Commit 36cab40

Browse files
committed
test: add get_protected_chat to testplugin.py
1 parent 4186d78 commit 36cab40

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

python/src/deltachat/testplugin.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import weakref
1111
import random
1212
from queue import Queue
13+
from threading import Event
1314
from typing import Callable, Dict, List, Optional, Set
1415

1516
import pytest
@@ -590,6 +591,25 @@ def get_accepted_chat(self, ac1: Account, ac2: Account):
590591
ac2.create_chat(ac1)
591592
return ac1.create_chat(ac2)
592593

594+
def get_protected_chat(self, ac1: Account, ac2: Account):
595+
class SetupPlugin:
596+
def __init__(self) -> None:
597+
self.member_added = Event()
598+
599+
@account_hookimpl
600+
def ac_member_added(self, chat: deltachat.Chat, contact, actor, message):
601+
self.member_added.set()
602+
603+
setupplugin = SetupPlugin()
604+
ac1.add_account_plugin(setupplugin)
605+
chat = ac1.create_group_chat("Protected Group", verified=True)
606+
qr = chat.get_join_qr()
607+
ac2.qr_join_chat(qr)
608+
setupplugin.member_added.wait(timeout=30)
609+
ac2.wait_next_incoming_message()
610+
ac2.wait_next_incoming_message()
611+
return chat
612+
593613
def introduce_each_other(self, accounts, sending=True):
594614
to_wait = []
595615
for i, acc in enumerate(accounts):

python/tests/test_1_online.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -500,26 +500,20 @@ def test_forward_messages(acfactory, lp):
500500

501501
def test_forward_encrypted_to_unencrypted(acfactory, lp):
502502
ac1, ac2, ac3 = acfactory.get_online_accounts(3)
503-
chat = acfactory.get_accepted_chat(ac1, ac2)
503+
chat = acfactory.get_protected_chat(ac1, ac2)
504504

505-
lp.sec("ac1: send unencrypted message to ac2")
506-
txt = "This is still unencrypted"
505+
lp.sec("ac1: send encrypted message to ac2")
506+
txt = "This should be encrypted"
507507
chat.send_text(txt)
508508
msg = ac2.wait_next_incoming_message()
509509
assert msg.text == txt
510-
assert not msg.is_encrypted()
510+
assert msg.is_encrypted()
511511

512-
lp.sec("ac2: send encrypted message to ac1")
513-
txt = "This should be encrypted now"
514-
msg.chat.send_text(txt)
515-
msg2 = ac1.wait_next_incoming_message()
516-
assert msg2.is_encrypted()
517-
518-
lp.sec("ac1: forward message to ac3 unencrypted ")
519-
unencrypted_chat = ac1.create_chat(ac3)
520-
msg3 = unencrypted_chat.send_msg(msg)
521-
assert not msg3.is_encrypted()
522-
assert msg2.is_encrypted()
512+
lp.sec("ac2: forward message to ac3 unencrypted ")
513+
unencrypted_chat = ac2.create_chat(ac3)
514+
msg2 = unencrypted_chat.send_msg(msg)
515+
assert not msg2.is_encrypted()
516+
assert msg.is_encrypted()
523517

524518

525519
def test_forward_own_message(acfactory, lp):

0 commit comments

Comments
 (0)