mirror of
https://github.com/bunkerity/bunkerized-nginx
synced 2023-12-13 21:30:18 +01:00
Add country linux tests
This commit is contained in:
parent
cff5c77679
commit
a29ac80e4b
|
@ -41,7 +41,14 @@ try:
|
||||||
|
|
||||||
status_code = get(
|
status_code = get(
|
||||||
f"http://www.example.com",
|
f"http://www.example.com",
|
||||||
headers={"Host": "www.example.com"},
|
headers={
|
||||||
|
"Host": "www.example.com",
|
||||||
|
}
|
||||||
|
| (
|
||||||
|
{"X-Forwarded-For": "2.0.0.3" if country == "FR" else "8.0.0.3"}
|
||||||
|
if getenv("TEST_TYPE", "docker") == "linux"
|
||||||
|
else {}
|
||||||
|
),
|
||||||
).status_code
|
).status_code
|
||||||
|
|
||||||
if status_code == 403:
|
if status_code == 403:
|
||||||
|
|
|
@ -1,17 +1,39 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
echo "🌍 Building country stack ..."
|
integration=$1
|
||||||
|
|
||||||
# Starting stack
|
if [ -z "$integration" ] ; then
|
||||||
docker compose pull bw-docker
|
echo "🌍 Please provide an integration name as argument ❌"
|
||||||
if [ $? -ne 0 ] ; then
|
exit 1
|
||||||
echo "🌍 Pull failed ❌"
|
elif [ "$integration" != "docker" ] && [ "$integration" != "linux" ] ; then
|
||||||
|
echo "🌍 Integration \"$integration\" is not supported ❌"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
docker compose -f docker-compose.test.yml build
|
|
||||||
if [ $? -ne 0 ] ; then
|
echo "🌍 Building country stack for integration \"$integration\" ..."
|
||||||
|
|
||||||
|
# Starting stack
|
||||||
|
if [ "$integration" = "docker" ] ; then
|
||||||
|
docker compose pull bw-docker
|
||||||
|
if [ $? -ne 0 ] ; then
|
||||||
|
echo "🌍 Pull failed ❌"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
docker compose -f docker-compose.test.yml build
|
||||||
|
if [ $? -ne 0 ] ; then
|
||||||
echo "🌍 Build failed ❌"
|
echo "🌍 Build failed ❌"
|
||||||
exit 1
|
exit 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
sudo systemctl stop bunkerweb
|
||||||
|
echo "USE_REAL_IP=yes" | sudo tee -a /etc/bunkerweb/variables.env
|
||||||
|
echo "REAL_IP_FROM=127.0.0.0/24" | sudo tee -a /etc/bunkerweb/variables.env
|
||||||
|
|
||||||
|
echo "BLACKLIST_COUNTRY=" | sudo tee -a /etc/bunkerweb/variables.env
|
||||||
|
echo "WHITELIST_COUNTRY=" | sudo tee -a /etc/bunkerweb/variables.env
|
||||||
|
sudo touch /var/www/html/index.html
|
||||||
|
export COUNTRY=""
|
||||||
|
export TEST_TYPE="linux"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
manual=0
|
manual=0
|
||||||
|
@ -19,8 +41,15 @@ end=0
|
||||||
cleanup_stack () {
|
cleanup_stack () {
|
||||||
exit_code=$?
|
exit_code=$?
|
||||||
if [[ $end -eq 1 || $exit_code = 1 ]] || [[ $end -eq 0 && $exit_code = 0 ]] && [ $manual = 0 ] ; then
|
if [[ $end -eq 1 || $exit_code = 1 ]] || [[ $end -eq 0 && $exit_code = 0 ]] && [ $manual = 0 ] ; then
|
||||||
|
if [ "$integration" = "docker" ] ; then
|
||||||
find . -type f -name 'docker-compose.*' -exec sed -i 's@BLACKLIST_COUNTRY: "US"@BLACKLIST_COUNTRY: ""@' {} \;
|
find . -type f -name 'docker-compose.*' -exec sed -i 's@BLACKLIST_COUNTRY: "US"@BLACKLIST_COUNTRY: ""@' {} \;
|
||||||
find . -type f -name 'docker-compose.*' -exec sed -i 's@WHITELIST_COUNTRY: "FR"@WHITELIST_COUNTRY: ""@' {} \;
|
find . -type f -name 'docker-compose.*' -exec sed -i 's@WHITELIST_COUNTRY: "FR"@WHITELIST_COUNTRY: ""@' {} \;
|
||||||
|
else
|
||||||
|
sudo sed -i 's@BLACKLIST_COUNTRY=.*$@BLACKLIST_COUNTRY=@' /etc/bunkerweb/variables.env
|
||||||
|
sudo sed -i 's@WHITELIST_COUNTRY=.*$@WHITELIST_COUNTRY=@' /etc/bunkerweb/variables.env
|
||||||
|
unset BLACKLIST_COUNTRY
|
||||||
|
unset WHITELIST_COUNTRY
|
||||||
|
fi
|
||||||
if [[ $end -eq 1 && $exit_code = 0 ]] ; then
|
if [[ $end -eq 1 && $exit_code = 0 ]] ; then
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
@ -28,10 +57,15 @@ cleanup_stack () {
|
||||||
|
|
||||||
echo "🌍 Cleaning up current stack ..."
|
echo "🌍 Cleaning up current stack ..."
|
||||||
|
|
||||||
|
if [ "$integration" == "docker" ] ; then
|
||||||
docker compose down -v --remove-orphans
|
docker compose down -v --remove-orphans
|
||||||
|
else
|
||||||
|
sudo systemctl stop bunkerweb
|
||||||
|
sudo truncate -s 0 /var/log/bunkerweb/error.log
|
||||||
|
fi
|
||||||
|
|
||||||
if [ $? -ne 0 ] ; then
|
if [ $? -ne 0 ] ; then
|
||||||
echo "🌍 Down failed ❌"
|
echo "🌍 Cleanup failed ❌"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -47,14 +81,27 @@ do
|
||||||
echo "🌍 Running tests without the country plugin ..."
|
echo "🌍 Running tests without the country plugin ..."
|
||||||
elif [ "$test" = "blacklist" ] ; then
|
elif [ "$test" = "blacklist" ] ; then
|
||||||
echo "🌍 Running tests when blacklisting United States ..."
|
echo "🌍 Running tests when blacklisting United States ..."
|
||||||
|
if [ "$integration" == "docker" ] ; then
|
||||||
find . -type f -name 'docker-compose.*' -exec sed -i 's@BLACKLIST_COUNTRY: ""@BLACKLIST_COUNTRY: "US"@' {} \;
|
find . -type f -name 'docker-compose.*' -exec sed -i 's@BLACKLIST_COUNTRY: ""@BLACKLIST_COUNTRY: "US"@' {} \;
|
||||||
|
else
|
||||||
|
sudo sed -i 's@BLACKLIST_COUNTRY=.*$@BLACKLIST_COUNTRY=US@' /etc/bunkerweb/variables.env
|
||||||
|
export BLACKLIST_COUNTRY="US"
|
||||||
|
fi
|
||||||
elif [ "$test" = "whitelist" ] ; then
|
elif [ "$test" = "whitelist" ] ; then
|
||||||
echo "🌍 Running tests when whitelisting France ..."
|
echo "🌍 Running tests when whitelisting France ..."
|
||||||
|
if [ "$integration" == "docker" ] ; then
|
||||||
find . -type f -name 'docker-compose.*' -exec sed -i 's@BLACKLIST_COUNTRY: "US"@BLACKLIST_COUNTRY: ""@' {} \;
|
find . -type f -name 'docker-compose.*' -exec sed -i 's@BLACKLIST_COUNTRY: "US"@BLACKLIST_COUNTRY: ""@' {} \;
|
||||||
find . -type f -name 'docker-compose.*' -exec sed -i 's@WHITELIST_COUNTRY: ""@WHITELIST_COUNTRY: "FR"@' {} \;
|
find . -type f -name 'docker-compose.*' -exec sed -i 's@WHITELIST_COUNTRY: ""@WHITELIST_COUNTRY: "FR"@' {} \;
|
||||||
|
else
|
||||||
|
sudo sed -i 's@BLACKLIST_COUNTRY=.*$@BLACKLIST_COUNTRY=@' /etc/bunkerweb/variables.env
|
||||||
|
sudo sed -i 's@WHITELIST_COUNTRY=.*$@WHITELIST_COUNTRY=FR@' /etc/bunkerweb/variables.env
|
||||||
|
unset BLACKLIST_COUNTRY
|
||||||
|
export WHITELIST_COUNTRY="FR"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "🌍 Starting stack ..."
|
echo "🌍 Starting stack ..."
|
||||||
|
if [ "$integration" == "docker" ] ; then
|
||||||
docker compose up -d
|
docker compose up -d
|
||||||
if [ $? -ne 0 ] ; then
|
if [ $? -ne 0 ] ; then
|
||||||
echo "🌍 Up failed, retrying ... ⚠️"
|
echo "🌍 Up failed, retrying ... ⚠️"
|
||||||
|
@ -67,10 +114,18 @@ do
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
|
sudo systemctl start bunkerweb
|
||||||
|
if [ $? -ne 0 ] ; then
|
||||||
|
echo "🌍 Start failed ❌"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# Check if stack is healthy
|
# Check if stack is healthy
|
||||||
echo "🌍 Waiting for stack to be healthy ..."
|
echo "🌍 Waiting for stack to be healthy ..."
|
||||||
i=0
|
i=0
|
||||||
|
if [ "$integration" == "docker" ] ; then
|
||||||
while [ $i -lt 120 ] ; do
|
while [ $i -lt 120 ] ; do
|
||||||
containers=("country-bw-1" "country-bw-scheduler-1")
|
containers=("country-bw-1" "country-bw-scheduler-1")
|
||||||
healthy="true"
|
healthy="true"
|
||||||
|
@ -93,31 +148,81 @@ do
|
||||||
echo "🌍 Docker stack is not healthy ❌"
|
echo "🌍 Docker stack is not healthy ❌"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
|
while [ $i -lt 120 ] ; do
|
||||||
|
check="$(sudo cat /var/log/bunkerweb/error.log | grep "BunkerWeb is ready")"
|
||||||
|
if ! [ -z "$check" ] ; then
|
||||||
|
echo "🌍 Linux stack is healthy ✅"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
sleep 1
|
||||||
|
i=$((i+1))
|
||||||
|
done
|
||||||
|
if [ $i -ge 120 ] ; then
|
||||||
|
sudo journalctl -u bunkerweb --no-pager
|
||||||
|
echo "🛡️ Showing BunkerWeb error logs ..."
|
||||||
|
sudo cat /var/log/bunkerweb/error.log
|
||||||
|
echo "🛡️ Showing BunkerWeb access logs ..."
|
||||||
|
sudo cat /var/log/bunkerweb/access.log
|
||||||
|
echo "🌍 Linux stack is not healthy ❌"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# Start tests
|
# Start tests
|
||||||
|
|
||||||
echo "🌍 Starting the FR container"
|
echo "🌍 Starting the FR country"
|
||||||
|
if [ "$integration" == "docker" ] ; then
|
||||||
docker compose -f docker-compose.test.yml up tests-fr --abort-on-container-exit --exit-code-from tests-fr
|
docker compose -f docker-compose.test.yml up tests-fr --abort-on-container-exit --exit-code-from tests-fr
|
||||||
|
|
||||||
if [ $? -ne 0 ] ; then
|
|
||||||
echo "🌍 Test \"$test\" failed for the FR container ❌"
|
|
||||||
echo "🛡️ Showing BunkerWeb and BunkerWeb Scheduler logs ..."
|
|
||||||
docker compose logs bw bw-scheduler
|
|
||||||
exit 1
|
|
||||||
else
|
else
|
||||||
echo "🌍 Test \"$test\" succeeded for the FR container ✅"
|
export COUNTRY="FR"
|
||||||
|
python3 main.py
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "🌍 Starting the US container"
|
|
||||||
docker compose -f docker-compose.test.yml up tests-us --abort-on-container-exit --exit-code-from tests-us
|
|
||||||
|
|
||||||
if [ $? -ne 0 ] ; then
|
if [ $? -ne 0 ] ; then
|
||||||
echo "🌍 Test \"$test\" failed for the US container ❌"
|
echo "🌍 Test \"$test\" failed for the FR country ❌"
|
||||||
echo "🛡️ Showing BunkerWeb and BunkerWeb Scheduler logs ..."
|
echo "🛡️ Showing BunkerWeb and BunkerWeb Scheduler logs ..."
|
||||||
|
if [ "$integration" == "docker" ] ; then
|
||||||
docker compose logs bw bw-scheduler
|
docker compose logs bw bw-scheduler
|
||||||
|
else
|
||||||
|
sudo journalctl -u bunkerweb --no-pager
|
||||||
|
echo "🛡️ Showing BunkerWeb error logs ..."
|
||||||
|
sudo cat /var/log/bunkerweb/error.log
|
||||||
|
echo "🛡️ Showing BunkerWeb access logs ..."
|
||||||
|
sudo cat /var/log/bunkerweb/access.log
|
||||||
|
echo "🛡️ Showing Geckodriver logs ..."
|
||||||
|
sudo cat geckodriver.log
|
||||||
|
fi
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
echo "🌍 Test \"$test\" succeeded for the US container ✅"
|
echo "🌍 Test \"$test\" succeeded for the FR country ✅"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "🌍 Starting the US country"
|
||||||
|
if [ "$integration" == "docker" ] ; then
|
||||||
|
docker compose -f docker-compose.test.yml up tests-us --abort-on-container-exit --exit-code-from tests-us
|
||||||
|
else
|
||||||
|
export COUNTRY="US"
|
||||||
|
python3 main.py
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $? -ne 0 ] ; then
|
||||||
|
echo "🌍 Test \"$test\" failed for the US country ❌"
|
||||||
|
echo "🛡️ Showing BunkerWeb and BunkerWeb Scheduler logs ..."
|
||||||
|
if [ "$integration" == "docker" ] ; then
|
||||||
|
docker compose logs bw bw-scheduler
|
||||||
|
else
|
||||||
|
sudo journalctl -u bunkerweb --no-pager
|
||||||
|
echo "🛡️ Showing BunkerWeb error logs ..."
|
||||||
|
sudo cat /var/log/bunkerweb/error.log
|
||||||
|
echo "🛡️ Showing BunkerWeb access logs ..."
|
||||||
|
sudo cat /var/log/bunkerweb/access.log
|
||||||
|
echo "🛡️ Showing Geckodriver logs ..."
|
||||||
|
sudo cat geckodriver.log
|
||||||
|
fi
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo "🌍 Test \"$test\" succeeded for the US country ✅"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
manual=1
|
manual=1
|
||||||
|
|
Loading…
Reference in a new issue