Skip to content

Commit 644c6a7

Browse files
committed
Add test of %smtp.send() xlat
1 parent fca5758 commit 644c6a7

File tree

4 files changed

+87
-1
lines changed

4 files changed

+87
-1
lines changed

scripts/ci/exim-setup.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ echo "smtp_to_request_1: smtp_to_request_1" >> ${BUILDDIR}/untaint
146146
echo "smtp_to_request_2: smtp_to_request_2" >> ${BUILDDIR}/untaint
147147
echo "smtp_to_request_3: smtp_to_request_3" >> ${BUILDDIR}/untaint
148148
echo "smtp_cc_request_1: smtp_cc_request_1" >> ${BUILDDIR}/untaint
149-
echo "smtp_cc_request_2: smtp_cc_request_2" >> ${BUILDDIR}/untaint
149+
echo "xlat_recipient_1: xlat_recipient_1" >> ${BUILDDIR}/untaint
150+
echo "xlat_recipient_2: xlat_recipient_2" >> ${BUILDDIR}/untaint
150151

151152
echo "Generating the file attachment"
152153
# Generate a file for test email attachments

src/tests/modules/smtp/module.conf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,21 @@ smtp {
4848
set_date = no
4949
}
5050

51+
smtp smtp_xlat {
52+
tls {
53+
require_cert = never
54+
}
55+
56+
username = "Bob"
57+
password = "Saget"
58+
59+
uri = "$ENV{SMTP_TEST_SERVER}:$ENV{SMTP_TEST_SERVER_PORT}"
60+
timeout = 200s
61+
62+
envelope_address = "postmaster@localhost"
63+
64+
set_date = no
65+
}
66+
5167
delay {
5268
}

src/tests/modules/smtp/xlat.attrs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#
2+
# Input packet
3+
#
4+
Packet-Type = Access-Request
5+
User-Name = 'Bob'
6+
User-Password = 'Saget'
7+
8+
#
9+
# Expected answer
10+
#
11+
Packet-Type == Access-Accept
12+

src/tests/modules/smtp/xlat.unlang

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
bool sent
2+
3+
#
4+
# Test xlat with all 3 arguments
5+
#
6+
sent = %smtp_xlat.send('xlat_recipient_1@localhost', 'Simple email', 'With body')
7+
8+
#
9+
# Xlat failure is likely a timeout
10+
# Avoid false negatives by aborting test
11+
#
12+
if (!sent) {
13+
if (Module-Failure-Message[*] == 'smtp: curl request failed: Timeout was reached (28)') {
14+
test_pass
15+
handled
16+
}
17+
test_fail
18+
}
19+
20+
#
21+
# Wait up to five seconds for exim to deliver the email
22+
# Then confirm it was delivered
23+
#
24+
foreach i (%range(50)) {
25+
if %file.exists('build/ci/exim4/mail/xlat_recipient_1') {
26+
break;
27+
}
28+
%delay(0.1)
29+
}
30+
if !%file.exists('build/ci/exim4/mail/xlat_recipient_1') {
31+
test_fail
32+
}
33+
34+
#
35+
# Test xlat with just recipient and subject
36+
#
37+
sent := %smtp_xlat.send('xlat_recipient_2@localhost', 'Simple email two')
38+
39+
if (!sent) {
40+
if (Module-Failure-Message[*] == 'smtp: curl request failed: Timeout was reached (28)') {
41+
test_pass
42+
handled
43+
}
44+
test_fail
45+
}
46+
47+
foreach i (%range(50)) {
48+
if %file.exists('build/ci/exim4/mail/xlat_recipient_2') {
49+
break;
50+
}
51+
%delay(0.1)
52+
}
53+
if !%file.exists('build/ci/exim4/mail/xlat_recipient_2') {
54+
test_fail
55+
}
56+
57+
test_pass

0 commit comments

Comments
 (0)