From 21b0e6d915037cffd8d6b1e1c9caecea00635f66 Mon Sep 17 00:00:00 2001 From: Mitchell Krog Date: Wed, 26 Jun 2019 11:17:28 +0200 Subject: [PATCH] FINALIZE Rate Limiting Test Closes: #175 --- .dev-tools/generate-files.sh | 1 + .dev-tools/test-blocker-rate-limiting.sh | 101 +++++++++++++++++++++++ .dev-tools/test-blocker-whitelist.sh | 62 -------------- .travis.yml | 1 + 4 files changed, 103 insertions(+), 62 deletions(-) create mode 100644 .dev-tools/test-blocker-rate-limiting.sh diff --git a/.dev-tools/generate-files.sh b/.dev-tools/generate-files.sh index 78b07dca1..9feadf917 100755 --- a/.dev-tools/generate-files.sh +++ b/.dev-tools/generate-files.sh @@ -60,6 +60,7 @@ sudo chmod +x ${TRAVIS_BUILD_DIR}/.dev-tools/test-blocker-badwords.sh sudo chmod +x ${TRAVIS_BUILD_DIR}/.dev-tools/test-blocker-whitelist-domains.sh sudo chmod +x ${TRAVIS_BUILD_DIR}/.dev-tools/test-blocker-whitelist-ips.sh sudo chmod +x ${TRAVIS_BUILD_DIR}/.dev-tools/test-blocker-blacklist-domains.sh +sudo chmod +x ${TRAVIS_BUILD_DIR}/.dev-tools/test-blocker-rate-limiting.sh sudo chmod +x ${TRAVIS_BUILD_DIR}/.dev-tools/test-blocker-whitelist.sh sudo chmod +x ${TRAVIS_BUILD_DIR}/.dev-tools/prepare-robots-input.sh sudo chmod +x ${TRAVIS_BUILD_DIR}/.dev-tools/install-nginx-1.sh diff --git a/.dev-tools/test-blocker-rate-limiting.sh b/.dev-tools/test-blocker-rate-limiting.sh new file mode 100644 index 000000000..a531d816c --- /dev/null +++ b/.dev-tools/test-blocker-rate-limiting.sh @@ -0,0 +1,101 @@ +#!/bin/bash +# Curl Testing Script for Nginx Ultimate Bad Bot Blocker +# Created by: Mitchell Krog (mitchellkrog@gmail.com) +# Copyright: Mitchell Krog - https://github.com/mitchellkrogza +# Repo Url: https://github.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker + +############################################################################## +# _ __ _ # +# / |/ /__ _(_)__ __ __ # +# / / _ `/ / _ \\ \ / # +# /_/|_/\_, /_/_//_/_\_\ # +# __/___/ __ ___ __ ___ __ __ # +# / _ )___ ____/ / / _ )___ / /_ / _ )/ /__ ____/ /_____ ____ # +# / _ / _ `/ _ / / _ / _ \/ __/ / _ / / _ \/ __/ '_/ -_) __/ # +# /____/\_,_/\_,_/ /____/\___/\__/ /____/_/\___/\__/_/\_\\__/_/ # +# # +############################################################################## + +# ************************ +# Set Terminal Font Colors +# ************************ + +bold=$(tput bold) +red=$(tput setaf 1) +green=$(tput setaf 2) +yellow=$(tput setaf 3) +blue=$(tput setaf 4) +magenta=$(tput setaf 5) +cyan=$(tput setaf 6) +white=$(tput setaf 7) +defaultcolor=$(tput setaf default) + +# ****************** +# TEST RATE LIMITING +# ****************** + +printf "\n" +echo "${bold}${green}---------------------------" +echo "${bold}${green}Starting Rate Limiting Test" +echo "${bold}${green}---------------------------" +printf "\n\n" + +# *************************** +# Make GoogleBot Rate Limited +# *************************** + +echo "${bold}${yellow}-----------------------------" +echo "${bold}${yellow}Making GoogleBot ${yellow}RATE LIMITED" +echo "${bold}${yellow}-----------------------------" +printf "\n\n" +sudo cp ${TRAVIS_BUILD_DIR}/.dev-tools/test_units/rate-limiting-user-agents.conf /etc/nginx/bots.d/blacklist-user-agents.conf + +echo "${bold}${green}---------------" +echo "${bold}${green}Reloading Nginx" +echo "${bold}${green}---------------" +printf "\n\n" +sudo nginx -t && sudo nginx -s reload + +echo "${bold}${yellow}-----------------------------------------------------------------------" +echo "${bold}${yellow}Sleeping for 10 seconds to allow Nginx to Properly Reload inside Travis" +echo "${bold}${yellow}-----------------------------------------------------------------------" +printf "\n\n" +sleep 10s + +ratelimittestfile=${TRAVIS_BUILD_DIR}/.dev-tools/test_units/ratelimittest.txt +truncate -s 0 ${ratelimittestfile} +curl -A "GoogleBot" http://localhost:9000 2>&1 > ${ratelimittestfile} & +curl -A "GoogleBot" http://localhost:9000 2>&1 >> ${ratelimittestfile} & +curl -A "GoogleBot" http://localhost:9000 2>&1 >> ${ratelimittestfile} & +curl -A "GoogleBot" http://localhost:9000 2>&1 >> ${ratelimittestfile} & +curl -A "GoogleBot" http://localhost:9000 2>&1 >> ${ratelimittestfile} & +curl -A "GoogleBot" http://localhost:9000 2>&1 >> ${ratelimittestfile} & +curl -A "GoogleBot" http://localhost:9000 2>&1 >> ${ratelimittestfile} & +curl -A "GoogleBot" http://localhost:9000 2>&1 >> ${ratelimittestfile} & +curl -A "GoogleBot" http://localhost:9000 2>&1 >> ${ratelimittestfile} & +curl -A "GoogleBot" http://localhost:9000 2>&1 >> ${ratelimittestfile} & +curl -A "GoogleBot" http://localhost:9000 2>&1 >> ${ratelimittestfile} & +curl -A "GoogleBot" http://localhost:9000 2>&1 >> ${ratelimittestfile} & +curl -A "GoogleBot" http://localhost:9000 2>&1 >> ${ratelimittestfile} & +curl -A "GoogleBot" http://localhost:9000 2>&1 >> ${ratelimittestfile} & +curl -A "GoogleBot" http://localhost:9000 2>&1 >> ${ratelimittestfile} + +if grep -i 'Unavailable' < ${ratelimittestfile}; then + echo "${bold}${green}PASSED - ${red}GoogleBot was ${bold}${red}RATE LIMITED" + else + echo "${bold}${red}FAILED - ${red}GoogleBot was ${bold}${red}NOT RATE LIMITED" + fi + +printf "\n" +echo "${bold}${green}---------------------------" +echo "${bold}${green}Rate Limiting Test Complete" +echo "${bold}${green}---------------------------" +printf "\n\n" + +# ********************** +# Exit With Error Number +# ********************** + +exit ${?} + + diff --git a/.dev-tools/test-blocker-whitelist.sh b/.dev-tools/test-blocker-whitelist.sh index c930cb3c1..b32c0177d 100755 --- a/.dev-tools/test-blocker-whitelist.sh +++ b/.dev-tools/test-blocker-whitelist.sh @@ -229,68 +229,6 @@ echo "${bold}${green}Whitelisting Test Complete" echo "${bold}${green}--------------------------" printf "\n\n" -# ****************** -# TEST RATE LIMITING -# ****************** - -printf "\n" -echo "${bold}${green}---------------------------" -echo "${bold}${green}Starting Rate Limiting Test" -echo "${bold}${green}---------------------------" -printf "\n\n" - -# *************************** -# Make GoogleBot Rate Limited -# *************************** - -echo "${bold}${yellow}-----------------------------" -echo "${bold}${yellow}Making GoogleBot ${yellow}RATE LIMITED" -echo "${bold}${yellow}-----------------------------" -printf "\n\n" -sudo cp ${TRAVIS_BUILD_DIR}/.dev-tools/test_units/rate-limiting-user-agents.conf /etc/nginx/bots.d/blacklist-user-agents.conf - -echo "${bold}${green}---------------" -echo "${bold}${green}Reloading Nginx" -echo "${bold}${green}---------------" -printf "\n\n" -sudo nginx -t && sudo nginx -s reload - -echo "${bold}${yellow}-----------------------------------------------------------------------" -echo "${bold}${yellow}Sleeping for 30 seconds to allow Nginx to Properly Reload inside Travis" -echo "${bold}${yellow}-----------------------------------------------------------------------" -printf "\n\n" -sleep 10s - -ratelimittestfile=${TRAVIS_BUILD_DIR}/.dev-tools/test_units/ratelimittest.txt -truncate -s 0 ${ratelimittestfile} -curl -A "GoogleBot" http://localhost:9000 2>&1 > ${ratelimittestfile} & -curl -A "GoogleBot" http://localhost:9000 2>&1 >> ${ratelimittestfile} & -curl -A "GoogleBot" http://localhost:9000 2>&1 >> ${ratelimittestfile} & -curl -A "GoogleBot" http://localhost:9000 2>&1 >> ${ratelimittestfile} & -curl -A "GoogleBot" http://localhost:9000 2>&1 >> ${ratelimittestfile} & -curl -A "GoogleBot" http://localhost:9000 2>&1 >> ${ratelimittestfile} & -curl -A "GoogleBot" http://localhost:9000 2>&1 >> ${ratelimittestfile} & -curl -A "GoogleBot" http://localhost:9000 2>&1 >> ${ratelimittestfile} & -curl -A "GoogleBot" http://localhost:9000 2>&1 >> ${ratelimittestfile} & -curl -A "GoogleBot" http://localhost:9000 2>&1 >> ${ratelimittestfile} & -curl -A "GoogleBot" http://localhost:9000 2>&1 >> ${ratelimittestfile} & -curl -A "GoogleBot" http://localhost:9000 2>&1 >> ${ratelimittestfile} & -curl -A "GoogleBot" http://localhost:9000 2>&1 >> ${ratelimittestfile} & -curl -A "GoogleBot" http://localhost:9000 2>&1 >> ${ratelimittestfile} & -curl -A "GoogleBot" http://localhost:9000 2>&1 >> ${ratelimittestfile} - -if grep -i 'Unavailable' < ${ratelimittestfile}; then - echo "${bold}${green}PASSED - ${red}GoogleBot was ${bold}${red}RATE LIMITED" - else - echo "${bold}${red}FAILED - ${red}GoogleBot was ${bold}${red}NOT RATE LIMITED" - fi - -printf "\n" -echo "${bold}${green}---------------------------" -echo "${bold}${green}Rate Limiting Test Complete" -echo "${bold}${green}---------------------------" -printf "\n\n" - # ******************* # RELEASE NEW VERSION # ******************* diff --git a/.travis.yml b/.travis.yml index 80b39a777..13e8b3bb7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -51,6 +51,7 @@ script: - bash .dev-tools/test-blocker-badwords.sh - bash .dev-tools/test-blocker-whitelist-domains.sh - bash .dev-tools/test-blocker-whitelist-ips.sh + - bash .dev-tools/test-blocker-rate-limiting.sh - bash .dev-tools/test-blocker-whitelist.sh - bash .dev-tools/modify-files-and-commit.sh