2 ################################################################################
4 ## Copyright (c) International Business Machines Corp., 2001 ##
6 ## This program is free software; you can redistribute it and#or modify ##
7 ## it under the terms of the GNU General Public License as published by ##
8 ## the Free Software Foundation; either version 2 of the License, or ##
9 ## (at your option) any later version. ##
11 ## This program is distributed in the hope that it will be useful, but ##
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
13 ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ##
14 ## for more details. ##
16 ## You should have received a copy of the GNU General Public License ##
17 ## along with this program; if not, write to the Free Software ##
18 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ##
20 ################################################################################
22 # File : mail_tests.sh
24 # Description: Tests basic functions of mail system. The aim of the test is to
25 # make sure that certain basic functionality of mail is expected
26 # to work as per man page. There are 4 - 5 operations that are
27 # done on a regular basis wrt mail. ie.
28 # mail send to an user@domain - received by that user@domain
29 # mail is send to nosuchuser@domain - mail delivery failure
30 # mail is send to user@nosuchdomain - mail delivery failure
31 # mail to user1@domain and cc user2@domain - mail rec by both
32 # mail to user1@domain and bcc user2@domain - mail rec by both
34 # Author: Manoj Iyer, manjo@mail.utexas.edu
36 # History: Jan 07 2003 - Created - Manoj Iyer.
37 # Jan 09 2003 - Added Test #2 #3 #4 and #5.
38 # Jan 10 2002 - Fixed various bugs I had introduced in the test.
39 # - Added SETUP and CLEANUP sections
44 if [ -z "$LTPTMP" -a -z "$TMPBASE" ]
58 type mail > /dev
/null
2>&1
63 # check if the user mail_test exists on this system.
64 # if not add that user mail_test, will removed before exiting test.
65 RC
=$
(awk '/^mail_test/ {print 1}' /etc
/passwd
)
69 $LTPBIN/tst_resm TINFO
"INIT: Adding temporary user mail_test"
70 useradd
-m -s /bin
/bash mail_test
> $LTPTMP/tst_mail.out
2>&1 || RC
=$?
73 $LTPBIN/tst_brk TBROK
$LTPTMP/tst_mail.out NULL \
74 "Test INIT: Failed adding user mail_test. Reason:"
78 $LTPBIN/tst_resm TINFO
"INIT: Removing all mails for mail_test and root"
79 echo "d*" |
mail -u mail_test
> /dev
/null
2>&1
80 echo "d*" |
mail -u root
> /dev
/null
2>&1
82 # Set return code RC variable to 0, it will be set with a non-zero return code
83 # in case of error. Set TFAILCNT to 0, increment if there occures a failure.
92 # Test that mail user@domain will send a mail to that user at that domain.
97 $LTPBIN/tst_resm TINFO
"Test #1: mail root@localhost will send mail to root"
98 $LTPBIN/tst_resm TINFO
"Test #1: user on local machine."
101 if [ -z "$MAIL_NOT_INSTALLED" ]; then
102 cat > $LTPTMP/tst_mail.
in <<EOF
103 This is a test email.
106 mail -s "Test" root@localhost
< $LTPTMP/tst_mail.
in \
107 > $LTPTMP/tst_mail.out
2>&1 || RC
=$?
110 $LTPBIN/tst_res TFAIL
$LTPTMP/tst_mail.out \
111 "Test #1: mail command failed. Reason: "
112 TFAILCNT
=$
(( $TFAILCNT+1 ))
114 # check if root received a new email with Test as subject
115 # but wait for the mail to arrive.
118 echo "d" |
mail -u root
> $LTPTMP/tst_mail.res
2>&1
119 mailsub
=$
(awk '/^>N/ {print match($9, "Test")}' $LTPTMP/tst_mail.res
)
120 if [ -n "$mailsub" ] && [ "$mailsub" -ne 0 ]
122 $LTPBIN/tst_resm TPASS \
123 "Test #1: Mail was send to root & was received"
125 $LTPBIN/tst_res TFAIL
$LTPTMP/tst_mail.res \
126 "Test #1: Mail send to root, but was not received"
127 TFAILCNT
=$
(( $TFAILCNT+1 ))
131 $LTPBIN/tst_resm TCONF
"mail command not installed"
136 # Test that mail user@bad-domain will result in a warning from the mailer
137 # daemon that the domain does not exist.
145 $LTPBIN/tst_resm TINFO \
146 "Test #2: mail user@bad-domain will result in failure"
147 $LTPBIN/tst_resm TINFO
"Test #2: to deliver the mail. Mailer daemon should"
148 $LTPBIN/tst_resm TINFO
"Test #2: report this failure."
150 if [ -z $MAIL_NOT_INSTALLED ]; then
151 cat > $LTPTMP/tst_mail.
in <<EOF
152 This is a test email.
155 # Don't use underscores in domain names (they're illegal)...
156 mail -s "Test" root@thisdomaindoesnotexist
< $LTPTMP/tst_mail.
in \
157 > $LTPTMP/tst_mail.out
2>&1
160 $LTPBIN/tst_res TFAIL
$LTPTMP/tst_mail.out \
161 "Test #2: mail command failed. Reason: "
162 TFAILCNT
=$
(( $TFAILCNT+1 ))
164 # check if Mailer-Deamon reported any delivery failure.
165 # but wait for the mail to arrive first, sleep 5s.
167 echo "d" |
mail -u root
> $LTPTMP/tst_mail.res
2>&1
168 RC1
=$
(awk '/^>N/ {IGNORECASE=1; print match($3, "Mailer-Daemon")}' \
169 $LTPTMP/tst_mail.res
)
170 ##################################################################
171 # In this testcase, mail will get "Returnedmail:", while mailx will
172 # get "UndeliveredMailReturned:".
173 # Either of mail and mailx may be linked to another.
175 # /bin/mail -> /bin/mailx
177 # /bin/mailx -> /bin/mail
178 ##################################################################
179 RC2
=$
(awk '/^>N/ {print match($9 $10, "Returnedmail:")}' \
180 $LTPTMP/tst_mail.res
)
181 RC3
=$
(awk '/^>N/ {print match($9 $10, "UndeliveredMail")}' \
182 $LTPTMP/tst_mail.res
)
184 if [ -z "$RC1" -a -z "$RC2" -a -z "$RC3" ]
186 $LTPBIN/tst_res TFAIL
$LTPTMP/tst_mail.res \
187 "Test #2: No new mail for root. Reason:"
188 TFAILCNT
=$
(( $TFAILCNT+1 ))
190 if [ $RC1 -ne 0 -a $RC2 -ne 0 ] ||
[ $RC1 -ne 0 -a $RC3 -ne 0 ]
192 $LTPBIN/tst_resm TPASS \
193 "Test #2: Mailer-Deamon reported delivery failure"
195 $LTPBIN/tst_res TFAIL
$LTPTMP/tst_mail.res \
196 "Test #2: Mailer-Deamon failed to report delivery failure. Reason:"
197 TFAILCNT
=$
(( $TFAILCNT+1 ))
201 $LTPBIN/tst_resm TCONF
"mail command not installed"
205 # Test that mail non_existant_user@localhost will result in delivery failure.
206 # Mailer-Deamon will report this failure.
214 $LTPBIN/tst_resm TINFO \
215 "Test #3: mail non_existant_user@localhost will fail"
216 $LTPBIN/tst_resm TINFO
"Test #3: to deliver the mail. Mailer daemon should"
217 $LTPBIN/tst_resm TINFO
"Test #3: report this failure."
219 if [ -z $MAIL_NOT_INSTALLED ]; then
220 cat > $LTPTMP/tst_mail.
in <<EOF
221 This is a test email.
224 mail -s "Test" non_existant_userr@localhost
< $LTPTMP/tst_mail.
in \
225 > $LTPTMP/tst_mail.out
2>&1
228 $LTPBIN/tst_res TFAIL
$LTPTMP/tst_mail.out \
229 "Test #3: mail command failed. Reason: "
230 TFAILCNT
=$
(( $TFAILCNT+1 ))
232 # check if Mailer-Deamon reported any delivery failure.
233 # but wait for the mail to arrive first, sleep 5s.
235 echo "d" |
mail -u root
> $LTPTMP/tst_mail.res
2>&1
236 RC1
=$
(awk '/^>N/ {IGNORECASE=1; print match($3, "Mailer-Daemon")}' \
237 $LTPTMP/tst_mail.res
)
238 ##################################################################
239 # In this testcase, mail will get "Returnedmail:", while mailx will
240 # get "UndeliveredMailReturned:".
241 # Either of mail and mailx may be linked to another.
243 # /bin/mail -> /bin/mailx
245 # /bin/mailx -> /bin/mail
246 ##################################################################
247 RC2
=$
(awk '/^>N/ {print match($9 $10, "Returnedmail:")}' \
248 $LTPTMP/tst_mail.res
)
249 RC3
=$
(awk '/^>N/ {print match($9 $10, "UndeliveredMail")}' \
250 $LTPTMP/tst_mail.res
)
252 if [ -z "$RC1" -a -z "$RC2" -a -z "$RC3" ]
254 $LTPBIN/tst_res TFAIL
$LTPTMP/tst_mail.res \
255 "Test #2: No new mail for root. Reason:"
256 TFAILCNT
=$
(( $TFAILCNT+1 ))
258 if [ $RC1 -ne 0 -a $RC2 -ne 0 ] ||
[ $RC1 -ne 0 -a $RC3 -ne 0 ]
260 $LTPBIN/tst_resm TPASS \
261 "Test #3: Mailer-Deamon reported delivery failure"
263 $LTPBIN/tst_res TFAIL
$LTPTMP/tst_mail.res \
264 "Test #3: Mailer-Deamon failed to report delivery failure. Reason:"
265 TFAILCNT
=$
(( $TFAILCNT+1 ))
270 $LTPBIN/tst_resm TCONF
"mail command not installed"
274 # Test that mail -c user@domain option will carbon copy that user.
280 $LTPBIN/tst_resm TINFO
"Test #4: Test that mail -c user@domain will"
281 $LTPBIN/tst_resm TINFO
"Test #4: carbon copy user@domain"
282 if [ -z $MAIL_NOT_INSTALLED ]; then
284 # send mail to root and carbon copy mail_test
285 mail -s "Test" root@localhost
-c mail_test@localhost
< \
286 $LTPTMP/tst_mail.
in > $LTPTMP/tst_mail.out
2>&1 || RC
=$?
289 $LTPBIN/tst_res TFAIL
$LTPTMP/tst_mail.out \
290 "Test #4: mail command failed. Reason:"
291 TFAILCNT
=$
(( $TFAILCNT+1 ))
293 # Check if mail_test received the mail and
294 # also if root received the main copy of the email.
296 echo "d" |
mail -u root
> $LTPTMP/tst_mail.res
2>&1
297 RC1
=$
(awk '/^>N/ {print match($9, "Test")}' $LTPTMP/tst_mail.res
)
298 echo "d" |
mail -u mail_test
> $LTPTMP/tst_mail.res
2>&1
299 RC2
=$
(awk '/^>N/ {print match($9, "Test")}' $LTPTMP/tst_mail.res
)
300 if [ -n "$RC1" -a -n "$RC2" ] && ["$RC1" -ne 0 -a "$RC2" -ne 0 ]
302 $LTPBIN/tst_resm TPASS \
303 "Test #4: Mail was carbon copied to user mail_test"
305 $LTPBIN/tst_res TFAIL
$LTPTMP/tst_mail.res \
306 "Test #4: mail failed to carbon copy user mail_test. Reason:"
307 TFAILCNT
=$
(( $TFAILCNT+1 ))
311 $LTPBIN/tst_resm TCONF
"mail command not installed"
315 # Test that mail -b user@domain option will blind carbon copy that user.
321 $LTPBIN/tst_resm TINFO
"Test #5: Test that mail -b user@domain will"
322 $LTPBIN/tst_resm TINFO
"Test #5: blind carbon copy user@domain"
323 if [ -z $MAIL_NOT_INSTALLED ]; then
325 # send mail to root and carbon copy mail_test
326 mail -s "Test" root@localhost
-c mail_test@localhost
< \
327 $LTPTMP/tst_mail.
in > $LTPTMP/tst_mail.out
2>&1 || RC
=$?
330 $LTPBIN/tst_res TFAIL
$LTPTMP/tst_mail.out \
331 "Test #5: mail command failed. Reason:"
332 TFAILCNT
=$
(( $TFAILCNT+1 ))
334 # Check if mail_test received the mail and
335 # also if root received the main copy of the email.
337 echo "d" |
mail -u root
> $LTPTMP/tst_mail.res
2>&1
338 RC1
=$
(awk '/^>N/ {print match($9, "Test")}' $LTPTMP/tst_mail.res
)
339 echo "d" |
mail -u mail_test
> $LTPTMP/tst_mail.res
2>&1
340 RC2
=$
(awk '/^>N/ {print match($9, "Test")}' $LTPTMP/tst_mail.res
)
341 if [ -n "$RC1" -a -n "$RC2" ] && [ "$RC1" -ne 0 -a "$RC2" -ne 0 ]
343 $LTPBIN/tst_resm TPASS \
344 "Test #5: Mail was carbon copied to user mail_test"
346 $LTPBIN/tst_res TFAIL
$LTPTMP/tst_mail.res \
347 "Test #5: mail failed to carbon copy user mail_testi. Reason:"
348 TFAILCNT
=$
(( $TFAILCNT+1 ))
352 $LTPBIN/tst_resm TCONF
"mail command not installed"
356 # remove all the temporary files created by this test.
360 $LTPBIN/tst_resm TINFO
"Test CLEAN: Removing temporary files from $LTPTMP"
361 rm -fr $LTPTMP/tst_mail
*
363 $LTPBIN/tst_resm TINFO
"Test CLEAN: Removing temporary user mail_test"
364 userdel
-r mail_test
> /dev
/null
2>&1