Files
cc-ci/tests/mailu/functional/test_mail_flow.py
autonomic-bot 9a7772563a style: repo-wide lint pass — make the lint gate green again
Push builds have been RED on the lint step since ~build 209 from accumulated
formatting drift. This is the mechanical cleanup: ruff format + ruff --fix
(UP038 isinstance unions, SIM105 contextlib.suppress, UP031 f-strings, SIM115
tempfile context manager), shfmt -i 2 -ci, nixpkgs-fmt/statix/deadnix (merged
attrsets, dropped unused lib args), yamllint, and shell quoting fixes in
tests/lasuite-docs/setup_custom_tests.sh. No behaviour changes intended;
lint: PASS, unit tests: 138 passed.
2026-06-09 21:56:15 +00:00

55 lines
2.5 KiB
Python

"""mailu — recipe-specific functional test #2 (Phase 2 P3, the characteristic end-to-end mail flow).
Provision a mailbox, INJECT a uniquely-marked message to it via the postfix container's local
`sendmail` (locally-originated → not greylisted, no auth/TLS needed), then VERIFY it was DELIVERED
and STORED by polling dovecot's `doveadm search` in the imap container. This is mailu's defining
behaviour (it is a mail server): a real postfix → rspamd → dovecot deliver→store→fetch round-trip,
not an API/health stand-in.
We use the in-container mail tools (sendmail/doveadm) rather than the host network ports because the
TLS_FLAVOR=notls deploy makes dovecot refuse plaintext auth over the network (143) — the in-container
path exercises the same delivery/storage stack without that constraint, and avoids rspamd greylisting
of network senders.
"""
from __future__ import annotations
import os
import sys
import time
import uuid
sys.path.insert(0, os.path.dirname(__file__))
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", "..", "runner"))
import _mailu # noqa: E402
from harness import lifecycle # noqa: E402
def test_send_and_receive_mail(live_app):
mail_domain = live_app
local = "ccci-flow-" + uuid.uuid4().hex[:8]
password = "CcCi-" + uuid.uuid4().hex[:16] + "-Aa1!"
_mailu.ensure_domain(live_app, mail_domain)
email_addr = _mailu.create_user(live_app, local, mail_domain, password)
marker = "ccci-mailflow-" + uuid.uuid4().hex
sender = f"admin@{mail_domain}"
# Inject via the postfix container's local sendmail (locally-originated; no greylist/auth/TLS).
msg = f"From: {sender}\\nTo: {email_addr}\\nSubject: {marker}\\n\\nbody {marker}\\n"
inject = f"printf '{msg}' | sendmail -f {sender} {email_addr}"
lifecycle.exec_in_app(live_app, ["sh", "-c", inject], service="smtp")
# Poll dovecot for the stored message (INBOX, then Junk in case rspamd files it).
deadline = time.time() + 150
while time.time() < deadline:
for box in ("INBOX", "Junk"):
query = f"doveadm search -u '{email_addr}' mailbox {box} " f"header subject '{marker}'"
out = lifecycle.exec_in_app(live_app, ["sh", "-c", query], service="imap")
if out.strip(): # a non-empty result = "<mailbox-guid> <uid>" → message stored
return
time.sleep(5)
raise AssertionError(
f"mail with subject {marker!r} injected to {email_addr} was not delivered/stored "
f"(doveadm search found nothing in INBOX/Junk within the postfix→rspamd→dovecot window)"
)