properly startup metadata service and add online test for metadata
This commit is contained in:
parent
a8765d8847
commit
46d31a91da
@ -2,7 +2,7 @@
|
|||||||
Description=Chatmail dict proxy for IMAP METADATA
|
Description=Chatmail dict proxy for IMAP METADATA
|
||||||
|
|
||||||
[Service]
|
[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
|
Restart=always
|
||||||
RestartSec=30
|
RestartSec=30
|
||||||
|
|
||||||
|
@ -8,7 +8,6 @@ from socketserver import (
|
|||||||
StreamRequestHandler,
|
StreamRequestHandler,
|
||||||
ThreadingMixIn,
|
ThreadingMixIn,
|
||||||
)
|
)
|
||||||
from .config import read_config
|
|
||||||
import sys
|
import sys
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
@ -147,15 +146,16 @@ class ThreadedUnixStreamServer(ThreadingMixIn, UnixStreamServer):
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
socket, username, config, metadata_dir = sys.argv[1:]
|
socket, username, vmail_dir = sys.argv[1:]
|
||||||
passwd_entry = pwd.getpwnam(username)
|
passwd_entry = pwd.getpwnam(username)
|
||||||
|
|
||||||
# XXX config is not currently used
|
vmail_dir = Path(vmail_dir)
|
||||||
config = read_config(config)
|
|
||||||
metadata_dir = Path(metadata_dir)
|
if not vmail_dir.exists():
|
||||||
if not metadata_dir.exists():
|
logging.error("vmail dir does not exist: %r", vmail_dir)
|
||||||
metadata_dir.mkdir()
|
return 1
|
||||||
notifier = Notifier(metadata_dir)
|
|
||||||
|
notifier = Notifier(vmail_dir)
|
||||||
|
|
||||||
class Handler(StreamRequestHandler):
|
class Handler(StreamRequestHandler):
|
||||||
def handle(self):
|
def handle(self):
|
||||||
|
@ -19,6 +19,7 @@ dependencies = [
|
|||||||
"black",
|
"black",
|
||||||
"pytest",
|
"pytest",
|
||||||
"pytest-xdist",
|
"pytest-xdist",
|
||||||
|
"imap_tools",
|
||||||
]
|
]
|
||||||
|
|
||||||
[project.scripts]
|
[project.scripts]
|
||||||
|
@ -108,6 +108,7 @@ def _install_remote_venv_with_chatmaild(config) -> None:
|
|||||||
execpath=f"{remote_venv_dir}/bin/{fn}",
|
execpath=f"{remote_venv_dir}/bin/{fn}",
|
||||||
config_path=remote_chatmail_inipath,
|
config_path=remote_chatmail_inipath,
|
||||||
remote_venv_dir=remote_venv_dir,
|
remote_venv_dir=remote_venv_dir,
|
||||||
|
mail_domain=config.mail_domain,
|
||||||
)
|
)
|
||||||
source_path = importlib.resources.files("chatmaild").joinpath(f"{fn}.service.f")
|
source_path = importlib.resources.files("chatmaild").joinpath(f"{fn}.service.f")
|
||||||
content = source_path.read_text().format(**params).encode()
|
content = source_path.read_text().format(**params).encode()
|
||||||
|
@ -5,6 +5,33 @@ import random
|
|||||||
import pytest
|
import pytest
|
||||||
import requests
|
import requests
|
||||||
import ipaddress
|
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:
|
class TestEndToEndDeltaChat:
|
||||||
@ -75,7 +102,10 @@ class TestEndToEndDeltaChat:
|
|||||||
)
|
)
|
||||||
lp.indent("good, message sending failed because quota was exceeded")
|
lp.indent("good, message sending failed because quota was exceeded")
|
||||||
return
|
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
|
saved_ok += 1
|
||||||
print(f"{saved_ok}: {line}")
|
print(f"{saved_ok}: {line}")
|
||||||
if saved_ok >= num_to_send:
|
if saved_ok >= num_to_send:
|
||||||
|
Loading…
Reference in New Issue
Block a user