From 964d6f91187b92936521423e21c40bb5ae634441 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Holcroft Date: Mon, 16 Oct 2017 17:46:33 +0200 Subject: [PATCH] Add ressource checks --- sub_scripts/testing_process.sh | 114 +++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) diff --git a/sub_scripts/testing_process.sh b/sub_scripts/testing_process.sh index 1f6a1e2..c61ec8c 100644 --- a/sub_scripts/testing_process.sh +++ b/sub_scripts/testing_process.sh @@ -271,6 +271,10 @@ CHECK_URL () { echo -e "\e[37m" # Write in 'light grey' grep "> "$URLS_TO_TEST" + + # CSS, favicon, etc. + cat "$script_dir/url_output" \ + | grep "link" \ + | grep -o 'href=['"'"'"][^"'"'"']*['"'"'"]' \ + | sed -e 's/^href=["'"'"']//' -e 's/["'"'"']$//' \ + | while read x ; do FULL_URL $x ; done \ + | sort --unique \ + | awk 'NF' \ + >> "$URLS_TO_TEST" + + # Get HTTP response code for every ressources + while read -r LINE; do + http_code=$(curl -o /dev/null --location --silent --head --write-out '%{http_code}' "$LINE") + touch "$RESULTS/$http_code" + echo "$LINE" >> "$RESULTS/$http_code" + done < "$URLS_TO_TEST" + + # Get content to make sure this is no SSO catch + if [ -e "$RESULTS/200" ] + then + while read -r LINE; do + curl -o "$RESULTS/download" --location --silent "$LINE" + url_title=$(grep "" "$RESULTS/download" | cut --delimiter='>' --fields=2 | cut --delimiter='<' --fields=1) + + # Check if the page title is neither the YunoHost portail or default nginx page + if [ "$url_title" = "YunoHost Portal" ] + then + touch "$RESULTS/portal" + echo "$LINE" >> "$RESULTS/portal" + fi + + rm "$RESULTS/download" + done < "$RESULTS/200" + fi + + if [ -e "$RESULTS/000" ] + then + ECHO_FORMAT "Some ressources could not be reached by curl.\n" "white" "bold" + cat "$RESULTS/000" + curl_error=1 + fi + + if [ -e "$RESULTS/404" ] + then + ECHO_FORMAT "Some ressources returns a code http 404.\n" "white" "bold" + cat "$RESULTS/404" + curl_error=1 + fi + + if [ -e "$RESULTS/portal" ] + then + ECHO_FORMAT "Some ressources where catched by SSO, they contain YunoHost's portal HTML.\n" "white" "bold" + cat "$RESULTS/portal" + curl_error=1 + rm "$RESULTS/portal" + fi + + wc -l "$RESULTS"/* + rm "$URLS_TO_TEST" + rm -rf "$RESULTS" +} + +FULL_URL() +{ + local url + local directory + local fullpath + url=$1 + + directory=$(dirname "$check_domain/hop") + fullpath=$(realpath -m "$directory/$url") + + if [[ ${url:0:2} == "//" ]] + then + echo "$url" + else + if [[ ${url:0} == "/" ]] + then + echo "$check_domain$url" + else + echo "${fullpath#$(pwd)/}" + fi + fi +} + + #================================================= # Generic functions for unit tests #=================================================