wget/Sanity/https/runtest.sh
2023-07-31 16:21:33 +02:00

136 lines
4.6 KiB
Bash
Executable file

#!/bin/bash
# vim: dict=/usr/share/rhts-library/dictionary.vim cpt=.,w,b,u,t,i,k
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# runtest.sh of /CoreOS/wget/Sanity/https
# Description: Sanity test for https options
# Author: Petr Splichal <psplicha@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="wget"
WwwUrl="https://localhost/wget/"
WwwDir="/var/www/html/wget"
srv_key=/etc/pki/tls/private/localhost.key
srv_cert=/etc/pki/tls/certs/localhost.crt
rlJournalStart
# set up
rlPhaseStartSetup
rlAssertRpm $PACKAGE
rlRun "TmpDir=\`mktemp -d\`" 0 "Creating tmp directory"
# create test www content
rlRun "mkdir $WwwDir" 0 "Creating www directory"
rlRun "echo 'TestContent' > $WwwDir/index.html"
# start the server ang go!
if [ -e $srv_key ]; then
rlRun "rlFileBackup $srv_key"
else
rlLog "$srv_key does not exist, not backing up"
fi
if [ -e $srv_cert ]; then
rlRun "rlFileBackup $srv_cert"
else
rlLog "$srv_cert does not exist, not backing up"
fi
if rlIsRHEL '5'; then
sig_hash="-sha1"
else
sig_hash="-sha256"
fi
rlRun "openssl req -x509 -newkey rsa:2048 -keyout $srv_key -out $srv_cert -subj '/CN=$(hostname)' -nodes -batch $sig_hash"
netstat -tulpn
rlRun "rlServiceStart httpd"
rlRun "pushd $TmpDir"
rlPhaseEnd
# get redhat page
rlPhaseStartTest "Test redhat.com page"
rlRun "mkdir redhat"
rlRun "pushd redhat"
rlRun "wget --inet4-only -O index.html https://www.redhat.com/"
rlAssertExists "index.html"
rlAssertGrep '</html>' 'index.html' -i
rlRun "popd"
rlPhaseEnd
# bad certificate
rlPhaseStartTest "Bad certificate"
rlRun "mkdir bad-certificate"
rlRun "pushd bad-certificate"
rlRun "wget $WwwUrl" 1,5
rlAssertNotExists "index.html"
rlRun "popd"
rlPhaseEnd
# --no-check--certificate
rlPhaseStartTest "Test --no-check--certificate"
rlRun "mkdir test--no-check-certificate"
rlRun "pushd test--no-check-certificate"
rlRun "wget --no-check-certificate $WwwUrl" 0
rlAssertExists "index.html"
rlAssertGrep "TestContent" "index.html"
rlRun "popd"
rlPhaseEnd
rlPhaseStartTest "Test --ca-certificate"
rlRun "wget --ca-certificate=/etc/pki/tls/certs/localhost.crt https://$(hostname)/wget/" 0
rlAssertExists "index.html"
rlAssertGrep "TestContent" "index.html"
rlRun "rm index.html"
rlPhaseEnd
# wget on RHEL <7.4 doesn't understand the TLSv1_2 name
if ! rlIsRHEL '<7.4'; then
rlPhaseStartTest "Test TLS 1.2"
rlRun "wget --ca-certificate=/etc/pki/tls/certs/localhost.crt --secure-protocol=TLSv1_2 https://$(hostname)/wget/" 0
rlAssertExists "index.html"
rlAssertGrep "TestContent" "index.html"
rlRun "rm index.html"
rlPhaseEnd
fi
# TLS 1.3 was added in RHEL-8
if ! rlIsRHEL '<8'; then
rlPhaseStartTest "Test TLS 1.3"
rlRun "wget --ca-certificate=/etc/pki/tls/certs/localhost.crt --secure-protocol=TLSv1_3 https://$(hostname)/wget/" 0
rlAssertExists "index.html"
rlAssertGrep "TestContent" "index.html"
rlRun "rm index.html"
rlPhaseEnd
fi
# clean up
rlPhaseStartCleanup
rlRun "tree || find"
rlRun "popd"
rlFileRestore
rlRun "rlServiceRestore httpd"
rlRun "rm -r $TmpDir $WwwDir" 0 "Removing test directories"
rlPhaseEnd
rlJournalPrintText
rlJournalEnd