Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions deltachat-rpc-client/src/deltachat_rpc_client/pytestplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import random
import subprocess
import sys
import urllib.parse
from typing import AsyncGenerator, Optional

import pytest
Expand Down Expand Up @@ -282,8 +283,15 @@ def factory(core_version):
channel = gw.remote_exec(remote_bob_loop)
cm = os.environ.get("CHATMAIL_DOMAIN")

# old cores need "ic=3" to accept
# the self-signed cert of an underscore domain
addr, password = acfactory.get_credentials()
dclogin_qr = f"dclogin://{urllib.parse.quote(addr, safe='@')}?p={urllib.parse.quote(password)}&v=1"
if cm and cm.startswith("_"):
dclogin_qr += "&ic=3"

# trigger getting an online account on bob's side
channel.send((accounts_dir, str(rpc_server_path), cm))
channel.send((accounts_dir, str(rpc_server_path), dclogin_qr))

# meanwhile get a local alice account
alice = acfactory.get_online_account()
Expand Down Expand Up @@ -315,10 +323,8 @@ def remote_bob_loop(channel):
import os

from deltachat_rpc_client import DeltaChat, Rpc
from deltachat_rpc_client.pytestplugin import ACFactory

accounts_dir, rpc_server_path, chatmail_domain = channel.receive()
os.environ["CHATMAIL_DOMAIN"] = chatmail_domain
accounts_dir, rpc_server_path, dclogin_qr = channel.receive()

# older core versions don't support specifying rpc_server_path
# so we can't just pass `rpc_server_path` argument to Rpc constructor
Expand All @@ -329,8 +335,16 @@ def remote_bob_loop(channel):
with rpc:
dc = DeltaChat(rpc)
channel.send(dc.rpc.get_system_info()["deltachat_core_version"])
acfactory = ACFactory(dc)
bob = acfactory.get_online_account()

# ACFactory would configure from a "dcaccount" QR,
# which old cores cannot use on underscore domains
bob = dc.add_account()
bob.set_config_from_qr(dclogin_qr)
if not bob.is_configured():
# cores <=2.22 only store login values from a "dclogin" QR
bob.configure()
bob.bring_online()

alice_vcard = channel.receive()
[alice_contact] = bob.import_vcard(alice_vcard)
ns = {"bob": bob, "bob_contact_alice": alice_contact}
Expand Down
6 changes: 5 additions & 1 deletion deltachat-rpc-client/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ def connect(self):
host = user.rsplit("@")[-1]
pw = self.account.get_config("mail_pw")

self.conn = MailBox(host, port, ssl_context=ssl.create_default_context())
ssl_context = ssl.create_default_context()
if host.startswith("_"):
ssl_context.check_hostname = False
ssl_context.verify_mode = ssl.CERT_NONE
self.conn = MailBox(host, port, ssl_context=ssl_context)
self.conn.login(user, pw)

self.select_folder("INBOX")
Expand Down
4 changes: 2 additions & 2 deletions deltachat-rpc-client/tests/test_chatlist_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def test_delivery_status_failed(acfactory: ACFactory) -> None:
assert failing_message.get_snapshot().state == const.MessageState.OUT_FAILED


def test_download_on_demand(acfactory: ACFactory) -> None:
def test_download_on_demand(acfactory: ACFactory, data) -> None:
"""
Test if download on demand emits chatlist update events.
This is only needed for last message in chat, but finding that out is too expensive, so it's always emitted
Expand All @@ -128,7 +128,7 @@ def test_download_on_demand(acfactory: ACFactory) -> None:
msg.get_snapshot().chat.accept()
bob.get_chat_by_id(chat_id).send_message(
"Hello World, this message is bigger than 5 bytes",
file="../test-data/image/screenshot.jpg",
file=data.get_path("image/screenshot.jpg"),
)

message = alice.wait_for_incoming_msg()
Expand Down
6 changes: 6 additions & 0 deletions deltachat-rpc-client/tests/test_iroh_webxdc.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
from deltachat_rpc_client import EventType


@pytest.fixture(autouse=True)
def _xfail_underscore_domain():
if os.environ.get("CHATMAIL_DOMAIN", "").startswith("_"):
pytest.xfail("iroh does not support underscore domains")


@pytest.fixture
def path_to_webxdc(request):
p = request.path.parent.parent.parent.joinpath("test-data/webxdc/chess.xdc")
Expand Down
4 changes: 2 additions & 2 deletions deltachat-rpc-client/tests/test_multitransport.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def test_change_address(acfactory) -> None:
assert sender_addr2 == new_alice_addr


def test_download_on_demand(acfactory) -> None:
def test_download_on_demand(acfactory, data) -> None:
alice, bob = acfactory.get_online_accounts(2)
alice.set_config("download_limit", "1")

Expand All @@ -87,7 +87,7 @@ def test_download_on_demand(acfactory) -> None:

alice.create_chat(bob)
chat_bob_alice = bob.create_chat(alice)
chat_bob_alice.send_message(file="../test-data/image/screenshot.jpg")
chat_bob_alice.send_message(file=data.get_path("image/screenshot.jpg"))
msg = alice.wait_for_incoming_msg()
snapshot = msg.get_snapshot()
assert snapshot.download_state == DownloadState.AVAILABLE
Expand Down
9 changes: 6 additions & 3 deletions deltachat-rpc-client/tests/test_something.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,11 @@ def test_lowercase_address(acfactory) -> None:

def test_configure_ip(acfactory) -> None:
addr, password = acfactory.get_credentials()
domain = addr.rsplit("@")[-1]
if domain.startswith("_"):
pytest.skip("Underscore domains accept invalid certificates")
account = acfactory.get_unconfigured_account()
ip_address = socket.gethostbyname(addr.rsplit("@")[-1])
ip_address = socket.gethostbyname(domain)

with pytest.raises(JsonRpcError):
account.add_or_update_transport(
Expand Down Expand Up @@ -1412,7 +1415,7 @@ def test_synchronize_member_list_on_group_rejoin(acfactory, log):
assert msg.get_snapshot().chat.num_contacts() == 2


def test_large_message(acfactory) -> None:
def test_large_message(acfactory, data) -> None:
"""
Test sending large message without download limit set,
so it is sent with pre-message but downloaded without user interaction.
Expand All @@ -1422,7 +1425,7 @@ def test_large_message(acfactory) -> None:
alice_chat_bob = alice.create_chat(bob)
alice_chat_bob.send_message(
"Hello World, this message is bigger than 5 bytes",
file="../test-data/image/screenshot.jpg",
file=data.get_path("image/screenshot.jpg"),
)

msg = bob.wait_for_incoming_msg()
Expand Down
8 changes: 4 additions & 4 deletions deltachat-rpc-client/tests/test_webxdc.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
def test_webxdc(acfactory) -> None:
def test_webxdc(acfactory, data) -> None:
alice, bob = acfactory.get_online_accounts(2)

alice_contact_bob = alice.create_contact(bob, "Bob")
alice_chat_bob = alice_contact_bob.create_chat()
alice_chat_bob.send_message(text="Let's play chess!", file="../test-data/webxdc/chess.xdc")
alice_chat_bob.send_message(text="Let's play chess!", file=data.get_path("webxdc/chess.xdc"))

event = bob.wait_for_incoming_msg_event()
bob_chat_alice = bob.get_chat_by_id(event.chat_id)
Expand Down Expand Up @@ -43,12 +43,12 @@ def test_webxdc(acfactory) -> None:
]


def test_webxdc_insert_lots_of_updates(acfactory) -> None:
def test_webxdc_insert_lots_of_updates(acfactory, data) -> None:
alice, bob = acfactory.get_online_accounts(2)

alice_contact_bob = alice.create_contact(bob, "Bob")
alice_chat_bob = alice_contact_bob.create_chat()
message = alice_chat_bob.send_message(text="Let's play chess!", file="../test-data/webxdc/chess.xdc")
message = alice_chat_bob.send_message(text="Let's play chess!", file=data.get_path("webxdc/chess.xdc"))

for i in range(2000):
message.send_webxdc_status_update({"payload": str(i)}, "description")