refactor(deltachat-rpc-client): add helper functions to wait for securejoin

This commit is contained in:
link2xt
2023-11-17 10:23:01 +00:00
parent 255fbe94f7
commit acf1faf151
2 changed files with 24 additions and 44 deletions

View File

@@ -271,6 +271,18 @@ class Account:
if event.kind == EventType.INCOMING_MSG: if event.kind == EventType.INCOMING_MSG:
return event return event
def wait_for_securejoin_inviter_success(self):
while True:
event = self.wait_for_event()
if event["kind"] == "SecurejoinInviterProgress" and event["progress"] == 1000:
break
def wait_for_securejoin_joiner_success(self):
while True:
event = self.wait_for_event()
if event["kind"] == "SecurejoinJoinerProgress" and event["progress"] == 1000:
break
def get_fresh_messages_in_arrival_order(self) -> List[Message]: def get_fresh_messages_in_arrival_order(self) -> List[Message]:
"""Return fresh messages list sorted in the order of their arrival, with ascending IDs.""" """Return fresh messages list sorted in the order of their arrival, with ascending IDs."""
warn( warn(

View File

@@ -9,20 +9,14 @@ def test_qr_setup_contact(acfactory) -> None:
qr_code, _svg = alice.get_qr_code() qr_code, _svg = alice.get_qr_code()
bob.secure_join(qr_code) bob.secure_join(qr_code)
while True: alice.wait_for_securejoin_inviter_success()
event = alice.wait_for_event()
if event["kind"] == "SecurejoinInviterProgress" and event["progress"] == 1000:
break
# Test that Alice verified Bob's profile. # Test that Alice verified Bob's profile.
alice_contact_bob = alice.get_contact_by_addr(bob.get_config("addr")) alice_contact_bob = alice.get_contact_by_addr(bob.get_config("addr"))
alice_contact_bob_snapshot = alice_contact_bob.get_snapshot() alice_contact_bob_snapshot = alice_contact_bob.get_snapshot()
assert alice_contact_bob_snapshot.is_verified assert alice_contact_bob_snapshot.is_verified
while True: bob.wait_for_securejoin_joiner_success()
event = bob.wait_for_event()
if event["kind"] == "SecurejoinJoinerProgress" and event["progress"] == 1000:
break
# Test that Bob verified Alice's profile. # Test that Bob verified Alice's profile.
bob_contact_alice = bob.get_contact_by_addr(alice.get_config("addr")) bob_contact_alice = bob.get_contact_by_addr(alice.get_config("addr"))
@@ -39,20 +33,15 @@ def test_qr_securejoin(acfactory):
logging.info("Bob joins verified group") logging.info("Bob joins verified group")
qr_code, _svg = alice_chat.get_qr_code() qr_code, _svg = alice_chat.get_qr_code()
bob.secure_join(qr_code) bob.secure_join(qr_code)
while True:
event = alice.wait_for_event() alice.wait_for_securejoin_inviter_success()
if event.kind == "SecurejoinInviterProgress" and event["progress"] == 1000:
break
# Test that Alice verified Bob's profile. # Test that Alice verified Bob's profile.
alice_contact_bob = alice.get_contact_by_addr(bob.get_config("addr")) alice_contact_bob = alice.get_contact_by_addr(bob.get_config("addr"))
alice_contact_bob_snapshot = alice_contact_bob.get_snapshot() alice_contact_bob_snapshot = alice_contact_bob.get_snapshot()
assert alice_contact_bob_snapshot.is_verified assert alice_contact_bob_snapshot.is_verified
while True: bob.wait_for_securejoin_joiner_success()
event = bob.wait_for_event()
if event["kind"] == "SecurejoinJoinerProgress" and event["progress"] == 1000:
break
# Test that Bob verified Alice's profile. # Test that Bob verified Alice's profile.
bob_contact_alice = bob.get_contact_by_addr(alice.get_config("addr")) bob_contact_alice = bob.get_contact_by_addr(alice.get_config("addr"))
@@ -97,10 +86,7 @@ def test_qr_readreceipt(acfactory) -> None:
charlie.secure_join(qr_code) charlie.secure_join(qr_code)
for joiner in [bob, charlie]: for joiner in [bob, charlie]:
while True: joiner.wait_for_securejoin_joiner_success()
event = joiner.wait_for_event()
if event["kind"] == "SecurejoinJoinerProgress" and event["progress"] == 1000:
break
logging.info("Alice creates a verified group") logging.info("Alice creates a verified group")
group = alice.create_group("Group", protect=True) group = alice.create_group("Group", protect=True)
@@ -163,10 +149,7 @@ def test_verified_group_recovery(acfactory) -> None:
logging.info("ac2 joins verified group") logging.info("ac2 joins verified group")
qr_code, _svg = chat.get_qr_code() qr_code, _svg = chat.get_qr_code()
ac2.secure_join(qr_code) ac2.secure_join(qr_code)
while True: ac1.wait_for_securejoin_inviter_success()
event = ac1.wait_for_event()
if event.kind == "SecurejoinInviterProgress" and event["progress"] == 1000:
break
# ac1 has ac2 directly verified. # ac1 has ac2 directly verified.
ac1_contact_ac2 = ac1.get_contact_by_addr(ac2.get_config("addr")) ac1_contact_ac2 = ac1.get_contact_by_addr(ac2.get_config("addr"))
@@ -174,10 +157,7 @@ def test_verified_group_recovery(acfactory) -> None:
logging.info("ac3 joins verified group") logging.info("ac3 joins verified group")
ac3_chat = ac3.secure_join(qr_code) ac3_chat = ac3.secure_join(qr_code)
while True: ac1.wait_for_securejoin_inviter_success()
event = ac1.wait_for_event()
if event.kind == "SecurejoinInviterProgress" and event["progress"] == 1000:
break
logging.info("ac2 logs in on a new device") logging.info("ac2 logs in on a new device")
ac2 = acfactory.resetup_account(ac2) ac2 = acfactory.resetup_account(ac2)
@@ -186,10 +166,7 @@ def test_verified_group_recovery(acfactory) -> None:
qr_code, _svg = ac3.get_qr_code() qr_code, _svg = ac3.get_qr_code()
ac2.secure_join(qr_code) ac2.secure_join(qr_code)
while True: ac3.wait_for_securejoin_inviter_success()
event = ac3.wait_for_event()
if event.kind == "SecurejoinInviterProgress" and event["progress"] == 1000:
break
logging.info("ac3 sends a message to the group") logging.info("ac3 sends a message to the group")
assert len(ac3_chat.get_contacts()) == 3 assert len(ac3_chat.get_contacts()) == 3
@@ -236,10 +213,7 @@ def test_verified_group_member_added_recovery(acfactory) -> None:
logging.info("ac2 joins verified group") logging.info("ac2 joins verified group")
qr_code, _svg = chat.get_qr_code() qr_code, _svg = chat.get_qr_code()
ac2.secure_join(qr_code) ac2.secure_join(qr_code)
while True: ac1.wait_for_securejoin_inviter_success()
event = ac1.wait_for_event()
if event.kind == "SecurejoinInviterProgress" and event["progress"] == 1000:
break
# ac1 has ac2 directly verified. # ac1 has ac2 directly verified.
ac1_contact_ac2 = ac1.get_contact_by_addr(ac2.get_config("addr")) ac1_contact_ac2 = ac1.get_contact_by_addr(ac2.get_config("addr"))
@@ -247,10 +221,7 @@ def test_verified_group_member_added_recovery(acfactory) -> None:
logging.info("ac3 joins verified group") logging.info("ac3 joins verified group")
ac3_chat = ac3.secure_join(qr_code) ac3_chat = ac3.secure_join(qr_code)
while True: ac1.wait_for_securejoin_inviter_success()
event = ac1.wait_for_event()
if event.kind == "SecurejoinInviterProgress" and event["progress"] == 1000:
break
logging.info("ac2 logs in on a new device") logging.info("ac2 logs in on a new device")
ac2 = acfactory.resetup_account(ac2) ac2 = acfactory.resetup_account(ac2)
@@ -259,10 +230,7 @@ def test_verified_group_member_added_recovery(acfactory) -> None:
qr_code, _svg = ac3.get_qr_code() qr_code, _svg = ac3.get_qr_code()
ac2.secure_join(qr_code) ac2.secure_join(qr_code)
while True: ac3.wait_for_securejoin_inviter_success()
event = ac3.wait_for_event()
if event.kind == "SecurejoinInviterProgress" and event["progress"] == 1000:
break
logging.info("ac3 sends a message to the group") logging.info("ac3 sends a message to the group")
assert len(ac3_chat.get_contacts()) == 3 assert len(ac3_chat.get_contacts()) == 3