From 964d6f91187b92936521423e21c40bb5ae634441 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Holcroft Date: Mon, 16 Oct 2017 17:46:33 +0200 Subject: [PATCH 1/3] 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 #================================================= From 35e2f53e30d4db698b4aff89b4f6257c9d56a069 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste <jean-baptiste@holcroft.fr> Date: Thu, 19 Oct 2017 11:00:34 +0200 Subject: [PATCH 2/3] add sed to remove folders --- sub_scripts/testing_process.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sub_scripts/testing_process.sh b/sub_scripts/testing_process.sh index c61ec8c..99ddb32 100644 --- a/sub_scripts/testing_process.sh +++ b/sub_scripts/testing_process.sh @@ -370,7 +370,7 @@ CHECK_URL_RESSOURCES() rm "$RESULTS/portal" fi - wc -l "$RESULTS"/* + wc -l "$RESULTS"/* | sed "s|$RESULTS||" rm "$URLS_TO_TEST" rm -rf "$RESULTS" } From 6b314ee11f358b1940906dd0b41432a858b27c6c Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Holcroft <jean-baptiste@holcroft.fr> Date: Thu, 19 Oct 2017 14:40:47 +0200 Subject: [PATCH 3/3] Do not test ressources if the page itself returns an error --- sub_scripts/testing_process.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sub_scripts/testing_process.sh b/sub_scripts/testing_process.sh index 99ddb32..cea8aac 100644 --- a/sub_scripts/testing_process.sh +++ b/sub_scripts/testing_process.sh @@ -273,7 +273,10 @@ CHECK_URL () { echo -e "\e[0m" # Test http status of ressources files - CHECK_URL_RESSOURCES + if [[ $curl_error -eq 0 ]] + then + CHECK_URL_RESSOURCES + fi fi fi