Support local mailbox provisioning over a restricted Unix socket

This commit is contained in:
parkel committed 2026-11-21 01:46:23 +01:00
1 parent 640bec5d1c
commit 8dfb64bf8c
5 files changed
+104 -1

No files matched your search

+37 -1
View File
@@ -2,7 +2,7 @@ import json
import os
import stat
from contextlib import redirect_stdout
from io import StringIO
from io import BytesIO, StringIO
from pathlib import Path
from subprocess import CompletedProcess
from tempfile import TemporaryDirectory
@@ -21,6 +21,42 @@ from coulobre.mail_node_apply import (
)
class MailboxApplyRequestTests(SimpleTestCase):
def setUp(self):
self.mailbox = MailboxSpec("example.net", "support")
self.apply = self.enterContext(
patch(
"coulobre.mail_node_apply.apply_mailbox",
return_value=Path("/private/credentials.json"),
)
)
def request(self, manifest):
output = StringIO()
with (
patch(
"sys.stdin",
SimpleNamespace(buffer=BytesIO(json.dumps(manifest).encode())),
),
redirect_stdout(output),
):
code = main(["apply-request"])
return code, json.loads(output.getvalue())
def test_request_reports_the_mailbox_identity_only(self):
manifest = self.mailbox.manifest()
code, reply = self.request(manifest)
self.apply.assert_called_once_with(self.mailbox)
self.assertEqual(code, 0)
self.assertEqual(reply, manifest | {"state": "configured", "problem": None})
def test_request_rejects_extra_credentials_before_acting(self):
code, reply = self.request(self.mailbox.manifest() | {"password": "untrusted"})
self.assertEqual(code, 1)
self.assertEqual(reply["state"], "failed")
self.apply.assert_not_called()
class MailboxApplyTests(SimpleTestCase):
def setUp(self):
directory = Path(self.enterContext(TemporaryDirectory()))
+12
View File
@@ -5,6 +5,7 @@ from dataclasses import dataclass
from pathlib import Path
from .domain_names import canonical_domain
from .node_requests import serve_apply_request
MANIFEST_VERSION = 1
MANIFEST_KIND = "virtual_mailbox"
@@ -74,10 +75,21 @@ def main(argv=None):
"apply", help="Install a virtual mailbox on the mail node."
)
apply.add_argument("manifest", type=Path)
commands.add_parser(
"apply-request",
help="Apply one mailbox manifest from standard input and report JSON.",
)
status = commands.add_parser("status", help="Check an installed virtual mailbox.")
status.add_argument("manifest", type=Path)
args = parser.parse_args(argv)
if args.command == "apply-request":
from .mail_node_apply import apply_mailbox
return serve_apply_request(
MANIFEST_VERSION, MailboxSpec.from_manifest, apply_mailbox
)
try:
payload = json.loads(args.manifest.read_text(encoding="utf-8"))
mailbox = MailboxSpec.from_manifest(payload)