From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <pve-devel-bounces@lists.proxmox.com> Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id D137B1FF164 for <inbox@lore.proxmox.com>; Fri, 23 May 2025 14:26:53 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id EFCBE19FA8; Fri, 23 May 2025 14:26:29 +0200 (CEST) From: Lukas Wagner <l.wagner@proxmox.com> To: pve-devel@lists.proxmox.com Date: Fri, 23 May 2025 14:26:14 +0200 Message-Id: <20250523122615.251430-6-l.wagner@proxmox.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250523122615.251430-1-l.wagner@proxmox.com> References: <20250523122615.251430-1-l.wagner@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.020 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH proxmox 2/3] notify: smtp: add test for building forwarded messages X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com> List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe> List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/> List-Post: <mailto:pve-devel@lists.proxmox.com> List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help> List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe> Reply-To: Proxmox VE development discussion <pve-devel@lists.proxmox.com> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" <pve-devel-bounces@lists.proxmox.com> Signed-off-by: Lukas Wagner <l.wagner@proxmox.com> --- proxmox-notify/src/endpoints/smtp.rs | 32 ++++++ proxmox-notify/testdata/test1.msg | 104 ++++++++++++++++++ .../test_forward_message_from_raw.ref | 95 ++++++++++++++++ 3 files changed, 231 insertions(+) create mode 100644 proxmox-notify/testdata/test1.msg create mode 100644 proxmox-notify/testdata/test_forward_message_from_raw.ref diff --git a/proxmox-notify/src/endpoints/smtp.rs b/proxmox-notify/src/endpoints/smtp.rs index 2f4bad3c..7ad85de8 100644 --- a/proxmox-notify/src/endpoints/smtp.rs +++ b/proxmox-notify/src/endpoints/smtp.rs @@ -376,3 +376,35 @@ fn build_forwarded_message( Ok(message) } + +#[cfg(all(test, feature = "mail-forwarder"))] +mod tests { + use lettre::message::header::Date; + + use super::*; + + #[test] + fn test_forward_message_from_raw() { + let input = "testdata/test1.msg"; + let reference = "testdata/test_forward_message_from_raw.ref"; + + let mut email_builder = + Message::builder().from("Sender <sender@example.com>".parse().unwrap()); + + email_builder = email_builder.to("Recipient <recipient@example.com>".parse().unwrap()); + + let raw_mail = std::fs::read(input).unwrap(); + let mut message = build_forwarded_message(email_builder, "test", &raw_mail).unwrap(); + + // The Date header contains the current time, let's just remove it + // for this test. + message.headers_mut().remove::<Date>(); + + let formatted = message.formatted(); + + // Uncomment to update the reference file. + // std::fs::write(reference, &formatted).unwrap(); + + assert_eq!(formatted, std::fs::read(reference).unwrap()); + } +} diff --git a/proxmox-notify/testdata/test1.msg b/proxmox-notify/testdata/test1.msg new file mode 100644 index 00000000..634e7522 --- /dev/null +++ b/proxmox-notify/testdata/test1.msg @@ -0,0 +1,104 @@ +From root@host.example.com Fri May 23 11:59:32 2025 +Return-Path: <root@host.example.com> +X-Original-To: root +Delivered-To: root@host.example.com +Received: by host.example.com (Postfix, from userid 0) + id 25CE920081A; Fri, 23 May 2025 11:59:32 +0200 (CEST) +Content-Type: multipart/alternative; + boundary="----_=_NextPart_002_1747994372" +MIME-Version: 1.0 +Subject: vzdump backup status (host.example.com): backup successful +From: Proxmox VE <root@host.example.com> +To: root@host.example.com +Date: Fri, 23 May 2025 11:59:32 +0200 +Auto-Submitted: auto-generated; +Message-Id: <20250523095932.25CE920081A@host.example.com> + +This is a multi-part message in MIME format. + +------_=_NextPart_002_1747994372 +Content-Type: text/plain; + charset="UTF-8" +Content-Transfer-Encoding: 8bit + + +Details +======= +VMID Name Status Time Size Filename +187 smtp-sink ok 11s 430.758 MiB /var/lib/vz/dump/vzdump-lxc-187-2025_05_23-11_59_21.tar.zst + +Total running time: 11s +Total size: 430.758 MiB + +Logs +==== +vzdump 187 --compress zstd --notes-template '{{guestname}}' --remove 0 --storage local --mode snapshot --notification-mode notification-system --node host + + +187: 2025-05-23 11:59:21 INFO: Starting Backup of VM 187 (lxc) +187: 2025-05-23 11:59:21 INFO: status = stopped +187: 2025-05-23 11:59:21 INFO: backup mode: stop +187: 2025-05-23 11:59:21 INFO: ionice priority: 7 +187: 2025-05-23 11:59:21 INFO: CT Name: smtp-sink +187: 2025-05-23 11:59:21 INFO: including mount point rootfs ('/') in backup +187: 2025-05-23 11:59:21 INFO: creating vzdump archive '/var/lib/vz/dump/vzdump-lxc-187-2025_05_23-11_59_21.tar.zst' +187: 2025-05-23 11:59:32 INFO: Total bytes written: 1519319040 (1.5GiB, 135MiB/s) +187: 2025-05-23 11:59:32 INFO: archive file size: 430MB +187: 2025-05-23 11:59:32 INFO: adding notes to backup +187: 2025-05-23 11:59:32 INFO: Finished Backup of VM 187 (00:00:11) + + + +------_=_NextPart_002_1747994372 +Content-Type: text/html; + charset="UTF-8" +Content-Transfer-Encoding: 8bit + +<html> + <body> + + <h1 style="font-size: 1.2em">Details</h1> + <table style="border: 1px solid;border-collapse=collapse;"> + <tr> + <th style="border: 1px solid;border-collapse=collapse;">VMID</th> + <th style="border: 1px solid;border-collapse=collapse;">Name</th> + <th style="border: 1px solid;border-collapse=collapse;">Status</th> + <th style="border: 1px solid;border-collapse=collapse;">Time</th> + <th style="border: 1px solid;border-collapse=collapse;">Size</th> + <th style="border: 1px solid;border-collapse=collapse;">Filename</th> + </tr> + + <tr> + <td style="border: 1px solid;border-collapse=collapse;">187</th> + <td style="border: 1px solid;border-collapse=collapse;">smtp-sink</th> + <td style="border: 1px solid;border-collapse=collapse;">ok</th> + <td style="border: 1px solid;border-collapse=collapse;">11s</th> + <td style="border: 1px solid;border-collapse=collapse;">430.758 MiB</th> + <td style="border: 1px solid;border-collapse=collapse;">/var/lib/vz/dump/vzdump-lxc-187-2025_05_23-11_59_21.tar.zst</th> + </tr> + + </table> + <br/> + Total running time: 11s<br/> + Total size: 430.758 MiB<br/> + <h1 style="font-size: 1.2em">Logs</h1> + <pre>vzdump 187 --compress zstd --notes-template '{{guestname}}' --remove 0 --storage local --mode snapshot --notification-mode notification-system --node host + + +187: 2025-05-23 11:59:21 INFO: Starting Backup of VM 187 (lxc) +187: 2025-05-23 11:59:21 INFO: status = stopped +187: 2025-05-23 11:59:21 INFO: backup mode: stop +187: 2025-05-23 11:59:21 INFO: ionice priority: 7 +187: 2025-05-23 11:59:21 INFO: CT Name: smtp-sink +187: 2025-05-23 11:59:21 INFO: including mount point rootfs ('/') in backup +187: 2025-05-23 11:59:21 INFO: creating vzdump archive '/var/lib/vz/dump/vzdump-lxc-187-2025_05_23-11_59_21.tar.zst' +187: 2025-05-23 11:59:32 INFO: Total bytes written: 1519319040 (1.5GiB, 135MiB/s) +187: 2025-05-23 11:59:32 INFO: archive file size: 430MB +187: 2025-05-23 11:59:32 INFO: adding notes to backup +187: 2025-05-23 11:59:32 INFO: Finished Backup of VM 187 (00:00:11) + +</pre> + </body> +</html> + +------_=_NextPart_002_1747994372-- diff --git a/proxmox-notify/testdata/test_forward_message_from_raw.ref b/proxmox-notify/testdata/test_forward_message_from_raw.ref new file mode 100644 index 00000000..79fede27 --- /dev/null +++ b/proxmox-notify/testdata/test_forward_message_from_raw.ref @@ -0,0 +1,95 @@ +From: Sender <sender@example.com> +To: Recipient <recipient@example.com> +Subject: vzdump backup status (host.example.com): backup successful +Content-Type: multipart/alternative; + boundary="----_=_NextPart_002_1747994372" +MIME-Version: 1.0 + +This is a multi-part message in MIME format. + +------_=_NextPart_002_1747994372 +Content-Type: text/plain; + charset="UTF-8" +Content-Transfer-Encoding: 8bit + + +Details +======= +VMID Name Status Time Size Filename +187 smtp-sink ok 11s 430.758 MiB /var/lib/vz/dump/vzdump-lxc-187-2025_05_23-11_59_21.tar.zst + +Total running time: 11s +Total size: 430.758 MiB + +Logs +==== +vzdump 187 --compress zstd --notes-template '{{guestname}}' --remove 0 --storage local --mode snapshot --notification-mode notification-system --node host + + +187: 2025-05-23 11:59:21 INFO: Starting Backup of VM 187 (lxc) +187: 2025-05-23 11:59:21 INFO: status = stopped +187: 2025-05-23 11:59:21 INFO: backup mode: stop +187: 2025-05-23 11:59:21 INFO: ionice priority: 7 +187: 2025-05-23 11:59:21 INFO: CT Name: smtp-sink +187: 2025-05-23 11:59:21 INFO: including mount point rootfs ('/') in backup +187: 2025-05-23 11:59:21 INFO: creating vzdump archive '/var/lib/vz/dump/vzdump-lxc-187-2025_05_23-11_59_21.tar.zst' +187: 2025-05-23 11:59:32 INFO: Total bytes written: 1519319040 (1.5GiB, 135MiB/s) +187: 2025-05-23 11:59:32 INFO: archive file size: 430MB +187: 2025-05-23 11:59:32 INFO: adding notes to backup +187: 2025-05-23 11:59:32 INFO: Finished Backup of VM 187 (00:00:11) + + + +------_=_NextPart_002_1747994372 +Content-Type: text/html; + charset="UTF-8" +Content-Transfer-Encoding: 8bit + +<html> + <body> + + <h1 style="font-size: 1.2em">Details</h1> + <table style="border: 1px solid;border-collapse=collapse;"> + <tr> + <th style="border: 1px solid;border-collapse=collapse;">VMID</th> + <th style="border: 1px solid;border-collapse=collapse;">Name</th> + <th style="border: 1px solid;border-collapse=collapse;">Status</th> + <th style="border: 1px solid;border-collapse=collapse;">Time</th> + <th style="border: 1px solid;border-collapse=collapse;">Size</th> + <th style="border: 1px solid;border-collapse=collapse;">Filename</th> + </tr> + + <tr> + <td style="border: 1px solid;border-collapse=collapse;">187</th> + <td style="border: 1px solid;border-collapse=collapse;">smtp-sink</th> + <td style="border: 1px solid;border-collapse=collapse;">ok</th> + <td style="border: 1px solid;border-collapse=collapse;">11s</th> + <td style="border: 1px solid;border-collapse=collapse;">430.758 MiB</th> + <td style="border: 1px solid;border-collapse=collapse;">/var/lib/vz/dump/vzdump-lxc-187-2025_05_23-11_59_21.tar.zst</th> + </tr> + + </table> + <br/> + Total running time: 11s<br/> + Total size: 430.758 MiB<br/> + <h1 style="font-size: 1.2em">Logs</h1> + <pre>vzdump 187 --compress zstd --notes-template '{{guestname}}' --remove 0 --storage local --mode snapshot --notification-mode notification-system --node host + + +187: 2025-05-23 11:59:21 INFO: Starting Backup of VM 187 (lxc) +187: 2025-05-23 11:59:21 INFO: status = stopped +187: 2025-05-23 11:59:21 INFO: backup mode: stop +187: 2025-05-23 11:59:21 INFO: ionice priority: 7 +187: 2025-05-23 11:59:21 INFO: CT Name: smtp-sink +187: 2025-05-23 11:59:21 INFO: including mount point rootfs ('/') in backup +187: 2025-05-23 11:59:21 INFO: creating vzdump archive '/var/lib/vz/dump/vzdump-lxc-187-2025_05_23-11_59_21.tar.zst' +187: 2025-05-23 11:59:32 INFO: Total bytes written: 1519319040 (1.5GiB, 135MiB/s) +187: 2025-05-23 11:59:32 INFO: archive file size: 430MB +187: 2025-05-23 11:59:32 INFO: adding notes to backup +187: 2025-05-23 11:59:32 INFO: Finished Backup of VM 187 (00:00:11) + +</pre> + </body> +</html> + +------_=_NextPart_002_1747994372-- -- 2.39.5 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel