Blob Blame History Raw
#!/bin/bash
# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
#   runtest.sh of /CoreOS/lftp/Regression/bz1364524-get-nonexistent-file
#   Description: Download nonexistent file with lftp
#   Author: Martin Frodl <mfrodl@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

PACKAGES="lftp"
CONF="/etc/vsftpd/vsftpd.conf"

rlJournalStart
    rlPhaseStartSetup
        rlAssertRpm --all

        rlFileBackup --clean /var/ftp
        rlRun "echo 'Quack!' > /var/ftp/duck" 0 "Creating test file on FTP server"
        rlRun "rlFileBackup $CONF" 0 "Back up $CONF"
        if ! rlIsRHEL '<=7'; then
            rlRun "sed -i s/anonymous_enable=NO/anonymous_enable=YES/ $CONF" 0 "Allow anonymous login"
        fi
        rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory"
        rlRun "pushd $TmpDir"
        rlRun "rlServiceStart vsftpd" 0 "Starting vsftpd FTP server"
    rlPhaseEnd

    rlPhaseStartTest "Download existing file from localhost FTP server"
        rlRun "lftp ftp://localhost -e 'get -c duck; exit'" 0 "Downloading existing file"
        rlAssertGrep 'Quack!' duck
    rlPhaseEnd

    rlPhaseStartTest "Download nonexistent file from localhost FTP server"
        rlRun "rlWatchdog \"lftp ftp://localhost -e 'get -c chick; exit'\" 8" 0 "Download nonexistent file"
        rlAssertNotExists "chick"
    rlPhaseEnd

    rlPhaseStartCleanup
        rlRun "popd"
        rlRun "rm -r $TmpDir" 0 "Removing tmp directory"
        rlRun "rlFileRestore" 0 "Restore $CONF"
        rlRun "rlServiceStop vsftpd" 0 "Stopping FTP server"
        rlFileRestore
    rlPhaseEnd
rlJournalPrintText
rlJournalEnd