From: Nick Porter Date: Thu, 4 Sep 2025 14:18:08 +0000 (+0100) Subject: Add test of %smtp.send() xlat X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=644c6a74de9b89dcda4308dffc2ee88d66b688ab;p=thirdparty%2Ffreeradius-server.git Add test of %smtp.send() xlat --- diff --git a/scripts/ci/exim-setup.sh b/scripts/ci/exim-setup.sh index 7aae26dde2..b92ebc8192 100755 --- a/scripts/ci/exim-setup.sh +++ b/scripts/ci/exim-setup.sh @@ -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 diff --git a/src/tests/modules/smtp/module.conf b/src/tests/modules/smtp/module.conf index d5adc3a5e0..c49ba13e18 100644 --- a/src/tests/modules/smtp/module.conf +++ b/src/tests/modules/smtp/module.conf @@ -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 index 0000000000..65ec9dc7e4 --- /dev/null +++ b/src/tests/modules/smtp/xlat.attrs @@ -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 index 0000000000..a651921b2d --- /dev/null +++ b/src/tests/modules/smtp/xlat.unlang @@ -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