Release v0.1.2
This commit is contained in:
46
webui/tests/mail-policy-validation.test.ts
Normal file
46
webui/tests/mail-policy-validation.test.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
function assert(condition: unknown, message = "assertion failed"): void {
|
||||
if (!condition) throw new Error(message);
|
||||
}
|
||||
|
||||
function assertEqual<T>(actual: T, expected: T, message = "values should be equal"): void {
|
||||
if (actual !== expected) throw new Error(`${message}: expected ${String(expected)}, got ${String(actual)}`);
|
||||
}
|
||||
|
||||
function assertDeepEqual(actual: unknown, expected: unknown, message = "values should be deeply equal"): void {
|
||||
const actualJson = JSON.stringify(actual);
|
||||
const expectedJson = JSON.stringify(expected);
|
||||
if (actualJson !== expectedJson) throw new Error(`${message}: expected ${expectedJson}, got ${actualJson}`);
|
||||
}
|
||||
|
||||
import { mailPolicyValueAllowed, validateMailPolicy, wildcardPatternMatches } from "../src/features/mail/mailPolicyValidation";
|
||||
|
||||
assertEqual(wildcardPatternMatches("*.example.org", "smtp.example.org"), true);
|
||||
assertEqual(wildcardPatternMatches("smtp?.example.org", "smtp1.example.org"), true);
|
||||
assertEqual(wildcardPatternMatches("smtp?.example.org", "smtp12.example.org"), false);
|
||||
|
||||
const policy = {
|
||||
whitelist: {
|
||||
smtp_hosts: ["smtp.allowed.test"],
|
||||
from_headers: ["*@allowed.test"],
|
||||
recipient_domains: ["allowed.test"]
|
||||
},
|
||||
blacklist: {
|
||||
smtp_hosts: ["smtp.blocked.test"],
|
||||
envelope_senders: ["blocked@*"]
|
||||
}
|
||||
};
|
||||
|
||||
assertDeepEqual(mailPolicyValueAllowed(policy, "smtp_hosts", "smtp.allowed.test"), { allowed: true, value: "smtp.allowed.test" });
|
||||
assertEqual(mailPolicyValueAllowed(policy, "smtp_hosts", "smtp.blocked.test").allowed, false, "blacklist wins for SMTP host");
|
||||
assertEqual(mailPolicyValueAllowed(policy, "smtp_hosts", "smtp.other.test").allowed, false, "whitelist blocks unknown SMTP host");
|
||||
|
||||
const messages = validateMailPolicy(policy, {
|
||||
smtpHost: "smtp.other.test",
|
||||
envelopeSender: "blocked@allowed.test",
|
||||
fromHeader: "sender@other.test",
|
||||
recipientDomains: ["allowed.test", "denied.test", "user@denied.test"]
|
||||
});
|
||||
assert(messages.some((item) => item.key === "smtp_hosts" && item.value === "smtp.other.test"));
|
||||
assert(messages.some((item) => item.key === "envelope_senders" && item.value === "blocked@allowed.test"));
|
||||
assert(messages.some((item) => item.key === "from_headers" && item.value === "sender@other.test"));
|
||||
assertEqual(messages.filter((item) => item.key === "recipient_domains" && item.value === "denied.test").length, 1, "recipient domains are normalized and de-duplicated");
|
||||
30
webui/tests/mailbox-folders.test.ts
Normal file
30
webui/tests/mailbox-folders.test.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
function assert(condition: unknown, message = "assertion failed"): void {
|
||||
if (!condition) throw new Error(message);
|
||||
}
|
||||
|
||||
function assertEqual<T>(actual: T, expected: T, message = "values should be equal"): void {
|
||||
if (actual !== expected) throw new Error(`${message}: expected ${String(expected)}, got ${String(actual)}`);
|
||||
}
|
||||
|
||||
function assertDeepEqual(actual: unknown, expected: unknown, message = "values should be deeply equal"): void {
|
||||
const actualJson = JSON.stringify(actual);
|
||||
const expectedJson = JSON.stringify(expected);
|
||||
if (actualJson !== expectedJson) throw new Error(`${message}: expected ${expectedJson}, got ${actualJson}`);
|
||||
}
|
||||
|
||||
import { buildMailboxFolderTree, findFolderNodeId, folderAncestorIds, folderParts } from "../src/features/mail/mailboxFolders";
|
||||
|
||||
assertDeepEqual(folderParts("INBOX.Sent.Archive"), ["INBOX", "Sent", "Archive"]);
|
||||
assertDeepEqual(folderParts("Projects/2026/Inbox"), ["Projects", "2026", "Inbox"]);
|
||||
|
||||
const tree = buildMailboxFolderTree([
|
||||
{ name: "Archive/2026", flags: [] },
|
||||
{ name: "INBOX", flags: [] },
|
||||
{ name: "INBOX.Sent", flags: ["\\Sent"] },
|
||||
{ name: "Projects/2026/Inbox", flags: [] }
|
||||
]);
|
||||
|
||||
assertEqual(tree[0].id, "INBOX", "INBOX sorts first");
|
||||
assertEqual(findFolderNodeId(tree, "INBOX.Sent"), "INBOX/Sent");
|
||||
assertDeepEqual(folderAncestorIds(tree, "Projects/2026/Inbox"), ["Projects", "Projects/2026", "Projects/2026/Inbox"]);
|
||||
assertEqual(tree.find((node) => node.id === "INBOX")?.children[0]?.folderName, "INBOX.Sent");
|
||||
Reference in New Issue
Block a user