From 36ecc2800314f75c1687e1e686cbd7ccc2de77fd Mon Sep 17 00:00:00 2001 From: Mitchell Krog Date: Sat, 22 Jun 2019 09:58:48 +0200 Subject: [PATCH] Fix New Curl Test Format on Test Unit REF: #264 --- .../run-curl-tests-testing-of-changes.sh | 55 +++++-------------- 1 file changed, 14 insertions(+), 41 deletions(-) diff --git a/.dev-tools/run-curl-tests-testing-of-changes.sh b/.dev-tools/run-curl-tests-testing-of-changes.sh index 88250010e..2e0151f7b 100755 --- a/.dev-tools/run-curl-tests-testing-of-changes.sh +++ b/.dev-tools/run-curl-tests-testing-of-changes.sh @@ -27,11 +27,8 @@ echo "Tests Starting" # ************************************************* run_curltest1 () { -truncate -s 0 ${_curltest1} printf '\n%s\n%s\n%s\n\n' "#########################" "TESTING BAD BOT IS DENIED" "#########################" -printf '%s%s\n\n' "Last Tested: " "$_now" >> "${_curltest1}" -curl -A "80legs" http://localhost:9000/index.php 2>> ${_curltest1} -if grep -i '(52)' ${_curltest1}; then +if curl -A "80legs" http://localhost:9000/index.php 2 | grep -i '(52)'; then echo "$(tput setaf 2)BAD BOT DETECTED - TEST PASSED" else echo "$(tput setaf 1)BAD BOT NOT DETECTED - TEST FAILED" @@ -45,11 +42,8 @@ run_curltest1 # ************************************************** run_curltest2 () { -truncate -s 0 ${_curltest2} printf '\n%s\n%s\n%s\n\n' "#########################" "TESTING BAD BOT IS DENIED" "#########################" -printf '%s%s\n\n' "Last Tested: " "$_now" >> "${_curltest2}" -curl -A "Nutch" http://localhost:9000/index.php 2>> ${_curltest2} -if grep -i '(52)' ${_curltest2}; then +if curl -A "Nutch" http://localhost:9000/index.php 2 | grep -i '(52)'; then echo "$(tput setaf 2)BAD BOT DETECTED - TEST PASSED" else echo "$(tput setaf 1)BAD BOT NOT DETECTED - TEST FAILED" @@ -64,11 +58,8 @@ run_curltest2 # ****************************************************************** run_curltest3 () { -truncate -s 0 ${_curltest3} printf '\n%s\n%s\n%s\n\n' "##############################" "TESTING BAD REFERRER IS DENIED" "##############################" -printf '%s%s\n\n' "Last Tested: " "$_now" >> "${_curltest3}" -curl -I http://localhost:9000/index.php -e http://100dollars-seo.com 2>> ${_curltest3} -if grep -i '(52)' ${_curltest3}; then +if curl -I http://localhost:9000/index.php -e http://100dollars-seo.com 2 | grep -i '(52)'; then echo "$(tput setaf 2)BAD REFERRER DETECTED - TEST PASSED" else echo "$(tput setaf 1)BAD REFERRER NOT DETECTED - TEST FAILED" @@ -83,11 +74,8 @@ run_curltest3 # ****************************************************** run_curltest4 () { -truncate -s 0 ${_curltest4} printf '\n%s\n%s\n%s\n\n' "##############################" "TESTING BAD REFERRER IS DENIED" "##############################" -printf '%s%s\n\n' "Last Tested: " "$_now" >> "${_curltest4}" -curl -I http://localhost:9000/index.php -e http://zx6.ru 2>> ${_curltest4} -if grep -i '(52)' ${_curltest4}; then +if curl -I http://localhost:9000/index.php -e http://zx6.ru 2 | grep -i '(52)'; then echo "$(tput setaf 2)BAD REFERRER DETECTED - TEST PASSED" else echo "$(tput setaf 1)BAD REFERRER NOT DETECTED - TEST FAILED" @@ -101,11 +89,8 @@ run_curltest4 # ***************************************************** run_curltest5 () { -truncate -s 0 ${_curltest5} printf '\n%s\n%s\n%s\n\n' "###########################" "TESTING GOOD BOT IS ALLOWED" "###########################" -printf '%s%s\n\n' "Last Tested: " "$_now" >> "${_curltest5}" -curl -v -A "GoogleBot" http://localhost:9000/index.php 2>&1 >> ${_curltest5} -if grep -i 'Welcome' ${_curltest5}; then +if curl -v -A "GoogleBot" http://localhost:9000/index.php 2>&1 | grep -i 'Welcome'; then echo "$(tput setaf 2)GOOD BOT ALLOWED THROUGH - TEST PASSED" else echo "$(tput setaf 1)GOOD BOT NOT ALLOWED THROUGH - TEST FAILED" @@ -119,11 +104,8 @@ run_curltest5 # *************************************************** run_curltest6 () { -truncate -s 0 ${_curltest6} printf '\n%s\n%s\n%s\n\n' "###########################" "TESTING GOOD BOT IS ALLOWED" "###########################" -printf '%s%s\n\n' "Last Tested: " "$_now" >> "${_curltest6}" -curl -v -A "BingBot" http://localhost:9000/index.php 2>&1 >> ${_curltest6} -if grep -i 'Welcome' ${_curltest6}; then +if curl -v -A "BingBot" http://localhost:9000/index.php 2>&1 | grep -i 'Welcome'; then echo "$(tput setaf 2)GOOD BOT ALLOWED THROUGH - TEST PASSED" else echo "$(tput setaf 1)GOOD BOT NOT ALLOWED THROUGH - TEST FAILED" @@ -137,11 +119,8 @@ run_curltest6 # *********************************************************** run_curltest7 () { -truncate -s 0 ${_curltest7} printf '\n%s\n%s\n%s\n\n' "################################" "TESTING GOOD REFERRER IS ALLOWED" "################################" -printf '%s%s\n\n' "Last Tested: " "$_now" >> "${_curltest7}" -curl http://localhost:9000/index.php -e http://google.com 2>&1 >> ${_curltest7} -if grep -i 'Welcome' ${_curltest7}; then +if curl http://localhost:9000/index.php -e http://google.com 2>&1 | grep -i 'Welcome'; then echo "$(tput setaf 2)GOOD REFERRER DETECTED - TEST PASSED" else echo "$(tput setaf 1)GOOD REFERRER NOT DETECTED - TEST FAILED" @@ -155,11 +134,8 @@ run_curltest7 # *********************************************************** run_curltest8 () { -truncate -s 0 ${_curltest8} printf '\n%s\n%s\n%s\n\n' "################################" "TESTING GOOD REFERRER IS ALLOWED" "################################" -printf '%s%s\n\n' "Last Tested: " "$_now" >> "${_curltest8}" -curl http://localhost:9000/index.php -e http://bing.com 2>&1 >> ${_curltest8} -if grep -i 'Welcome' ${_curltest8}; then +if curl http://localhost:9000/index.php -e http://bing.com 2>&1 | grep -i 'Welcome'; then echo "$(tput setaf 2)GOOD REFERRER DETECTED - TEST PASSED" else echo "$(tput setaf 1)GOOD REFERRER NOT DETECTED - TEST FAILED" @@ -173,11 +149,8 @@ run_curltest8 # ************************************************** run_curltest9 () { -truncate -s 0 ${_curltest9} printf '\n%s\n%s\n%s\n\n' "#########################" "TESTING BAD BOT IS DENIED" "#########################" -printf '%s%s\n\n' "Last Tested: " "$_now" >> "${_curltest9}" -curl -A "Googlebot/Nutch-1.7" http://localhost:9000/index.php 2>> ${_curltest9} -if grep -i '(52)' ${_curltest9}; then +if curl -A "Googlebot/Nutch-1.7" http://localhost:9000/index.php 2 | grep -i '(52)'; then echo "$(tput setaf 2)BAD BOT DETECTED - TEST PASSED" else echo "$(tput setaf 1)BAD BOT NOT DETECTED - TEST FAILED" @@ -192,7 +165,7 @@ run_curltest9 run_curltest10 () { printf '\n%s\n%s\n%s\n\n' "#########################" "TESTING BAD BOT IS DENIED" "#########################" -if curl -A "Mozilla/5.0 (compatible; Googlebot/Nutch2.1; +http://www.google.com/bot.html)" http://localhost:9000/index.php 2 | grep -i '(52)' ${_curltest10}; then +if curl -A "Mozilla/5.0 (compatible; Googlebot/Nutch2.1; +http://www.google.com/bot.html)" http://localhost:9000/index.php 2 | grep -i '(52)'; then echo "$(tput setaf 2)BAD BOT DETECTED - TEST PASSED" else echo "$(tput setaf 1)BAD BOT NOT DETECTED - TEST FAILED" @@ -207,7 +180,7 @@ run_curltest10 run_curltest11 () { printf '\n%s\n%s\n%s\n\n' "#########################" "TESTING BAD BOT IS DENIED" "#########################" -if curl -A "Mozilla/5.0 (compatible; Googlebot/nutch/-2.1; +http://www.google.com/bot.html)" http://localhost:9000/index.php 2 | grep -i '(52)' ${_curltest11}; then +if curl -A "Mozilla/5.0 (compatible; Googlebot/nutch/-2.1; +http://www.google.com/bot.html)" http://localhost:9000/index.php 2 | grep -i '(52)'; then echo "$(tput setaf 2)BAD BOT DETECTED - TEST PASSED" else echo "$(tput setaf 1)BAD BOT NOT DETECTED - TEST FAILED" @@ -222,7 +195,7 @@ run_curltest11 run_curltest12 () { printf '\n%s\n%s\n%s\n\n' "############################" "TESTING FALSE POSITIVE CASES" "############################" -if curl -v -A "Mozilla/5.0 (compatible; Googlebot-Image/Snutch\-/-2.1; +http://www.google.com/bot.html)" http://localhost:9000/index.php 2>&1 | grep -i 'Welcome' ${_curltest12}; then +if curl -v -A "Mozilla/5.0 (compatible; Googlebot-Image/Snutch\-/-2.1; +http://www.google.com/bot.html)" http://localhost:9000/index.php 2>&1 | grep -i 'Welcome'; then echo "$(tput setaf 2)NO FALSE POSITIVE - TEST PASSED" else echo "$(tput setaf 1)FALSE POSITIVE - TEST FAILED" @@ -236,7 +209,7 @@ run_curltest12 run_curltest13 () { printf '\n%s\n%s\n%s\n\n' "############################" "TESTING FALSE POSITIVE CASES" "############################" -if curl -v -A "SnutchMozilla/5.0 (compatible; Googlebot-Image/SMutch\-/-2.1; +http://www.google.com/bot.html)" http://localhost:9000/index.php 2>&1 | grep -i 'Welcome' ${_curltest13}; then +if curl -v -A "SnutchMozilla/5.0 (compatible; Googlebot-Image/SMutch\-/-2.1; +http://www.google.com/bot.html)" http://localhost:9000/index.php 2>&1 | grep -i 'Welcome'; then echo "$(tput setaf 2)NO FALSE POSITIVE - TEST PASSED" else echo "$(tput setaf 1)FALSE POSITIVE - TEST FAILED" @@ -250,7 +223,7 @@ run_curltest13 run_curltest14 () { printf '\n%s\n%s\n%s\n\n' "############################" "TESTING FALSE POSITIVE CASES" "############################" -if curl -v -A "Mozilla/5.0 (X11; Linux x86_64; rv:67.0) Gecko/20100101 Firefox/67.0" http://localhost:9000/index.php 2>&1 | grep -i 'Welcome' ${_curltest14}; then +if curl -v -A "Mozilla/5.0 (X11; Linux x86_64; rv:67.0) Gecko/20100101 Firefox/67.0" http://localhost:9000/index.php 2>&1 | grep -i 'Welcome'; then echo "$(tput setaf 2)NO FALSE POSITIVE - TEST PASSED" else echo "$(tput setaf 1)FALSE POSITIVE - TEST FAILED"