123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- #Copyright (C) 2016,2023 Weber Yann
- #
- #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 3 of the License, or
- #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/>.
-
-
- #
- # HTTP/HTTPS tests
- #
-
- _check_http_status() {
- # $1 url
- # $2 status
- # $* curl options
- url=$1
- shift 1
- expt=$1
- if [ -z "$1" ]
- then
- expt=200
- fi
- shift 1
-
- status=$(curl -s -o /dev/null -w "%{http_code}" "$@" "$url")
- if [ "$status" -ne "$expt" ]
- then
- fail "Check http status $expt for $url : $status returned"
- elif [ "$verbose" -gt 0 ]
- then
- success "Check http status $status for $url"
- fi
- }
-
- check_http_status() {
- # $1 url
- # $2 status
- _check_http_status "$1" "$2"
- }
-
- check_http_200() {
- _check_http_status "$1" 200
- }
-
- check_https_cert() {
- # Check that SSL Cert is valid
- # $1 URL
- status=$(curl -s -o /dev/null -w "%{http_code}" "https://$1")
- rep=$?
- if [ "$rep" -eq 0 ]
- then
- success "https://$1 cert verified"
- return
- fi
- status=$(curl -k -s -o /dev/null -q "%{http_code}" "https://$1")
- rep=$?
- if [ "$rep" -eq 0 ]
- then
- fail "https://$1 cert invalid"
- else
- err "Unable to curl https://$1"
- fi
- }
-
- check_html_title() {
- url="$1"
- expt="$2"
-
- tmpxsl=$(mktemp -t XSL.XXXXXXXXXXX)
- echo '<?xml version="1.0"?>
- <xsl:stylesheet version="1.0"
- xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
- <xsl:output method = "text"/>
- <xsl:template match="/">
- <xsl:value-of select="/html/head/title"/>
- </xsl:template>
- </xsl:stylesheet>' > "$tmpxsl"
-
- tmphtml=$(mktemp -t html.XXXXXXXXX)
-
- curl --silent "$url" > "$tmphtml"
- if title=$(xsltproc --html --novalid "$tmpxsl" "$tmphtml" 2>/dev/null)
- then
- :
- else
- title=$(xsltproc --novalid "$tmpxsl" "$tmphtml" 2>/dev/null)
- fi
-
- if [ "$title" = "$expt" ]
- then
- success "$url HTML title is '$expt'"
- else
- fail "$url HTML title is '$title' but '$expt' expected"
- fi
-
- rm "$tmpxsl" "$tmphtml" 2>/dev/null
- }
|