159 lines
5.7 KiB
Bash
Executable file
159 lines
5.7 KiB
Bash
Executable file
#!/bin/bash
|
|
# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
#
|
|
# runtest.sh of /CoreOS/sendmail/functionality/singlehost
|
|
# Description: Sendmail - sanity checking, there are two users on
|
|
# one machine, sending mails each other, checking
|
|
# sending mail, incoming mail, e-mail parser
|
|
#
|
|
# Author: Petr Sklenar <psklenar@redhat.com>
|
|
# Rewritten (beakerlib): Patrik Mosko <pmosko@redhat.com>
|
|
#
|
|
#
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
#
|
|
# Copyright (c) 2018 Red Hat, Inc.
|
|
#
|
|
# This program is free software: you can redistribute it and/or
|
|
# modify it under the terms of the GNU General Public License as
|
|
# published by the Free Software Foundation, either version 2 of
|
|
# the License, or (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be
|
|
# useful, but WITHOUT ANY WARRANTY; without even the implied
|
|
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
# PURPOSE. See the GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see http://www.gnu.org/licenses/.
|
|
#
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
# Include Beaker environment
|
|
. /usr/share/beakerlib/beakerlib.sh || exit 1
|
|
|
|
PACKAGE=sendmail
|
|
|
|
rlJournalStart
|
|
|
|
########## SETUP PHASE ##########
|
|
rlPhaseStartSetup
|
|
MAIL_SEND="200"
|
|
USER1=testuser_mail
|
|
MAIL_NUMBER_1="undef"
|
|
MAIL_NUMBER_2=0
|
|
|
|
rlAssertRpm $PACKAGE
|
|
rlRun "useradd -G mail $USER1"
|
|
|
|
rlFileBackup --clean --missing-ok "/etc/mail/sendmail.mc"
|
|
rlFileBackup --clean --missing-ok "/etc/mail/access"
|
|
rlFileBackup --clean --missing-ok "/var/spool/mail/$USER1"
|
|
rlFileBackup "/var/lib/alternatives/mta"
|
|
rlFileBackup "/etc/alternatives"
|
|
|
|
rlLog "changing configuration files"
|
|
rlRun "sed -i -e \"s/^DAEMON_OPTIONS.* /dnl ##### \\\0 /\" /etc/mail/sendmail.mc"
|
|
rlRun "sed -i -e \"s/.*FEATURE(\\\`relay_based_on_MX').*/dnl ##### \\\0 /\" /etc/mail/sendmail.mc"
|
|
rlRun "sed -i -e \"s/.*FEATURE(\\\`accept_unresolvable_domains').*/dnl ##### \\\0 /\" /etc/mail/sendmail.mc"
|
|
rlRun "echo \`hostname\` RELAY >> /etc/mail/access"
|
|
rlRun "echo \`hostname -d\` RELAY >> /etc/mail/access"
|
|
rlRun "echo \`hostname -f\` RELAY >> /etc/mail/access"
|
|
|
|
rlRun "cat /etc/mail/access"
|
|
rlRun "cat /etc/hosts"
|
|
rlRun "rm -rf /var/spool/mail/$USER1"
|
|
rlRun "mail_tmp=\`mktemp\`" 0 "Creating temporary file for storing results"
|
|
|
|
service postfix status --no-pager && rlServiceStop postfix
|
|
service sendmail status --no-pager && rlServiceStop sendmail
|
|
rlRun "alternatives --set mta $(rpm --eval '%{_sbindir}')/sendmail.sendmail"
|
|
|
|
rlRun "cd /etc/mail"
|
|
rlRun "sudo make"
|
|
rlServiceStart "sendmail"
|
|
rlPhaseEnd
|
|
|
|
|
|
#################### TEST PHASE ####################
|
|
rlPhaseStartTest "Sending mails"
|
|
rlRun "nmap -p 25 localhost"
|
|
|
|
for i in `seq 1 $MAIL_SEND`; do
|
|
mail -s test_message_subject $USER1@localhost.localdomain << EOF
|
|
This is $i. test message
|
|
EOF
|
|
sleep 0.4
|
|
done
|
|
sleep 60
|
|
|
|
rlRun "MAIL_bak=$MAIL" 0 "Backup MAIL variable"
|
|
rlRun "export \"MAIL=/var/spool/mail/$USER1\""
|
|
|
|
# reading mail files usig basic cat:
|
|
rlLog "Running 'cat /var/spool/mail/$USER1'"
|
|
cat /var/spool/mail/$USER1 | rlLog "1. File /var/spool/mail/$USER1 is readable"
|
|
QUEUE1=$(sendmail -bp | grep "Total requests:" | awk '{print $3}')
|
|
MAIL_NUMBER_1=$(cat /var/spool/mail/$USER1 | grep "This is .* test message" | wc -l)
|
|
|
|
[[ $MAIL_NUMBER_1 != undef ]] && rlPass "2a. There are $MAIL_NUMBER_1 messages delivered"
|
|
rlLog "2b. There are $QUEUE1 messages in queue"
|
|
|
|
rlRun "let \"MAIL_NUMBER_1 += QUEUE1\""
|
|
if [[ $MAIL_SEND -ge $MAIL_NUMBER_1 ]]; then
|
|
rlLog "2c. There are together $MAIL_NUMBER_1 messages (queue + send & received)"
|
|
fi
|
|
rlPhaseEnd
|
|
|
|
|
|
#################### TEST PHASE ####################
|
|
rlPhaseStartTest "Reading mails with 'mail'"
|
|
rlRun "/usr/sbin/sendmail -q"
|
|
sleep 30
|
|
|
|
if (rlIsRHELLike '>=9' || rlIsFedora); then
|
|
rlRun "cat /var/spool/mail/$USER1 > $mail_tmp"
|
|
else
|
|
mail << EOF > /a.temp
|
|
quit
|
|
EOF
|
|
|
|
sleep 30
|
|
mail << EOF > $mail_tmp
|
|
quit
|
|
EOF
|
|
fi
|
|
#bash
|
|
|
|
# comparing previous two way of reading
|
|
rlRun "/usr/sbin/sendmail -q"
|
|
MAIL_NUMBER_2=$(cat $mail_tmp | grep "Held .* messages in" | awk '{print $2}')
|
|
[[ $MAIL_SEND -ge $MAIL_NUMBER_2 ]] &&
|
|
rlPass "3. There are $MAIL_NUMBER_2 messages" ||
|
|
rlFail "3. Something wrong, there should be no more than $MAIL_SEND messages!"
|
|
|
|
# delivered mail + mail in queue = sent mails
|
|
QUEUE2=$(sendmail -bp | grep "Total requests:" | awk '{print $3}')
|
|
rlLog "There are $QUEUE2 mails now!!!!!"
|
|
rlPhaseEnd
|
|
|
|
|
|
########## CLEANUP PHASE ##########
|
|
rlPhaseStartCleanup
|
|
rlRun "rm -f $mail_tmp"
|
|
rlFileRestore
|
|
|
|
# restore MTA's
|
|
service sendmail status --no-pager && rlServiceStop sendmail
|
|
service postfix status --no-pager && rlServiceStop postfix
|
|
rlRun "alternatives --auto mta"
|
|
rlServiceRestore "sendmail"
|
|
rlCheckpm && rlServiceRestore "postfix"
|
|
|
|
rlRun "userdel -fr $USER1"
|
|
rlRun "export MAIL=$MAIL_bak"
|
|
rlPhaseEnd
|
|
rlJournalPrintText
|
|
rlJournalEnd
|
|
|