Adding sanity tests

tests:
initscript
headercheck
bodycheck
This commit is contained in:
Frantisek Hrdina 2022-06-02 14:26:06 +02:00
commit 0382a47e2d
6 changed files with 474 additions and 0 deletions

23
Sanity/bodycheck/main.fmf Normal file
View file

@ -0,0 +1,23 @@
summary: bodycheck
description: ''
contact: fhrdina@redhat.com
component:
- postfix
test: ./runtest.sh
framework: beakerlib
recommend:
- postfix
- nc
duration: 20m
enabled: true
tag:
- Tier1
- postfix::junk::bodycheck
tier: '1'
adjust:
- enabled: false
when: distro < rhel-6
continue: false
extra-nitrate: TC#0602484
extra-summary: /CoreOS/postfix/Sanity/bodycheck
extra-task: /CoreOS/postfix/Sanity/bodycheck

138
Sanity/bodycheck/runtest.sh Executable file
View file

@ -0,0 +1,138 @@
#!/bin/bash
# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# runtest.sh of /CoreOS/postfix/Sanity/bodycheck
# Description: bodycheck
# Author: Robin Hack <rhack@redhat.com>
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Copyright (c) 2019 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="postfix"
rlJournalStart
rlPhaseStartSetup
rlAssertRpm $PACKAGE
rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory"
rlRun "pushd $TmpDir"
if rlIsRHEL 5; then
rlServiceStop "sendmail"
fi
rlServiceStop "postfix"
rlFileBackup "/etc/postfix/main.cf"
rlFileBackup "/etc/postfix/vmailbox"
rlFileBackup "/etc/postfix/virtual"
rlPhaseEnd
rlPhaseStartSetup
# don't care
rm -rf /var/mail/vhosts
rlRun "mkdir -p /var/mail/vhosts/example.com"
rlRun "chown -R 5000:5000 /var/mail/vhosts/"
cat << "EOF" > "/etc/postfix/main.cf"
myhostname = randomstuff.at
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = localhost.randomstuff.at, localhost
relayhost =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
smtpd_relay_restrictions = reject_unauth_destination
virtual_mailbox_domains = example.com
virtual_mailbox_base = /var/mail/vhosts
virtual_mailbox_maps = hash:/etc/postfix/vmailbox
virtual_minimum_uid = 100
virtual_uid_maps = static:5000
virtual_gid_maps = static:5000
virtual_alias_maps = hash:/etc/postfix/virtual
body_checks = regexp:/etc/postfix/body_checks
EOF
cat << "EOF" > "/etc/postfix/vmailbox"
info@example.com example.com/info
sales@example.com example.com/sales/
EOF
cat << "EOF" > "/etc/postfix/virtual"
postmaster@example.com postmaster
EOF
cat << "EOF" > "/etc/postfix/body_checks"
/Aliens/ REJECT
EOF
rlRun "postmap /etc/postfix/virtual"
rlRun "postmap /etc/postfix/vmailbox"
rlServiceStart "postfix"
rlPhaseEnd
rlPhaseStartTest
cat << "EOF" | nc localhost 25 &> TESTOUT
EHLO aliens.outerworld
MAIL FROM: friendly@alien.xt
RCPT TO: info@example.com
DATA
Hello we are friendly Aliens and we are comming in peace!
.
EOF
rlAssertGrep "message content rejected" TESTOUT
rlAssertNotGrep "Ok: queued as" TESTOUT
rlPhaseEnd
rlPhaseStartCleanup
rlRun "popd"
rlRun "rm -r $TmpDir" 0 "Removing tmp directory"
rlRun "rm -rf /var/mail/vhosts"
rlServiceStop "postfix"
rlFileRestore
rlRun "rm -rf /etc/postfix/vmailbox.db"
rlRun "rm -rf /etc/postfix/virtual.db"
rlRun "rm -rf /etc/postfix/body_checks"
if rlIsRHEL 5; then
rlServiceRestore "sendmail"
rlServiceStop "postfix"
else
rlServiceRestore "postfix"
fi
rlPhaseEnd
rlJournalPrintText
rlJournalEnd

View file

@ -0,0 +1,23 @@
summary: headercheck
description: ''
contact: fhrdina@redhat.com
component:
- postfix
test: ./runtest.sh
framework: beakerlib
recommend:
- postfix
- nc
duration: 20m
enabled: true
tag:
- Tier1
- postfix::junk::headercheck
tier: '1'
adjust:
- enabled: false
when: distro < rhel-6
continue: false
extra-nitrate: TC#0602485
extra-summary: /CoreOS/postfix/Sanity/headercheck
extra-task: /CoreOS/postfix/Sanity/headercheck

139
Sanity/headercheck/runtest.sh Executable file
View file

@ -0,0 +1,139 @@
#!/bin/bash
# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# runtest.sh of /CoreOS/postfix/Sanity/headercheck
# Description: headercheck
# Author: Robin Hack <rhack@redhat.com>
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Copyright (c) 2019 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="postfix"
rlJournalStart
rlPhaseStartSetup
rlAssertRpm $PACKAGE
rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory"
rlRun "pushd $TmpDir"
if rlIsRHEL 5; then
rlServiceStop "sendmail"
fi
rlServiceStop "postfix"
rlFileBackup "/etc/postfix/main.cf"
rlFileBackup "/etc/postfix/vmailbox"
rlFileBackup "/etc/postfix/virtual"
rlPhaseEnd
rlPhaseStartSetup
# don't care
rm -rf /var/mail/vhosts
rlRun "mkdir -p /var/mail/vhosts/example.com"
rlRun "chown -R 5000:5000 /var/mail/vhosts/"
cat << "EOF" > "/etc/postfix/main.cf"
myhostname = randomstuff.at
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = localhost.randomstuff.at, localhost
relayhost =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
smtpd_relay_restrictions = reject_unauth_destination
virtual_mailbox_domains = example.com
virtual_mailbox_base = /var/mail/vhosts
virtual_mailbox_maps = hash:/etc/postfix/vmailbox
virtual_minimum_uid = 100
virtual_uid_maps = static:5000
virtual_gid_maps = static:5000
virtual_alias_maps = hash:/etc/postfix/virtual
header_checks = regexp:/etc/postfix/header_checks
EOF
cat << "EOF" > "/etc/postfix/vmailbox"
info@example.com example.com/info
sales@example.com example.com/sales/
EOF
cat << "EOF" > "/etc/postfix/virtual"
postmaster@example.com postmaster
EOF
cat << "EOF" > "/etc/postfix/header_checks"
/^From.*alien\.xt/ REJECT Sorry, no aliens welcome!
EOF
rlRun "postmap /etc/postfix/virtual"
rlRun "postmap /etc/postfix/vmailbox"
rlServiceStart "postfix"
rlPhaseEnd
rlPhaseStartTest
cat << "EOF" | nc localhost 25 &> TESTOUT
EHLO aliens.outerworld
MAIL FROM: friendly@alien.xt
RCPT TO: info@example.com
DATA
From: friendly@alien.xt
Hello we are friendly Aliens and we are comming in peace!
.
EOF
rlAssertGrep "Sorry, no aliens welcome!" TESTOUT
rlAssertNotGrep "Ok: queued as" TESTOUT
rlPhaseEnd
rlPhaseStartCleanup
rlRun "popd"
rlRun "rm -r $TmpDir" 0 "Removing tmp directory"
rlRun "rm -rf /var/mail/vhosts"
rlServiceStop "postfix"
rlFileRestore
rlRun "rm -rf /etc/postfix/vmailbox.db"
rlRun "rm -rf /etc/postfix/virtual.db"
rlRun "rm -rf /etc/postfix/header_checks"
if rlIsRHEL 5; then
rlServiceRestore "sendmail"
rlServiceStop "postfix"
else
rlServiceRestore "postfix"
fi
rlPhaseEnd
rlJournalPrintText
rlJournalEnd

View file

@ -0,0 +1,26 @@
summary: Basic initscript test for postfix
description: ''
contact: fhrdina@redhat.com
component:
- postfix
test: ./runtest.sh
framework: beakerlib
recommend:
- postfix
duration: 5m
enabled: true
tag:
- Tier1
- postfix::initscripts
tier: '1'
link:
- relates: https://bugzilla.redhat.com/show_bug.cgi?id=584377
- relates: https://bugzilla.redhat.com/show_bug.cgi?id=557756
- relates: https://bugzilla.redhat.com/show_bug.cgi?id=528151
adjust:
- enabled: false
when: distro < rhel-6
continue: false
extra-nitrate: TC#0044097
extra-summary: /CoreOS/postfix/Sanity/initscript
extra-task: /CoreOS/postfix/Sanity/initscript

125
Sanity/initscript/runtest.sh Executable file
View file

@ -0,0 +1,125 @@
#!/bin/bash
# vim: dict=/usr/share/rhts-library/dictionary.vim cpt=.,w,b,u,t,i,k
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# runtest.sh of /CoreOS/postfix/Sanity/initscript
# Description: Init script should meet LSB specifications
# Author: Jan Scotka <jscotka@redhat.com>, Yulia Kopkova <ykopkova@redhat.com>
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Copyright (c) 2009 Red Hat, Inc. All rights reserved.
#
# This copyrighted material is made available to anyone wishing
# to use, modify, copy, or redistribute it subject to the terms
# and conditions of the GNU General Public License version 2.
#
# 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, write to the Free
# Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301, USA.
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Include rhts environment
. /usr/share/beakerlib/beakerlib.sh || exit 1
PACKAGE="postfix"
STATUS_LOG="test.log"
SERVICE=$PACKAGE
rlJournalStart
rlPhaseStartSetup
rlAssertRpm $PACKAGE
rlRun "useradd testuserqa" 0 "Add test user"
rlServiceStop sendmail
rlServiceStop $SERVICE
rlRun "TmpDir=\`mktemp -d\`"
rlRun "pushd $TmpDir"
rlPhaseEnd
rlPhaseStartTest
rlLog ">>>>>>>>> service start"
rlRun "service $SERVICE start" 0 " Service must start without problem"
rlRun "service $SERVICE status &>> $STATUS_LOG" 0 " Then Status command "
rlRun "service $SERVICE start" 0 " Already started service "
rlRun "service $SERVICE status &>> $STATUS_LOG" 0 " Again status command "
rlLog ">>>>>>>>> service restart"
rlRun "service $SERVICE restart" 0 " Restarting of service"
rlRun "service $SERVICE status &>> $STATUS_LOG" 0 " Status command "
rlLog ">>>>>>>>> service stop"
rlRun "service $SERVICE stop" 0 " Stopping service "
rlRun "service $SERVICE status &>> $STATUS_LOG" 3 " Status of stopped service "
rlRun "service $SERVICE stop" 0 " Stopping service again "
rlRun "service $SERVICE status &>> $STATUS_LOG" 3 " Status of stopped service "
rlServiceStart $SERVICE
sleep 10
rlAssertExists "/var/spool/postfix/pid/master.pid" "Pid file /var/spool/postfix/pid/master.pid must exist"
SERVICE_PID=`cat /var/spool/postfix/pid/master.pid`
rlRun "kill -11 $SERVICE_PID" 0 "Kill $SERVICE"
sleep 5
if rlIsRHEL '<=6'; then
EXIT_STATUS=1;
rlAssertExists "/var/spool/postfix/pid/master.pid" "Pid file /var/spool/postfix/pid/master.pid must exist after kill"
else
EXIT_STATUS=3;
fi
rlRun "service $SERVICE status &>> $STATUS_LOG" $EXIT_STATUS " Existing pid file, but service not started "
rlRun "rm -f /var/spool/postfix/pid/master.pid" 0 "Remove .pid file"
rlLog ">>>>>>>>> lock file"
if rlIsRHEL '<=6'; then
EXIT_STATUS=2;
rlAssertExists "/var/lock/subsys/$SERVICE" "Lock file /var/lock/subsys/$SERVICE must exist"
else
EXIT_STATUS=3;
fi
rlRun "service $SERVICE status &>> $STATUS_LOG" $EXIT_STATUS "Existing lock file, but service not started "
rlServiceStop $SERVICE
rlLog ">>>>>>>>> insufficient rights"
# Polkit rpm installed is causing that running with insufficient rights returns 1 instead of 4
if ( (rlIsRHEL '>=9' || rlIsFedora) && ! rlCheckRpm 'polkit' ) || rlIsRHEL '<=6' ; then
ACCESS_DENIED_EXIT_STATUS=4
else
ACCESS_DENIED_EXIT_STATUS=1
fi
rlRun "service $SERVICE start " 0 " Starting service for restarting under nonpriv user "
rlRun "su testuserqa -c 'service $SERVICE restart'" $ACCESS_DENIED_EXIT_STATUS "Insufficient rights, restarting service under nonprivileged user must fail"
rlLog ">>>>>>>>> operations"
rlRun "service $SERVICE start" 0 " Service have to implement start function "
rlRun "service $SERVICE restart" 0 " Service have to implement restart function "
rlRun "service $SERVICE status &>> $STATUS_LOG" 0 " Service have to implement status function "
rlRun "service $SERVICE condrestart" 0 " Service have to implement condrestart function "
rlRun "service $SERVICE reload" 0 " Service have to implement reload function "
rlRun "service $SERVICE force-reload" 0 " Service have to implement force-reload function "
rlLog ">>>>>>>>> nonexist operations"
rlRun "service $SERVICE noexistop" 2 " Testing proper return code when nonexisting function"
rlPhaseEnd
rlPhaseStartCleanup
rlServiceRestore $SERVICE
rlServiceRestore sendmail
rlRun "userdel -fr testuserqa" 0 "Remove test user"
rlRun "popd"
rlRun "rm -r $TmpDir"
rlPhaseEnd
rlJournalPrintText
rlJournalEnd