Skip to content

Commit

Permalink
refactor(deltachat-rpc-client): add helper functions to wait for secu…
Browse files Browse the repository at this point in the history
…rejoin
  • Loading branch information
link2xt committed Nov 17, 2023
1 parent 255fbe9 commit acf1faf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 44 deletions.
12 changes: 12 additions & 0 deletions deltachat-rpc-client/src/deltachat_rpc_client/account.py
Expand Up @@ -271,6 +271,18 @@ def wait_for_incoming_msg_event(self):
if event.kind == EventType.INCOMING_MSG:
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]:
"""Return fresh messages list sorted in the order of their arrival, with ascending IDs."""
warn(
Expand Down
56 changes: 12 additions & 44 deletions deltachat-rpc-client/tests/test_securejoin.py
Expand Up @@ -9,20 +9,14 @@ def test_qr_setup_contact(acfactory) -> None:
qr_code, _svg = alice.get_qr_code()
bob.secure_join(qr_code)

while True:
event = alice.wait_for_event()
if event["kind"] == "SecurejoinInviterProgress" and event["progress"] == 1000:
break
alice.wait_for_securejoin_inviter_success()

# Test that Alice verified Bob's profile.
alice_contact_bob = alice.get_contact_by_addr(bob.get_config("addr"))
alice_contact_bob_snapshot = alice_contact_bob.get_snapshot()
assert alice_contact_bob_snapshot.is_verified

while True:
event = bob.wait_for_event()
if event["kind"] == "SecurejoinJoinerProgress" and event["progress"] == 1000:
break
bob.wait_for_securejoin_joiner_success()

# Test that Bob verified Alice's profile.
bob_contact_alice = bob.get_contact_by_addr(alice.get_config("addr"))
Expand All @@ -39,20 +33,15 @@ def test_qr_securejoin(acfactory):
logging.info("Bob joins verified group")
qr_code, _svg = alice_chat.get_qr_code()
bob.secure_join(qr_code)
while True:
event = alice.wait_for_event()
if event.kind == "SecurejoinInviterProgress" and event["progress"] == 1000:
break

alice.wait_for_securejoin_inviter_success()

# Test that Alice verified Bob's profile.
alice_contact_bob = alice.get_contact_by_addr(bob.get_config("addr"))
alice_contact_bob_snapshot = alice_contact_bob.get_snapshot()
assert alice_contact_bob_snapshot.is_verified

while True:
event = bob.wait_for_event()
if event["kind"] == "SecurejoinJoinerProgress" and event["progress"] == 1000:
break
bob.wait_for_securejoin_joiner_success()

# Test that Bob verified Alice's profile.
bob_contact_alice = bob.get_contact_by_addr(alice.get_config("addr"))
Expand Down Expand Up @@ -97,10 +86,7 @@ def test_qr_readreceipt(acfactory) -> None:
charlie.secure_join(qr_code)

for joiner in [bob, charlie]:
while True:
event = joiner.wait_for_event()
if event["kind"] == "SecurejoinJoinerProgress" and event["progress"] == 1000:
break
joiner.wait_for_securejoin_joiner_success()

logging.info("Alice creates a verified group")
group = alice.create_group("Group", protect=True)
Expand Down Expand Up @@ -163,21 +149,15 @@ def test_verified_group_recovery(acfactory) -> None:
logging.info("ac2 joins verified group")
qr_code, _svg = chat.get_qr_code()
ac2.secure_join(qr_code)
while True:
event = ac1.wait_for_event()
if event.kind == "SecurejoinInviterProgress" and event["progress"] == 1000:
break
ac1.wait_for_securejoin_inviter_success()

# ac1 has ac2 directly verified.
ac1_contact_ac2 = ac1.get_contact_by_addr(ac2.get_config("addr"))
assert ac1_contact_ac2.get_snapshot().verifier_id == SpecialContactId.SELF

logging.info("ac3 joins verified group")
ac3_chat = ac3.secure_join(qr_code)
while True:
event = ac1.wait_for_event()
if event.kind == "SecurejoinInviterProgress" and event["progress"] == 1000:
break
ac1.wait_for_securejoin_inviter_success()

logging.info("ac2 logs in on a new device")
ac2 = acfactory.resetup_account(ac2)
Expand All @@ -186,10 +166,7 @@ def test_verified_group_recovery(acfactory) -> None:
qr_code, _svg = ac3.get_qr_code()
ac2.secure_join(qr_code)

while True:
event = ac3.wait_for_event()
if event.kind == "SecurejoinInviterProgress" and event["progress"] == 1000:
break
ac3.wait_for_securejoin_inviter_success()

logging.info("ac3 sends a message to the group")
assert len(ac3_chat.get_contacts()) == 3
Expand Down Expand Up @@ -236,21 +213,15 @@ def test_verified_group_member_added_recovery(acfactory) -> None:
logging.info("ac2 joins verified group")
qr_code, _svg = chat.get_qr_code()
ac2.secure_join(qr_code)
while True:
event = ac1.wait_for_event()
if event.kind == "SecurejoinInviterProgress" and event["progress"] == 1000:
break
ac1.wait_for_securejoin_inviter_success()

# ac1 has ac2 directly verified.
ac1_contact_ac2 = ac1.get_contact_by_addr(ac2.get_config("addr"))
assert ac1_contact_ac2.get_snapshot().verifier_id == SpecialContactId.SELF

logging.info("ac3 joins verified group")
ac3_chat = ac3.secure_join(qr_code)
while True:
event = ac1.wait_for_event()
if event.kind == "SecurejoinInviterProgress" and event["progress"] == 1000:
break
ac1.wait_for_securejoin_inviter_success()

logging.info("ac2 logs in on a new device")
ac2 = acfactory.resetup_account(ac2)
Expand All @@ -259,10 +230,7 @@ def test_verified_group_member_added_recovery(acfactory) -> None:
qr_code, _svg = ac3.get_qr_code()
ac2.secure_join(qr_code)

while True:
event = ac3.wait_for_event()
if event.kind == "SecurejoinInviterProgress" and event["progress"] == 1000:
break
ac3.wait_for_securejoin_inviter_success()

logging.info("ac3 sends a message to the group")
assert len(ac3_chat.get_contacts()) == 3
Expand Down

0 comments on commit acf1faf

Please sign in to comment.