Skip to content

Commit 41b3f75

Browse files
committed
feat: allow to run the test suite against underscore-domain relays
Such relays serve self-signed certificates, and are created e.g. by cmlxc deploys.
1 parent 30a196c commit 41b3f75

4 files changed

Lines changed: 32 additions & 8 deletions

File tree

deltachat-rpc-client/src/deltachat_rpc_client/pytestplugin.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import random
1010
import subprocess
1111
import sys
12+
import urllib.parse
1213
from typing import AsyncGenerator, Optional
1314

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

286+
# old cores need "ic=3" to accept
287+
# the self-signed cert of an underscore domain
288+
addr, password = acfactory.get_credentials()
289+
dclogin_qr = f"dclogin://{urllib.parse.quote(addr, safe='@')}?p={urllib.parse.quote(password)}&v=1"
290+
if cm and cm.startswith("_"):
291+
dclogin_qr += "&ic=3"
292+
285293
# trigger getting an online account on bob's side
286-
channel.send((accounts_dir, str(rpc_server_path), cm))
294+
channel.send((accounts_dir, str(rpc_server_path), dclogin_qr))
287295

288296
# meanwhile get a local alice account
289297
alice = acfactory.get_online_account()
@@ -315,10 +323,8 @@ def remote_bob_loop(channel):
315323
import os
316324

317325
from deltachat_rpc_client import DeltaChat, Rpc
318-
from deltachat_rpc_client.pytestplugin import ACFactory
319326

320-
accounts_dir, rpc_server_path, chatmail_domain = channel.receive()
321-
os.environ["CHATMAIL_DOMAIN"] = chatmail_domain
327+
accounts_dir, rpc_server_path, dclogin_qr = channel.receive()
322328

323329
# older core versions don't support specifying rpc_server_path
324330
# so we can't just pass `rpc_server_path` argument to Rpc constructor
@@ -329,8 +335,13 @@ def remote_bob_loop(channel):
329335
with rpc:
330336
dc = DeltaChat(rpc)
331337
channel.send(dc.rpc.get_system_info()["deltachat_core_version"])
332-
acfactory = ACFactory(dc)
333-
bob = acfactory.get_online_account()
338+
339+
# ACFactory would configure from a "dcaccount" QR,
340+
# which old cores cannot use on underscore domains
341+
bob = dc.add_account()
342+
bob.set_config_from_qr(dclogin_qr)
343+
bob.bring_online()
344+
334345
alice_vcard = channel.receive()
335346
[alice_contact] = bob.import_vcard(alice_vcard)
336347
ns = {"bob": bob, "bob_contact_alice": alice_contact}

deltachat-rpc-client/tests/conftest.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ def connect(self):
3737
host = user.rsplit("@")[-1]
3838
pw = self.account.get_config("mail_pw")
3939

40-
self.conn = MailBox(host, port, ssl_context=ssl.create_default_context())
40+
ssl_context = ssl.create_default_context()
41+
if host.startswith("_"):
42+
ssl_context.check_hostname = False
43+
ssl_context.verify_mode = ssl.CERT_NONE
44+
self.conn = MailBox(host, port, ssl_context=ssl_context)
4145
self.conn.login(user, pw)
4246

4347
self.select_folder("INBOX")

deltachat-rpc-client/tests/test_iroh_webxdc.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
from deltachat_rpc_client import EventType
1818

1919

20+
@pytest.fixture(autouse=True)
21+
def _xfail_underscore_domain():
22+
if os.environ.get("CHATMAIL_DOMAIN", "").startswith("_"):
23+
pytest.xfail("iroh does not support underscore domains")
24+
25+
2026
@pytest.fixture
2127
def path_to_webxdc(request):
2228
p = request.path.parent.parent.parent.joinpath("test-data/webxdc/chess.xdc")

deltachat-rpc-client/tests/test_something.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,11 @@ def test_lowercase_address(acfactory) -> None:
105105

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

111114
with pytest.raises(JsonRpcError):
112115
account.add_or_update_transport(

0 commit comments

Comments
 (0)