mirror of
https://github.com/chatmail/core.git
synced 2026-05-07 17:06:35 +03:00
test: add get_protected_chat to testplugin.py
This commit is contained in:
@@ -10,6 +10,7 @@ import time
|
|||||||
import weakref
|
import weakref
|
||||||
import random
|
import random
|
||||||
from queue import Queue
|
from queue import Queue
|
||||||
|
from threading import Event
|
||||||
from typing import Callable, Dict, List, Optional, Set
|
from typing import Callable, Dict, List, Optional, Set
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
@@ -590,6 +591,25 @@ class ACFactory:
|
|||||||
ac2.create_chat(ac1)
|
ac2.create_chat(ac1)
|
||||||
return ac1.create_chat(ac2)
|
return ac1.create_chat(ac2)
|
||||||
|
|
||||||
|
def get_protected_chat(self, ac1: Account, ac2: Account):
|
||||||
|
class SetupPlugin:
|
||||||
|
def __init__(self) -> None:
|
||||||
|
self.member_added = Event()
|
||||||
|
|
||||||
|
@account_hookimpl
|
||||||
|
def ac_member_added(self, chat: deltachat.Chat, contact, actor, message):
|
||||||
|
self.member_added.set()
|
||||||
|
|
||||||
|
setupplugin = SetupPlugin()
|
||||||
|
ac1.add_account_plugin(setupplugin)
|
||||||
|
chat = ac1.create_group_chat("Protected Group", verified=True)
|
||||||
|
qr = chat.get_join_qr()
|
||||||
|
ac2.qr_join_chat(qr)
|
||||||
|
setupplugin.member_added.wait(timeout=30)
|
||||||
|
ac2.wait_next_incoming_message()
|
||||||
|
ac2.wait_next_incoming_message()
|
||||||
|
return chat
|
||||||
|
|
||||||
def introduce_each_other(self, accounts, sending=True):
|
def introduce_each_other(self, accounts, sending=True):
|
||||||
to_wait = []
|
to_wait = []
|
||||||
for i, acc in enumerate(accounts):
|
for i, acc in enumerate(accounts):
|
||||||
|
|||||||
@@ -500,26 +500,20 @@ def test_forward_messages(acfactory, lp):
|
|||||||
|
|
||||||
def test_forward_encrypted_to_unencrypted(acfactory, lp):
|
def test_forward_encrypted_to_unencrypted(acfactory, lp):
|
||||||
ac1, ac2, ac3 = acfactory.get_online_accounts(3)
|
ac1, ac2, ac3 = acfactory.get_online_accounts(3)
|
||||||
chat = acfactory.get_accepted_chat(ac1, ac2)
|
chat = acfactory.get_protected_chat(ac1, ac2)
|
||||||
|
|
||||||
lp.sec("ac1: send unencrypted message to ac2")
|
lp.sec("ac1: send encrypted message to ac2")
|
||||||
txt = "This is still unencrypted"
|
txt = "This should be encrypted"
|
||||||
chat.send_text(txt)
|
chat.send_text(txt)
|
||||||
msg = ac2.wait_next_incoming_message()
|
msg = ac2.wait_next_incoming_message()
|
||||||
assert msg.text == txt
|
assert msg.text == txt
|
||||||
assert not msg.is_encrypted()
|
assert msg.is_encrypted()
|
||||||
|
|
||||||
lp.sec("ac2: send encrypted message to ac1")
|
lp.sec("ac2: forward message to ac3 unencrypted ")
|
||||||
txt = "This should be encrypted now"
|
unencrypted_chat = ac2.create_chat(ac3)
|
||||||
msg.chat.send_text(txt)
|
msg2 = unencrypted_chat.send_msg(msg)
|
||||||
msg2 = ac1.wait_next_incoming_message()
|
assert not msg2.is_encrypted()
|
||||||
assert msg2.is_encrypted()
|
assert msg.is_encrypted()
|
||||||
|
|
||||||
lp.sec("ac1: forward message to ac3 unencrypted ")
|
|
||||||
unencrypted_chat = ac1.create_chat(ac3)
|
|
||||||
msg3 = unencrypted_chat.send_msg(msg)
|
|
||||||
assert not msg3.is_encrypted()
|
|
||||||
assert msg2.is_encrypted()
|
|
||||||
|
|
||||||
|
|
||||||
def test_forward_own_message(acfactory, lp):
|
def test_forward_own_message(acfactory, lp):
|
||||||
|
|||||||
Reference in New Issue
Block a user