]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add test of %smtp.send() xlat
authorNick Porter <nick@portercomputing.co.uk>
Thu, 4 Sep 2025 14:18:08 +0000 (15:18 +0100)
committerNick Porter <nick@portercomputing.co.uk>
Thu, 4 Sep 2025 14:32:41 +0000 (15:32 +0100)
scripts/ci/exim-setup.sh
src/tests/modules/smtp/module.conf
src/tests/modules/smtp/xlat.attrs [new file with mode: 0644]
src/tests/modules/smtp/xlat.unlang [new file with mode: 0644]

index 7aae26dde26cfd33350b28259149856f6ca135cc..b92ebc8192558ee38d6fda9e70d03159bd3f39f5 100755 (executable)
@@ -146,7 +146,8 @@ echo "smtp_to_request_1: smtp_to_request_1" >> ${BUILDDIR}/untaint
 echo "smtp_to_request_2: smtp_to_request_2" >> ${BUILDDIR}/untaint
 echo "smtp_to_request_3: smtp_to_request_3" >> ${BUILDDIR}/untaint
 echo "smtp_cc_request_1: smtp_cc_request_1" >> ${BUILDDIR}/untaint
-echo "smtp_cc_request_2: smtp_cc_request_2" >> ${BUILDDIR}/untaint
+echo "xlat_recipient_1: xlat_recipient_1" >> ${BUILDDIR}/untaint
+echo "xlat_recipient_2: xlat_recipient_2" >> ${BUILDDIR}/untaint
 
 echo "Generating the file attachment"
 # Generate a file for test email attachments
index d5adc3a5e0582811ec644ffe6123013ac976f8b1..c49ba13e18eca4494207738a1aa3908165416a59 100644 (file)
@@ -48,5 +48,21 @@ smtp {
        set_date = no
 }
 
+smtp smtp_xlat {
+       tls {
+               require_cert = never
+        }
+
+       username = "Bob"
+       password = "Saget"
+
+       uri = "$ENV{SMTP_TEST_SERVER}:$ENV{SMTP_TEST_SERVER_PORT}"
+       timeout = 200s
+
+       envelope_address = "postmaster@localhost"
+
+       set_date = no
+}
+
 delay {
 }
diff --git a/src/tests/modules/smtp/xlat.attrs b/src/tests/modules/smtp/xlat.attrs
new file mode 100644 (file)
index 0000000..65ec9dc
--- /dev/null
@@ -0,0 +1,12 @@
+#
+#  Input packet
+#
+Packet-Type = Access-Request
+User-Name = 'Bob'
+User-Password = 'Saget'
+
+#
+#  Expected answer
+#
+Packet-Type == Access-Accept
+
diff --git a/src/tests/modules/smtp/xlat.unlang b/src/tests/modules/smtp/xlat.unlang
new file mode 100644 (file)
index 0000000..a651921
--- /dev/null
@@ -0,0 +1,57 @@
+bool sent
+
+#
+#  Test xlat with all 3 arguments
+#
+sent = %smtp_xlat.send('xlat_recipient_1@localhost', 'Simple email', 'With body')
+
+#
+#  Xlat failure is likely a timeout
+#  Avoid false negatives by aborting test
+#
+if (!sent) {
+       if (Module-Failure-Message[*] == 'smtp: curl request failed: Timeout was reached (28)') {
+               test_pass
+               handled
+       }
+       test_fail
+}
+
+#
+# Wait up to five seconds for exim to deliver the email
+# Then confirm it was delivered
+#
+foreach i (%range(50)) {
+       if %file.exists('build/ci/exim4/mail/xlat_recipient_1') {
+               break;
+       }
+       %delay(0.1)
+}
+if !%file.exists('build/ci/exim4/mail/xlat_recipient_1') {
+       test_fail
+}
+
+#
+#  Test xlat with just recipient and subject
+#
+sent := %smtp_xlat.send('xlat_recipient_2@localhost', 'Simple email two')
+
+if (!sent) {
+       if (Module-Failure-Message[*] == 'smtp: curl request failed: Timeout was reached (28)') {
+               test_pass
+               handled
+       }
+       test_fail
+}
+
+foreach i (%range(50)) {
+       if %file.exists('build/ci/exim4/mail/xlat_recipient_2') {
+               break;
+       }
+       %delay(0.1)
+}
+if !%file.exists('build/ci/exim4/mail/xlat_recipient_2') {
+       test_fail
+}
+
+test_pass