mirror of
https://github.com/chatmail/relay.git
synced 2026-05-22 13:58:07 +00:00
cleanup dead code, clarify others
This commit is contained in:
4
.github/workflows/ci-no-dns.yaml
vendored
4
.github/workflows/ci-no-dns.yaml
vendored
@@ -9,6 +9,8 @@ on:
|
|||||||
pull_request:
|
pull_request:
|
||||||
branches: [ "main" ]
|
branches: [ "main" ]
|
||||||
|
|
||||||
|
permissions: {}
|
||||||
|
|
||||||
# Newest push wins: Prevents multiple runs from clashing and wasting runner efforts
|
# Newest push wins: Prevents multiple runs from clashing and wasting runner efforts
|
||||||
concurrency:
|
concurrency:
|
||||||
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
|
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
|
||||||
@@ -18,7 +20,7 @@ concurrency:
|
|||||||
jobs:
|
jobs:
|
||||||
no-dns:
|
no-dns:
|
||||||
name: LXC deploy and test
|
name: LXC deploy and test
|
||||||
uses: chatmail/cmlxc/.github/workflows/lxc-test.yml@v0.14.1
|
uses: chatmail/cmlxc/.github/workflows/lxc-test.yml@v0.14.5
|
||||||
with:
|
with:
|
||||||
cmlxc_commands: |
|
cmlxc_commands: |
|
||||||
cmlxc init
|
cmlxc init
|
||||||
|
|||||||
2
.github/workflows/ci.yaml
vendored
2
.github/workflows/ci.yaml
vendored
@@ -57,7 +57,7 @@ jobs:
|
|||||||
|
|
||||||
lxc-test:
|
lxc-test:
|
||||||
name: LXC deploy and test
|
name: LXC deploy and test
|
||||||
uses: chatmail/cmlxc/.github/workflows/lxc-test.yml@v0.14.1
|
uses: chatmail/cmlxc/.github/workflows/lxc-test.yml@v0.14.5
|
||||||
with:
|
with:
|
||||||
cmlxc_commands: |
|
cmlxc_commands: |
|
||||||
cmlxc init
|
cmlxc init
|
||||||
|
|||||||
@@ -200,13 +200,6 @@ def is_valid_ipv4(address: str) -> bool:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def format_arpa_address(address: str) -> str:
|
|
||||||
if is_valid_ipv4(address):
|
|
||||||
return ipaddress.IPv4Address(address).reverse_pointer
|
|
||||||
DomainValidator().validate_domain_re(address)
|
|
||||||
return address
|
|
||||||
|
|
||||||
|
|
||||||
def format_mail_domain(raw_domain: str) -> str:
|
def format_mail_domain(raw_domain: str) -> str:
|
||||||
if is_valid_ipv4(raw_domain):
|
if is_valid_ipv4(raw_domain):
|
||||||
return f"[{raw_domain}]"
|
return f"[{raw_domain}]"
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ from contextlib import nullcontext as does_not_raise
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from chatmaild.config import (
|
from chatmaild.config import (
|
||||||
format_arpa_address,
|
|
||||||
format_mail_domain,
|
format_mail_domain,
|
||||||
is_valid_ipv4,
|
is_valid_ipv4,
|
||||||
parse_size_mb,
|
parse_size_mb,
|
||||||
@@ -165,20 +164,6 @@ def test_is_valid_ipv4(input, result):
|
|||||||
assert result == is_valid_ipv4(input)
|
assert result == is_valid_ipv4(input)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
|
||||||
["input", "result", "exception"],
|
|
||||||
[
|
|
||||||
("example.org", "example.org", does_not_raise()),
|
|
||||||
("1.3.3.7", "7.3.3.1.in-addr.arpa", does_not_raise()),
|
|
||||||
("fe::1", None, pytest.raises(ValueError)),
|
|
||||||
("12394142", None, pytest.raises(ValueError)),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
def test_format_arpa_address(input, result, exception):
|
|
||||||
with exception:
|
|
||||||
assert result == format_arpa_address(input)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
["input", "result", "exception"],
|
["input", "result", "exception"],
|
||||||
[
|
[
|
||||||
|
|||||||
@@ -540,7 +540,7 @@ def deploy_chatmail(config_path: Path, disable_mail: bool, website_only: bool) -
|
|||||||
WebsiteDeployer(config),
|
WebsiteDeployer(config),
|
||||||
ChatmailVenvDeployer(config),
|
ChatmailVenvDeployer(config),
|
||||||
MtastsDeployer(),
|
MtastsDeployer(),
|
||||||
OpendkimDeployer(config.mail_domain),
|
*([] if config.ipv4_relay else [OpendkimDeployer(bare_host)]),
|
||||||
# Dovecot should be started before Postfix
|
# Dovecot should be started before Postfix
|
||||||
# because it creates authentication socket
|
# because it creates authentication socket
|
||||||
# required by Postfix.
|
# required by Postfix.
|
||||||
|
|||||||
3
cmdeploy/src/cmdeploy/external/deployer.py
vendored
3
cmdeploy/src/cmdeploy/external/deployer.py
vendored
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
from pyinfra import host
|
from pyinfra import host
|
||||||
from pyinfra.facts.files import File
|
from pyinfra.facts.files import File
|
||||||
|
|
||||||
@@ -40,5 +39,3 @@ class ExternalTlsDeployer(Deployer):
|
|||||||
running=True,
|
running=True,
|
||||||
enabled=True,
|
enabled=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,10 +5,10 @@ import subprocess
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
from chatmaild.config import is_valid_ipv4
|
||||||
|
|
||||||
from cmdeploy import remote
|
from cmdeploy import remote
|
||||||
from cmdeploy.cmdeploy import get_sshexec
|
from cmdeploy.cmdeploy import get_sshexec
|
||||||
from chatmaild.config import is_valid_ipv4
|
|
||||||
|
|
||||||
|
|
||||||
class TestSSHExecutor:
|
class TestSSHExecutor:
|
||||||
@@ -64,8 +64,10 @@ class TestSSHExecutor:
|
|||||||
else:
|
else:
|
||||||
pytest.fail("didn't raise exception")
|
pytest.fail("didn't raise exception")
|
||||||
|
|
||||||
def test_opendkim_restarted(self, sshexec):
|
def test_opendkim_restarted(self, sshexec, maildomain):
|
||||||
"""check that opendkim is not running for longer than a day."""
|
"""check that opendkim is not running for longer than a day."""
|
||||||
|
if is_valid_ipv4(maildomain):
|
||||||
|
pytest.skip(f"{maildomain} is an IPv4 relay, opendkim is not installed")
|
||||||
cmd = "systemctl show opendkim --timestamp=utc --property=ActiveEnterTimestamp"
|
cmd = "systemctl show opendkim --timestamp=utc --property=ActiveEnterTimestamp"
|
||||||
out = sshexec(call=remote.rshell.shell, kwargs=dict(command=cmd))
|
out = sshexec(call=remote.rshell.shell, kwargs=dict(command=cmd))
|
||||||
datestring = out.split("=")[1]
|
datestring = out.split("=")[1]
|
||||||
@@ -293,4 +295,6 @@ def test_nginx_access_log_only_defined_once(sshdomain):
|
|||||||
kwargs=dict(command="nginx -T 2>/dev/null"),
|
kwargs=dict(command="nginx -T 2>/dev/null"),
|
||||||
)
|
)
|
||||||
access_logs = [l for l in conf.splitlines() if l.strip().startswith("access_log")]
|
access_logs = [l for l in conf.splitlines() if l.strip().startswith("access_log")]
|
||||||
assert len(access_logs) == 1, f"expected 1 access_log, found {len(access_logs)}: {access_logs}"
|
assert len(access_logs) == 1, (
|
||||||
|
f"expected 1 access_log, found {len(access_logs)}: {access_logs}"
|
||||||
|
)
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import imaplib
|
import imaplib
|
||||||
import ipaddress
|
|
||||||
import itertools
|
import itertools
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
@@ -10,20 +9,11 @@ import time
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from chatmaild.config import read_config, format_mail_domain, is_valid_ipv4
|
from chatmaild.config import format_mail_domain, is_valid_ipv4, read_config
|
||||||
|
|
||||||
|
|
||||||
conftestdir = Path(__file__).parent
|
conftestdir = Path(__file__).parent
|
||||||
|
|
||||||
|
|
||||||
def _is_ip(domain):
|
|
||||||
try:
|
|
||||||
ipaddress.ip_address(domain)
|
|
||||||
return True
|
|
||||||
except ValueError:
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def pytest_configure(config):
|
def pytest_configure(config):
|
||||||
config._benchresults = {}
|
config._benchresults = {}
|
||||||
config.addinivalue_line(
|
config.addinivalue_line(
|
||||||
@@ -349,7 +339,7 @@ class ChatmailACFactory:
|
|||||||
account = self.dc.add_account()
|
account = self.dc.add_account()
|
||||||
domain_deliverable = format_mail_domain(domain)
|
domain_deliverable = format_mail_domain(domain)
|
||||||
addr, password = self.gencreds(domain_deliverable)
|
addr, password = self.gencreds(domain_deliverable)
|
||||||
if _is_ip(domain):
|
if is_valid_ipv4(domain):
|
||||||
# Use DCLOGIN scheme with explicit server hosts,
|
# Use DCLOGIN scheme with explicit server hosts,
|
||||||
# matching how madmail presents its addresses to users.
|
# matching how madmail presents its addresses to users.
|
||||||
qr = (
|
qr = (
|
||||||
@@ -423,10 +413,10 @@ class Remote:
|
|||||||
def iter_output(self, logcmd="", ready=None):
|
def iter_output(self, logcmd="", ready=None):
|
||||||
getjournal = "journalctl -f" if not logcmd else logcmd
|
getjournal = "journalctl -f" if not logcmd else logcmd
|
||||||
print(self.sshdomain)
|
print(self.sshdomain)
|
||||||
match self.sshdomain:
|
if self.sshdomain in ("@local", "localhost"):
|
||||||
case "@local": command = []
|
command = []
|
||||||
case "localhost": command = []
|
else:
|
||||||
case _: command = ["ssh", f"root@{self.sshdomain}"]
|
command = ["ssh", f"root@{self.sshdomain}"]
|
||||||
[command.append(arg) for arg in getjournal.split()]
|
[command.append(arg) for arg in getjournal.split()]
|
||||||
popen = subprocess.Popen(
|
popen = subprocess.Popen(
|
||||||
command,
|
command,
|
||||||
|
|||||||
@@ -23,8 +23,7 @@ def make_host(*fact_pairs):
|
|||||||
if cls not in facts:
|
if cls not in facts:
|
||||||
registered = ", ".join(c.__name__ for c in facts)
|
registered = ", ".join(c.__name__ for c in facts)
|
||||||
raise LookupError(
|
raise LookupError(
|
||||||
f"unexpected get_fact({cls.__name__}); "
|
f"unexpected get_fact({cls.__name__}); only registered: {registered}"
|
||||||
f"only registered: {registered}"
|
|
||||||
)
|
)
|
||||||
return facts[cls]
|
return facts[cls]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user