From 1651917a578f96a1af9b1f2f9f4cdbe2bbbf2f50 Mon Sep 17 00:00:00 2001 From: missytake Date: Thu, 12 Mar 2026 23:04:21 +0100 Subject: [PATCH] tests: adjust tests to [ipv4] mail_domain --- .../src/cmdeploy/tests/online/test_0_login.py | 8 ++--- .../src/cmdeploy/tests/online/test_0_qr.py | 16 ++++----- .../src/cmdeploy/tests/online/test_1_basic.py | 6 ++-- .../cmdeploy/tests/online/test_2_deltachat.py | 4 +-- cmdeploy/src/cmdeploy/tests/plugin.py | 33 +++++++++++-------- 5 files changed, 37 insertions(+), 30 deletions(-) diff --git a/cmdeploy/src/cmdeploy/tests/online/test_0_login.py b/cmdeploy/src/cmdeploy/tests/online/test_0_login.py index e5c2b857..bcfd171a 100644 --- a/cmdeploy/src/cmdeploy/tests/online/test_0_login.py +++ b/cmdeploy/src/cmdeploy/tests/online/test_0_login.py @@ -8,11 +8,11 @@ from chatmaild.config import read_config from cmdeploy.cmdeploy import main -def test_init(tmp_path, maildomain): +def test_init(tmp_path, maildomain_sanitized): inipath = tmp_path.joinpath("chatmail.ini") - main(["init", "--config", str(inipath), maildomain]) + main(["init", "--config", str(inipath), maildomain_sanitized]) config = read_config(inipath) - assert config.mail_domain == maildomain + assert config.mail_domain.strip("[").strip("]") == maildomain_sanitized def test_capabilities(imap): @@ -92,7 +92,7 @@ def test_concurrent_logins_same_account( def test_no_vrfy(chatmail_config): domain = chatmail_config.mail_domain - s = smtplib.SMTP(domain) + s = smtplib.SMTP(domain.strip("[").strip("]")) s.starttls() s.putcmd("vrfy", f"wrongaddress@{chatmail_config.mail_domain}") diff --git a/cmdeploy/src/cmdeploy/tests/online/test_0_qr.py b/cmdeploy/src/cmdeploy/tests/online/test_0_qr.py index b916e696..0a6fec62 100644 --- a/cmdeploy/src/cmdeploy/tests/online/test_0_qr.py +++ b/cmdeploy/src/cmdeploy/tests/online/test_0_qr.py @@ -10,31 +10,31 @@ def test_gen_qr_png_data(maildomain): @pytest.mark.filterwarnings("ignore::urllib3.exceptions.InsecureRequestWarning") -def test_fastcgi_working(maildomain, chatmail_config): - url = f"https://{maildomain}/new" +def test_fastcgi_working(maildomain_sanitized, chatmail_config): + url = f"https://{maildomain_sanitized}/new" print(url) verify = chatmail_config.tls_cert_mode == "acme" res = requests.post(url, verify=verify) - assert maildomain in res.json().get("email") + assert maildomain_sanitized in res.json().get("email") assert len(res.json().get("password")) > chatmail_config.password_min_length @pytest.mark.filterwarnings("ignore::urllib3.exceptions.InsecureRequestWarning") -def test_newemail_configure(maildomain, rpc, chatmail_config): +def test_newemail_configure(maildomain_sanitized, rpc, chatmail_config): """Test configuring accounts by scanning a QR code works.""" - url = f"DCACCOUNT:https://{maildomain}/new" + url = f"DCACCOUNT:https://{maildomain_sanitized}/new" for i in range(3): account_id = rpc.add_account() if chatmail_config.tls_cert_mode == "self": # deltachat core's rustls rejects self-signed HTTPS certs during # set_config_from_qr, so fetch credentials via requests instead - res = requests.post(f"https://{maildomain}/new", verify=False) + res = requests.post(f"https://{maildomain_sanitized}/new", verify=False) data = res.json() rpc.add_or_update_transport(account_id, { "addr": data["email"], "password": data["password"], - "imapServer": maildomain, - "smtpServer": maildomain, + "imapServer": maildomain_sanitized, + "smtpServer": maildomain_sanitized, "certificateChecks": "acceptInvalidCertificates", }) else: diff --git a/cmdeploy/src/cmdeploy/tests/online/test_1_basic.py b/cmdeploy/src/cmdeploy/tests/online/test_1_basic.py index 7ff23b5b..a5072402 100644 --- a/cmdeploy/src/cmdeploy/tests/online/test_1_basic.py +++ b/cmdeploy/src/cmdeploy/tests/online/test_1_basic.py @@ -21,6 +21,8 @@ class TestSSHExecutor: assert out == out2 def test_perform_initial(self, sshexec, maildomain): + if "[" in maildomain: + pytest.skip("Relay doesn't have a domain") res = sshexec( remote.rdns.perform_initial_checks, kwargs=dict(mail_domain=maildomain) ) @@ -131,7 +133,7 @@ def test_authenticated_from(cmsetup, maildata): @pytest.mark.parametrize("from_addr", ["fake@example.org", "fake@testrun.org"]) def test_reject_missing_dkim(cmsetup, maildata, from_addr): - domain = cmsetup.maildomain + domain = cmsetup.maildomain.strip("[").strip("]") sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.settimeout(10) try: @@ -143,7 +145,7 @@ def test_reject_missing_dkim(cmsetup, maildata, from_addr): msg = maildata( "encrypted.eml", from_addr=from_addr, to_addr=recipient.addr ).as_string() - conn = smtplib.SMTP(cmsetup.maildomain, 25, timeout=10) + conn = smtplib.SMTP(cmsetup.maildomain.strip("[").strip("]"), 25, timeout=10) conn.starttls() with conn as s: diff --git a/cmdeploy/src/cmdeploy/tests/online/test_2_deltachat.py b/cmdeploy/src/cmdeploy/tests/online/test_2_deltachat.py index 53e3846a..57392d7d 100644 --- a/cmdeploy/src/cmdeploy/tests/online/test_2_deltachat.py +++ b/cmdeploy/src/cmdeploy/tests/online/test_2_deltachat.py @@ -15,7 +15,7 @@ def imap_mailbox(cmfactory, ssl_context): (ac1,) = cmfactory.get_online_accounts(1) user = ac1.get_config("addr") password = ac1.get_config("mail_pw") - host = user.split("@")[1] + host = user.split("@")[1].strip("[").strip("]") mailbox = imap_tools.MailBox(host, ssl_context=ssl_context) mailbox.login(user, password) mailbox.dc_ac = ac1 @@ -178,7 +178,7 @@ def test_hide_senders_ip_address(cmfactory, ssl_context): chat.send_text("testing submission header cleanup") user2.wait_for_incoming_msg() addr = user2.get_config("addr") - host = addr.split("@")[1] + host = addr.split("@")[1].strip("[").strip("]") pw = user2.get_config("mail_pw") mailbox = imap_tools.MailBox(host, ssl_context=ssl_context) mailbox.login(addr, pw) diff --git a/cmdeploy/src/cmdeploy/tests/plugin.py b/cmdeploy/src/cmdeploy/tests/plugin.py index 34f258df..ef08b233 100644 --- a/cmdeploy/src/cmdeploy/tests/plugin.py +++ b/cmdeploy/src/cmdeploy/tests/plugin.py @@ -61,8 +61,13 @@ def maildomain(chatmail_config): @pytest.fixture(scope="session") -def sshdomain(maildomain): - return os.environ.get("CHATMAIL_SSH", maildomain) +def maildomain_sanitized(maildomain): + return maildomain.strip("[").strip("]") + + +@pytest.fixture(scope="session") +def sshdomain(maildomain_sanitized): + return os.environ.get("CHATMAIL_SSH", maildomain_sanitized) @pytest.fixture @@ -75,7 +80,7 @@ def maildomain2(): @pytest.fixture def sshdomain2(maildomain2): - return os.environ.get("CHATMAIL_SSH2", maildomain2) + return os.environ.get("CHATMAIL_SSH2", maildomain2.strip("[").strip("]")) def pytest_report_header(): @@ -176,14 +181,14 @@ def ssl_context(chatmail_config): @pytest.fixture -def imap(maildomain, ssl_context): - return ImapConn(maildomain, ssl_context=ssl_context) +def imap(maildomain_sanitized, ssl_context): + return ImapConn(maildomain_sanitized, ssl_context=ssl_context) @pytest.fixture -def make_imap_connection(maildomain, ssl_context): +def make_imap_connection(maildomain_sanitized, ssl_context): def make_imap_connection(): - conn = ImapConn(maildomain, ssl_context=ssl_context) + conn = ImapConn(maildomain_sanitized, ssl_context=ssl_context) conn.connect() return conn @@ -227,14 +232,14 @@ class ImapConn: @pytest.fixture -def smtp(maildomain, ssl_context): - return SmtpConn(maildomain, ssl_context=ssl_context) +def smtp(maildomain_sanitized, ssl_context): + return SmtpConn(maildomain_sanitized, ssl_context=ssl_context) @pytest.fixture -def make_smtp_connection(maildomain, ssl_context): +def make_smtp_connection(maildomain_sanitized, ssl_context): def make_smtp_connection(): - conn = SmtpConn(maildomain, ssl_context=ssl_context) + conn = SmtpConn(maildomain_sanitized, ssl_context=ssl_context) conn.connect() return conn @@ -321,8 +326,8 @@ class ChatmailACFactory: "password": password, # Setting server explicitly skips requesting autoconfig XML, # see https://datatracker.ietf.org/doc/draft-ietf-mailmaint-autoconfig/ - "imapServer": domain, - "smtpServer": domain, + "imapServer": domain.strip("[").strip("]"), + "smtpServer": domain.strip("[").strip("]"), } if self.chatmail_config.tls_cert_mode == "self": transport["certificateChecks"] = "acceptInvalidCertificates" @@ -454,7 +459,7 @@ class CMSetup: class CMUser: def __init__(self, maildomain, addr, password, ssl_context=None): - self.maildomain = maildomain + self.maildomain = maildomain.strip("[").strip("]") self.addr = addr self.password = password self.ssl_context = ssl_context