properly startup metadata service and add online test for metadata

This commit is contained in:
holger krekel 2024-03-27 13:17:33 +01:00
parent a8765d8847
commit 46d31a91da
5 changed files with 42 additions and 10 deletions

View File

@ -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

View File

@ -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):

View File

@ -19,6 +19,7 @@ dependencies = [
"black",
"pytest",
"pytest-xdist",
"imap_tools",
]
[project.scripts]

View File

@ -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()

View File

@ -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: