This commit is contained in:
Shelvacu
2025-04-09 21:37:24 -07:00
committed by Shelvacu on fw
parent c1c5f39a00
commit cfa5049922
7 changed files with 274 additions and 4 deletions

View File

@@ -1,9 +1,12 @@
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Any
if TYPE_CHECKING:
from hints import *
import json
import shlex
import uuid
DATA_JSON = """
@data@
"""
@@ -25,6 +28,55 @@ liam.wait_for_unit("postfix.service")
liam.wait_for_unit("dovecot2.service")
relay.wait_for_unit("mailpit.service")
def make_command(args: list) -> str:
return " ".join(map(shlex.quote, (map(str, args))))
class TesterThing():
uuid: str = ""
default_smtp: dict[str, str] = {}
default_imap: dict[str, str] = {}
default_mailpit: dict[str, str] = {}
def __init__(self, username: str, smtp: dict[str, str] = {}, imap: dict[str, str] = {}, mailpit: dict[str, str] = {}):
self.uuid = str(uuid.uuid4())
self.default_smtp = {
"rcptto": "someone@example.com",
"username": username,
**smtp
}
self.default_imap = {
"username": username,
**imap
}
self.default_mailpit = {
"mailpit-url": f"http://{relay_ip}:8025",
**mailpit
}
def run_expecting_json(self, name: str, **kwargs: dict[str, str]) -> dict[str, Any]:
args:list[str] = [name]
for k, v in kwargs:
dashed = k.replace("_","-")
args.append(f"--{dashed}")
args.append(v)
res = checker.succeed(make_command(args))
res = res.strip()
assert res != ""
return json.loads(res)
def run_smtp(self, **kwargs: dict[str, str]) -> bool:
args = {"message_magic": self.uuid, **self.default_smtp, **kwargs}
res = self.run_expecting_json("mailpit-smtp", **args)
return res["result"]
def smtp_accepted(self, **kwargs):
res = self.run_smtp(**kwargs)
assert res, "Message was not accepted when it should have been"
def smtp_rejected(self, **kwargs):
res = self.run_smtp(**kwargs)
assert not res, "Message was accepted when it was supposed to be rejected"
# The order of these shouldn't matter, other than what fails first. Whatever is at the top is probably whatever I was working on most recently.
checks = f"""
--submission --mailfrom robot@vacu.store --rcptto someone@example.com --username vacustore --expect-mailpit-received --mailpit-url http://{relay_ip}:8025