#!/bin/bash
# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# runtest.sh of /CoreOS/lftp/Regression/bz928307-follow-302-redirect
# Description: Basic smoke test for mod_wsgi
# Author: Petr Splichal <psplicha@redhat.com>
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Copyright (c) 2010 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
PACKAGES=${PACKAGES:-lftp}
REQUIRES=${REQUIRES:-httpd mod_wsgi}
rlJournalStart
rlPhaseStartSetup
rlRun "rlImport httpd/http" 0 "Importing httpd library" || rlDie
rlAssertRpm 'lftp' || rlDie "lftp not installed"
rlAssertRpm 'httpd' || rlDie "httpd not installed"
if rlIsRHEL '<=7'; then
rlAssertRpm 'mod_wsgi' || rlDie "mod_wsgi not installed"
else
rlAssertRpm 'python3-mod_wsgi' || rlDie "python3-mod_wsgi not installed"
fi
if rlIsRHEL '<7'; then
WSGI_CONF="${httpCONFDIR}/conf.d/wsgi.conf"
else
CONF=$(ls ${httpCONFDIR}/conf.modules.d | grep 10-wsgi.*conf$)
if ! rlIsRHEL '<=7'; then
sed -i s/mod_wsgi.so/mod_wsgi_python3.so/ wsgi.conf
fi
WSGI_CONF="${httpCONFDIR}/conf.modules.d/$CONF"
fi
rlRun "rlFileBackup --clean ${WSGI_CONF}"
rlRun "cp wsgi.conf ${WSGI_CONF}" 0 "Applying mod_wsgi configuration"
rlRun "rlFileBackup --clean ${httpROOTDIR}"
rlRun "mkdir ${httpROOTDIR}/target" 0 "Creating test directory"
rlRun "touch ${httpROOTDIR}/target/{one,two,three,four,five}"
WSGI_DIR="${httpROOTDIR}/wsgi-scripts"
rlRun "mkdir ${WSGI_DIR}" 0 "Creating WSGI script directory"
if rlIsRHEL '<=7'; then
rlRun "cp redir-absolute.py redir-relative.py ${WSGI_DIR}" 0 "Creating WSGI handlers"
else
rlRun "cp redir-absolute3.py ${WSGI_DIR}/redir-absolute.py" 0 "Creating WSGI handler redir-absolute.py"
rlRun "cp redir-relative3.py ${WSGI_DIR}/redir-relative.py" 0 "Creating WSGI handler redir-relative.py"
fi
rlRun "httpStart" 0 "Starting httpd"
rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory"
rlRun "pushd $TmpDir"
# This test needs the `target' directory listing generated by
# mod_autoindex to be available in `index.html'. To accomplish this
# goal, we need to download http://localhost/target/ when index.html
# does not exist. Only after the directory listing has been downloaded
# can we store the result to `index.html' in the `target' directory.
rlRun "curl http://localhost/target/ > index.html" 0 "Generating directory index with mod_autoindex"
rlRun "cp index.html ${httpROOTDIR}/target" 0 "Copying it to server"
rlPhaseEnd
# Try to use lftp's mirror functionality to download the contents of
# http://localhost/target/. There are two URLs which are redirected to this
# address (http://localhost/target/index.html, to be precise):
#
# http://localhost/absolute/
# < HTTP 302 Moved Temporarily
# < Location: http://localhost/target/index.html
#
# http://localhost/relative/
# < HTTP 302 Moved Temporarily
# < Location: /target/index.html
#
# Mirroring either of these two URLs should produce identical results, i.e.
# download the files mentioned in the directory listing.
for REDIR_TYPE in absolute relative; do
rlPhaseStartTest "Testing lftp mirror with $REDIR_TYPE redirect"
URL="http://localhost/${REDIR_TYPE}/"
rlRun -s "curl -vL ${URL}" 0 "Checking if requested URL is present"
rlAssertGrep '200 OK' $rlRun_LOG
rlRun "lftp -c 'mirror -c -I t* -I f* -X th* ${URL} .'"
rlAssertNotExists 'one'
rlAssertExists 'two'
rlAssertNotExists 'three'
rlAssertExists 'four'
rlAssertExists 'five'
rlRun "rm -f one two three four five"
rlPhaseEnd
done
rlPhaseStartCleanup
rlRun "popd"
rlRun "rm -r $TmpDir" 0 "Removing tmp directory"
rlRun "httpStop" 0 "Stopping httpd"
rlRun "rlFileRestore" 0 "Restoring original configuration"
rlRun "rlServiceRestore $httpHTTPD" 0 "Restoring httpd service"
rlPhaseEnd
rlJournalEnd
rlJournalPrintText