Skip to content

Commit a6febae

Browse files
committed
get tests working on IPv4 only machine
1 parent 4e480c4 commit a6febae

6 files changed

Lines changed: 27 additions & 16 deletions

File tree

chatmaild/src/chatmaild/config.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@ def __init__(self, inipath, params):
2323
self._inipath = inipath
2424
self.mail_domain = params["mail_domain"]
2525
self.mail_domain_hostname = format_arpa_address(params["mail_domain"])
26-
if is_valid_ipv4(params["mail_domain"]):
27-
self.mail_domain_deliverable = f"[{params['mail_domain']}]"
28-
else:
29-
self.mail_domain_deliverable = params["mail_domain"]
26+
self.mail_domain_deliverable = format_deliverable_domain(params["mail_domain"])
3027
self.max_user_send_per_minute = int(params.get("max_user_send_per_minute", 60))
3128
self.max_user_send_burst_size = int(params.get("max_user_send_burst_size", 10))
3229
self.max_mailbox_size = params["max_mailbox_size"]
@@ -182,3 +179,9 @@ def format_arpa_address(address: str) -> str:
182179
parts = address.split(".")
183180
return f"{parts[3]}.{parts[2]}.{parts[1]}.{parts[0]}.in-addr.arpa"
184181
return address
182+
183+
184+
def format_deliverable_domain(mail_domain: str) -> str:
185+
if is_valid_ipv4(mail_domain):
186+
return f"[{mail_domain}]"
187+
return mail_domain

cmdeploy/src/cmdeploy/postfix/master.cf.j2

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,9 @@ filter unix - n n - - lmtp
8080
127.0.0.1:{{ config.postfix_reinject_port }} inet n - n - 100 smtpd
8181
-o syslog_name=postfix/reinject
8282
-o milter_macro_daemon_name=ORIGINATING
83-
{% if config.mail_domain == config.mail_domain_deliverable %}
84-
-o smtpd_milters=unix:opendkim/opendkim.sock
85-
{% endif %}
8683
-o cleanup_service_name=authclean
84+
{% if config.mail_domain == config.mail_domain_deliverable %} -o smtpd_milters=unix:opendkim/opendkim.sock
85+
{% endif %}
8786

8887
# Local SMTP server for reinjecting incoming filtered mail
8988
127.0.0.1:{{ config.postfix_reinject_port_incoming }} inet n - n - 100 smtpd

cmdeploy/src/cmdeploy/tests/online/test_0_login.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,11 @@ def login_smtp_imap(smtp, imap):
9292
def test_no_vrfy(cmfactory, chatmail_config):
9393
ac = cmfactory.get_online_account()
9494
addr = ac.get_config("addr")
95-
domain = chatmail_config.mail_domain
9695

97-
s = smtplib.SMTP(domain)
96+
s = smtplib.SMTP(chatmail_config.mail_domain)
9897
s.starttls()
9998

100-
s.putcmd("vrfy", f"wrongaddress@{chatmail_config.mail_domain}")
99+
s.putcmd("vrfy", f"wrongaddress@{chatmail_config.mail_domain_deliverable}")
101100
result = s.getreply()
102101
print(result)
103102
s.putcmd("vrfy", addr)

cmdeploy/src/cmdeploy/tests/online/test_1_basic.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from cmdeploy import remote
1010
from cmdeploy.cmdeploy import get_sshexec
11+
from chatmaild.config import is_valid_ipv4
1112

1213

1314
class TestSSHExecutor:
@@ -21,6 +22,8 @@ def test_ls(self, sshexec):
2122
assert out == out2
2223

2324
def test_perform_initial(self, sshexec, maildomain):
25+
if is_valid_ipv4(maildomain):
26+
pytest.skip(f"{maildomain} is not a domain")
2427
res = sshexec(
2528
remote.rdns.perform_initial_checks, kwargs=dict(mail_domain=maildomain)
2629
)

cmdeploy/src/cmdeploy/tests/online/test_2_deltachat.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def imap_mailbox(cmfactory, ssl_context):
1515
(ac1,) = cmfactory.get_online_accounts(1)
1616
user = ac1.get_config("addr")
1717
password = ac1.get_config("mail_pw")
18-
host = user.split("@")[1]
18+
host = user.split("@")[1].strip("[").strip("]")
1919
mailbox = imap_tools.MailBox(host, ssl_context=ssl_context)
2020
mailbox.login(user, password)
2121
mailbox.dc_ac = ac1
@@ -178,7 +178,7 @@ def test_hide_senders_ip_address(cmfactory, ssl_context):
178178
chat.send_text("testing submission header cleanup")
179179
user2.wait_for_incoming_msg()
180180
addr = user2.get_config("addr")
181-
host = addr.split("@")[1]
181+
host = addr.split("@")[1].strip("[").strip("]")
182182
pw = user2.get_config("mail_pw")
183183
mailbox = imap_tools.MailBox(host, ssl_context=ssl_context)
184184
mailbox.login(addr, pw)

cmdeploy/src/cmdeploy/tests/plugin.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
from pathlib import Path
1010

1111
import pytest
12-
from chatmaild.config import read_config
12+
from chatmaild.config import read_config, format_deliverable_domain, is_valid_ipv4
13+
1314

1415
conftestdir = Path(__file__).parent
1516

@@ -65,6 +66,11 @@ def maildomain(chatmail_config):
6566
return chatmail_config.mail_domain
6667

6768

69+
@pytest.fixture(scope="session")
70+
def maildomain_deliverable(maildomain):
71+
return format_deliverable_domain(maildomain)
72+
73+
6874
@pytest.fixture(scope="session")
6975
def sshdomain(maildomain):
7076
return os.environ.get("CHATMAIL_SSH", maildomain)
@@ -281,7 +287,7 @@ def gencreds(chatmail_config):
281287
next(count)
282288

283289
def gen(domain=None):
284-
domain = domain if domain else chatmail_config.mail_domain
290+
domain = domain if domain else chatmail_config.mail_domain_deliverable
285291
while 1:
286292
num = next(count)
287293
alphanumeric = "abcdefghijklmnopqrstuvwxyz1234567890"
@@ -320,7 +326,8 @@ def __init__(self, rpc, maildomain, gencreds, chatmail_config):
320326

321327
def _make_transport(self, domain):
322328
"""Build a transport config dict for the given domain."""
323-
addr, password = self.gencreds(domain)
329+
domain_deliverable = format_deliverable_domain(domain)
330+
addr, password = self.gencreds(domain_deliverable)
324331
transport = {
325332
"addr": addr,
326333
"password": password,
@@ -329,7 +336,7 @@ def _make_transport(self, domain):
329336
"imapServer": domain,
330337
"smtpServer": domain,
331338
}
332-
if self.chatmail_config.tls_cert_mode == "self":
339+
if domain.startswith("_") or is_valid_ipv4(domain):
333340
transport["certificateChecks"] = "acceptInvalidCertificates"
334341
return transport
335342

0 commit comments

Comments
 (0)