Blob Blame History Raw
#!/bin/bash
# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
#   runtest.sh of /CoreOS/cups/Sanity/bz1257751-Email-notifications-lp-m-for-printer-classes
#   Description: Test for BZ#1257751 (Email notifications ("lp -m") for printer classes)
#   Author: Petr Sklenar <psklenar@redhat.com>
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
#   Copyright (c) 2016 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="cups"
MYHASH=petr$RANDOM
rlJournalStart
    rlPhaseStartSetup "setup cups"
        rlRun "rpm -q $PACKAGE"
        rlFileBackup /etc/cups/cupsd.conf
        echo "FileDevice Yes" >> /etc/cups/cupsd.conf
        rlServiceStart cups
        lpadmin -p testb$MYHASH -v file:///dev/null -E
        lpadmin -p testa$MYHASH -v file:///dev/null -E
        lpadmin -p testa$MYHASH -c testclass$MYHASH
        lpadmin -p testb$MYHASH -c testclass$MYHASH
        cupsenable testclass$MYHASH
        rlRun "cupsaccept testclass$MYHASH"
    rlPhaseEnd

    rlPhaseStartSetup "set up mail"
        rlFileBackup --clean /etc/cups/mailto.conf
        rlRun "rpm -q sendmail"
        echo "Subject $MYHASH" > /etc/cups/mailto.conf
        rlServiceStart sendmail
    rlPhaseEnd

    rlPhaseStartTest
        rlRun "useradd $MYHASH"
        rlRun "grep $MYHASH /var/spool/mail/$MYHASH|grep fstab" 1 "no mail should be there"
        su $MYHASH -c "lp -d testclass$MYHASH -m /etc/fstab"
        rlAssert0 "send a mail as $MYHASH" $?
#        rlRun "grep $MYHASH /var/spool/mail/$MYHASH|grep fstab" 1 "no mail as its too quick"
#I thing it shouldn't send mail so quickly ^
        sleep 10
        rlRun "grep $MYHASH /var/spool/mail/$MYHASH|grep fstab" 0 "NOW it should be with MAIL"
    rlPhaseEnd

    rlPhaseStartCleanup
        rlRun "cancel -a" 0 "Cancel job if needed"
        rlFileSubmit /var/log/cups/error_log
        userdel -r $MYHASH
        lpadmin -x testa$MYHASH
        lpadmin -x testb$MYHASH
        lpadmin -x testclass$MYHASH
        rlFileRestore
        rlServiceRestore cups
    rlPhaseEnd
rlJournalPrintText
rlJournalEnd