From 46d31a91da57d5430acaf97464d064e238c73939 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Wed, 27 Mar 2024 13:17:33 +0100 Subject: [PATCH] properly startup metadata service and add online test for metadata --- .../src/chatmaild/chatmail-metadata.service.f | 2 +- chatmaild/src/chatmaild/metadata.py | 16 +++++----- cmdeploy/pyproject.toml | 1 + cmdeploy/src/cmdeploy/__init__.py | 1 + .../cmdeploy/tests/online/test_2_deltachat.py | 32 ++++++++++++++++++- 5 files changed, 42 insertions(+), 10 deletions(-) diff --git a/chatmaild/src/chatmaild/chatmail-metadata.service.f b/chatmaild/src/chatmaild/chatmail-metadata.service.f index ffd74b1..6d4bb9a 100644 --- a/chatmaild/src/chatmaild/chatmail-metadata.service.f +++ b/chatmaild/src/chatmaild/chatmail-metadata.service.f @@ -2,7 +2,7 @@ Description=Chatmail dict proxy for IMAP METADATA [Service] -ExecStart={execpath} /run/dovecot/metadata.socket vmail {config_path} /home/vmail/metadata +ExecStart={execpath} /run/dovecot/metadata.socket vmail /home/vmail/mail/{mail_domain} Restart=always RestartSec=30 diff --git a/chatmaild/src/chatmaild/metadata.py b/chatmaild/src/chatmaild/metadata.py index dc40593..6894767 100644 --- a/chatmaild/src/chatmaild/metadata.py +++ b/chatmaild/src/chatmaild/metadata.py @@ -8,7 +8,6 @@ from socketserver import ( StreamRequestHandler, ThreadingMixIn, ) -from .config import read_config import sys import logging import os @@ -147,15 +146,16 @@ class ThreadedUnixStreamServer(ThreadingMixIn, UnixStreamServer): def main(): - socket, username, config, metadata_dir = sys.argv[1:] + socket, username, vmail_dir = sys.argv[1:] passwd_entry = pwd.getpwnam(username) - # XXX config is not currently used - config = read_config(config) - metadata_dir = Path(metadata_dir) - if not metadata_dir.exists(): - metadata_dir.mkdir() - notifier = Notifier(metadata_dir) + vmail_dir = Path(vmail_dir) + + if not vmail_dir.exists(): + logging.error("vmail dir does not exist: %r", vmail_dir) + return 1 + + notifier = Notifier(vmail_dir) class Handler(StreamRequestHandler): def handle(self): diff --git a/cmdeploy/pyproject.toml b/cmdeploy/pyproject.toml index 060865c..3502a30 100644 --- a/cmdeploy/pyproject.toml +++ b/cmdeploy/pyproject.toml @@ -19,6 +19,7 @@ dependencies = [ "black", "pytest", "pytest-xdist", + "imap_tools", ] [project.scripts] diff --git a/cmdeploy/src/cmdeploy/__init__.py b/cmdeploy/src/cmdeploy/__init__.py index eb3ae94..2c14909 100644 --- a/cmdeploy/src/cmdeploy/__init__.py +++ b/cmdeploy/src/cmdeploy/__init__.py @@ -108,6 +108,7 @@ def _install_remote_venv_with_chatmaild(config) -> None: execpath=f"{remote_venv_dir}/bin/{fn}", config_path=remote_chatmail_inipath, remote_venv_dir=remote_venv_dir, + mail_domain=config.mail_domain, ) source_path = importlib.resources.files("chatmaild").joinpath(f"{fn}.service.f") content = source_path.read_text().format(**params).encode() diff --git a/cmdeploy/src/cmdeploy/tests/online/test_2_deltachat.py b/cmdeploy/src/cmdeploy/tests/online/test_2_deltachat.py index 7c3a361..502b41b 100644 --- a/cmdeploy/src/cmdeploy/tests/online/test_2_deltachat.py +++ b/cmdeploy/src/cmdeploy/tests/online/test_2_deltachat.py @@ -5,6 +5,33 @@ import random import pytest import requests import ipaddress +import imap_tools + + +@pytest.fixture +def imap_mailbox(cmfactory): + (ac1,) = cmfactory.get_online_accounts(1) + user = ac1.get_config("addr") + password = ac1.get_config("mail_pw") + mailbox = imap_tools.MailBox(user.split("@")[1]) + mailbox.login(user, password) + return mailbox + + +class TestMetadataTokens: + "Tests that use Metadata extension for storing tokens" + + def test_set_get_metadata(self, imap_mailbox): + "set and get metadata token for an account" + client = imap_mailbox.client + client.send(b'a01 SETMETADATA INBOX (/private/devicetoken "l1kj23lk123" )\n') + res = client.readline() + assert b"OK Setmetadata completed" in res + client.send(b"a02 GETMETADATA INBOX /private/devicetoken\n") + res = client.readline() + assert res[:1] == b"*" + res = client.readline().strip()[:-1] + assert res == b"l1kj23lk123" class TestEndToEndDeltaChat: @@ -75,7 +102,10 @@ class TestEndToEndDeltaChat: ) lp.indent("good, message sending failed because quota was exceeded") return - if "stored mail into mailbox 'inbox'" in line or "saved mail to inbox" in line: + if ( + "stored mail into mailbox 'inbox'" in line + or "saved mail to inbox" in line + ): saved_ok += 1 print(f"{saved_ok}: {line}") if saved_ok >= num_to_send: