Added linux tests to a few core plugins

This commit is contained in:
Théophile Diot 2023-09-19 17:53:07 +02:00
parent 0ece8fda00
commit 8a6e14d8c8
No known key found for this signature in database
GPG key ID: 248FEA4BAE400D06
13 changed files with 1316 additions and 482 deletions

View file

@ -26,7 +26,7 @@ jobs:
run: |
sudo apt purge -y firefox
sudo apt update
sudo apt install --no-install-recommends -y nodejs tar bzip2 wget curl grep libx11-xcb1 libappindicator3-1 libasound2 libdbus-glib-1-2 libxtst6 libxt6
sudo apt install --no-install-recommends -y git nodejs tar bzip2 wget curl grep libx11-xcb1 libappindicator3-1 libasound2 libdbus-glib-1-2 libxtst6 libxt6 php-fpm unzip
wget -O firefox-setup.tar.bz2 "https://download.mozilla.org/?product=firefox-latest-ssl&os=linux64"
tar -xjf firefox-setup.tar.bz2 -C /opt/
sudo ln -s /opt/firefox/firefox /usr/bin/firefox
@ -71,7 +71,13 @@ jobs:
run: sudo apt install -fy /tmp/bunkerweb.deb
- name: Edit configuration files
run: |
# Misc
echo "127.0.0.1 www.example.com" | sudo tee -a /etc/hosts
echo "127.0.0.1 bwadm.example.com" | sudo tee -a /etc/hosts
sudo cp ./tests/www-deb.conf /etc/php/8.1/fpm/pool.d/www.conf
sudo systemctl stop php8.1-fpm
sudo systemctl start php8.1-fpm
# BunkerWeb
echo "SERVER_NAME=www.example.com" | sudo tee /etc/bunkerweb/variables.env
echo "HTTP_PORT=80" | sudo tee -a /etc/bunkerweb/variables.env
echo "HTTPS_PORT=443" | sudo tee -a /etc/bunkerweb/variables.env

View file

@ -60,7 +60,7 @@ cleanup_stack () {
fi
if [ $? -ne 0 ] ; then
echo "🤖 cleanup failed ❌"
echo "🤖 Cleanup failed ❌"
exit 1
fi
@ -116,8 +116,8 @@ do
# Check if stack is healthy
echo "🤖 Waiting for stack to be healthy ..."
i=0
if [ "$integration" == "docker" ] ; then
i=0
while [ $i -lt 120 ] ; do
containers=("antibot-bw-1" "antibot-bw-scheduler-1")
healthy="true"
@ -141,7 +141,6 @@ do
exit 1
fi
else
i=0
while [ $i -lt 120 ] ; do
check="$(sudo cat /var/log/bunkerweb/error.log | grep "BunkerWeb is ready")"
if ! [ -z "$check" ] ; then

View file

@ -1,17 +1,36 @@
#!/bin/bash
echo "🔐 Building authbasic stack ..."
integration=$1
# Starting stack
docker compose pull bw-docker app1
if [ $? -ne 0 ] ; then
echo "🔐 Pull failed ❌"
if [ -z "$integration" ] ; then
echo "🔐 Please provide an integration name as argument ❌"
exit 1
elif [ "$integration" != "docker" ] && [ "$integration" != "linux" ] ; then
echo "🔐 Integration \"$integration\" is not supported ❌"
exit 1
fi
docker compose -f docker-compose.test.yml build
if [ $? -ne 0 ] ; then
echo "🔐 Build failed ❌"
exit 1
echo "🔐 Building authbasic stack for integration \"$integration\" ..."
# Starting stack
if [ "$integration" = "docker" ] ; then
docker compose pull bw-docker app1
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 ❌"
exit 1
fi
else
sudo systemctl stop bunkerweb
echo "USE_AUTH_BASIC=no" | sudo tee -a /etc/bunkerweb/variables.env
echo "AUTH_BASIC_LOCATION=sitewide" | sudo tee -a /etc/bunkerweb/variables.env
echo "AUTH_BASIC_USER=bunkerity" | sudo tee -a /etc/bunkerweb/variables.env
echo "AUTH_BASIC_PASSWORD=Secr3tP@ssw0rd" | sudo tee -a /etc/bunkerweb/variables.env
sudo touch /var/www/html/index.html
fi
manual=0
@ -19,10 +38,21 @@ end=0
cleanup_stack () {
exit_code=$?
if [[ $end -eq 1 || $exit_code = 1 ]] || [[ $end -eq 0 && $exit_code = 0 ]] && [ $manual = 0 ] ; then
find . -type f -name 'docker-compose.*' -exec sed -i 's@USE_AUTH_BASIC: "yes"@USE_AUTH_BASIC: "no"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@AUTH_BASIC_LOCATION: "/auth"@AUTH_BASIC_LOCATION: "sitewide"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@AUTH_BASIC_USER: "admin"@AUTH_BASIC_USER: "bunkerity"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@AUTH_BASIC_PASSWORD: "password"@AUTH_BASIC_PASSWORD: "Secr3tP\@ssw0rd"@' {} \;
if [ "$integration" == "docker" ] ; then
find . -type f -name 'docker-compose.*' -exec sed -i 's@USE_AUTH_BASIC: "yes"@USE_AUTH_BASIC: "no"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@AUTH_BASIC_LOCATION: "/auth"@AUTH_BASIC_LOCATION: "sitewide"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@AUTH_BASIC_USER: "admin"@AUTH_BASIC_USER: "bunkerity"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@AUTH_BASIC_PASSWORD: "password"@AUTH_BASIC_PASSWORD: "Secr3tP\@ssw0rd"@' {} \;
else
sudo sed -i 's@USE_AUTH_BASIC=.*$@USE_AUTH_BASIC=no@' /etc/bunkerweb/variables.env
sudo sed -i 's@AUTH_BASIC_LOCATION=.*$@AUTH_BASIC_LOCATION=sitewide@' /etc/bunkerweb/variables.env
sudo sed -i 's@AUTH_BASIC_USER=.*$@AUTH_BASIC_USER=bunkerity@' /etc/bunkerweb/variables.env
sudo sed -i 's@AUTH_BASIC_PASSWORD=.*$@AUTH_BASIC_PASSWORD=Secr3tP@ssw0rd@' /etc/bunkerweb/variables.env
unset USE_AUTH_BASIC
unset AUTH_BASIC_LOCATION
unset AUTH_BASIC_USER
unset AUTH_BASIC_PASSWORD
fi
if [[ $end -eq 1 && $exit_code = 0 ]] ; then
return
fi
@ -30,10 +60,15 @@ cleanup_stack () {
echo "🔐 Cleaning up current stack ..."
docker compose down -v --remove-orphans
if [ "$integration" == "docker" ] ; then
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
echo "🔐 Down failed ❌"
echo "🔐 Cleanup failed ❌"
exit 1
fi
@ -49,27 +84,57 @@ do
echo "🔐 Running tests without authbasic ..."
elif [ "$test" = "sitewide" ] ; then
echo "🔐 Running tests with sitewide authbasic ..."
find . -type f -name 'docker-compose.*' -exec sed -i 's@USE_AUTH_BASIC: "no"@USE_AUTH_BASIC: "yes"@' {} \;
if [ "$integration" == "docker" ] ; then
find . -type f -name 'docker-compose.*' -exec sed -i 's@USE_AUTH_BASIC: "no"@USE_AUTH_BASIC: "yes"@' {} \;
else
sudo sed -i 's@USE_AUTH_BASIC=.*$@USE_AUTH_BASIC=yes@' /etc/bunkerweb/variables.env
export USE_AUTH_BASIC="yes"
fi
elif [ "$test" = "location" ] ; then
echo "🔐 Running tests with the location changed ..."
find . -type f -name 'docker-compose.*' -exec sed -i 's@AUTH_BASIC_LOCATION: "sitewide"@AUTH_BASIC_LOCATION: "/auth"@' {} \;
if [ "$integration" == "docker" ] ; then
find . -type f -name 'docker-compose.*' -exec sed -i 's@AUTH_BASIC_LOCATION: "sitewide"@AUTH_BASIC_LOCATION: "/auth"@' {} \;
else
sudo sed -i 's@AUTH_BASIC_LOCATION=.*$@AUTH_BASIC_LOCATION=/auth@' /etc/bunkerweb/variables.env
export AUTH_BASIC_LOCATION="/auth"
fi
elif [ "$test" = "user" ] ; then
echo "🔐 Running tests with the user changed ..."
find . -type f -name 'docker-compose.*' -exec sed -i 's@AUTH_BASIC_LOCATION: "/auth"@AUTH_BASIC_LOCATION: "sitewide"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@AUTH_BASIC_USER: "bunkerity"@AUTH_BASIC_USER: "admin"@' {} \;
if [ "$integration" == "docker" ] ; then
find . -type f -name 'docker-compose.*' -exec sed -i 's@AUTH_BASIC_LOCATION: "/auth"@AUTH_BASIC_LOCATION: "sitewide"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@AUTH_BASIC_USER: "bunkerity"@AUTH_BASIC_USER: "admin"@' {} \;
else
sudo sed -i 's@AUTH_BASIC_LOCATION=.*$@AUTH_BASIC_LOCATION=sitewide@' /etc/bunkerweb/variables.env
sudo sed -i 's@AUTH_BASIC_USER=.*$@AUTH_BASIC_USER=admin@' /etc/bunkerweb/variables.env
export AUTH_BASIC_LOCATION="sitewide"
export AUTH_BASIC_USER="admin"
fi
elif [ "$test" = "password" ] ; then
echo "🔐 Running tests with the password changed ..."
find . -type f -name 'docker-compose.*' -exec sed -i 's@AUTH_BASIC_PASSWORD: "Secr3tP\@ssw0rd"@AUTH_BASIC_PASSWORD: "password"@' {} \;
if [ "$integration" == "docker" ] ; then
find . -type f -name 'docker-compose.*' -exec sed -i 's@AUTH_BASIC_PASSWORD: "Secr3tP\@ssw0rd"@AUTH_BASIC_PASSWORD: "password"@' {} \;
else
sudo sed -i 's@AUTH_BASIC_PASSWORD=.*$@AUTH_BASIC_PASSWORD=password@' /etc/bunkerweb/variables.env
export AUTH_BASIC_PASSWORD="password"
fi
fi
echo "🔐 Starting stack ..."
docker compose up -d
if [ $? -ne 0 ] ; then
echo "🔐 Up failed, retrying ... ⚠️"
manual=1
cleanup_stack
manual=0
if [ "$integration" == "docker" ] ; then
docker compose up -d
if [ $? -ne 0 ] ; then
echo "🔐 Up failed, retrying ... ⚠️"
manual=1
cleanup_stack
manual=0
docker compose up -d
if [ $? -ne 0 ] ; then
echo "🔐 Up failed ❌"
exit 1
fi
fi
else
sudo systemctl start bunkerweb
if [ $? -ne 0 ] ; then
echo "🔐 Up failed ❌"
exit 1
@ -79,37 +144,72 @@ do
# Check if stack is healthy
echo "🔐 Waiting for stack to be healthy ..."
i=0
while [ $i -lt 120 ] ; do
containers=("authbasic-bw-1" "authbasic-bw-scheduler-1")
healthy="true"
for container in "${containers[@]}" ; do
check="$(docker inspect --format "{{json .State.Health }}" $container | grep "healthy")"
if [ "$check" = "" ] ; then
healthy="false"
if [ "$integration" == "docker" ] ; then
while [ $i -lt 120 ] ; do
containers=("authbasic-bw-1" "authbasic-bw-scheduler-1")
healthy="true"
for container in "${containers[@]}" ; do
check="$(docker inspect --format "{{json .State.Health }}" $container | grep "healthy")"
if [ "$check" = "" ] ; then
healthy="false"
break
fi
done
if [ "$healthy" = "true" ] ; then
echo "🔐 Docker stack is healthy ✅"
break
fi
sleep 1
i=$((i+1))
done
if [ "$healthy" = "true" ] ; then
echo "🔐 Docker stack is healthy ✅"
break
if [ $i -ge 120 ] ; then
docker compose logs
echo "🔐 Docker stack is not healthy ❌"
exit 1
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
sleep 1
i=$((i+1))
done
if [ $i -ge 120 ] ; then
docker compose logs
echo "🔐 Docker stack is not healthy ❌"
exit 1
fi
# Start tests
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests
if [ "$integration" == "docker" ] ; then
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests
else
python3 main.py
fi
if [ $? -ne 0 ] ; then
echo "🔐 Test \"$test\" failed ❌"
echo "🛡️ Showing BunkerWeb and BunkerWeb Scheduler logs ..."
docker compose logs bw bw-scheduler
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 ✅"

View file

@ -1,17 +1,37 @@
#!/bin/bash
echo "📟 Building badbehavior stack ..."
integration=$1
# Starting stack
docker compose pull bw-docker
if [ $? -ne 0 ] ; then
echo "📟 Pull failed ❌"
if [ -z "$integration" ] ; then
echo "📟 Please provide an integration name as argument ❌"
exit 1
elif [ "$integration" != "docker" ] && [ "$integration" != "linux" ] ; then
echo "📟 Integration \"$integration\" is not supported ❌"
exit 1
fi
docker compose -f docker-compose.test.yml build
if [ $? -ne 0 ] ; then
echo "📟 Build failed ❌"
exit 1
echo "📟 Building badbehavior 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 ❌"
exit 1
fi
else
sudo systemctl stop bunkerweb
echo "USE_BAD_BEHAVIOR=yes" | sudo tee -a /etc/bunkerweb/variables.env
echo "BAD_BEHAVIOR_STATUS_CODES=400 401 403 404 405 429 444" | sudo tee -a /etc/bunkerweb/variables.env
echo "BAD_BEHAVIOR_BAN_TIME=86400" | sudo tee -a /etc/bunkerweb/variables.env
echo "BAD_BEHAVIOR_THRESHOLD=10" | sudo tee -a /etc/bunkerweb/variables.env
echo "BAD_BEHAVIOR_COUNT_TIME=60" | sudo tee -a /etc/bunkerweb/variables.env
sudo touch /var/www/html/index.html
fi
manual=0
@ -19,11 +39,24 @@ end=0
cleanup_stack () {
exit_code=$?
if [[ $end -eq 1 || $exit_code = 1 ]] || [[ $end -eq 0 && $exit_code = 0 ]] && [ $manual = 0 ] ; then
find . -type f -name 'docker-compose.*' -exec sed -i 's@USE_BAD_BEHAVIOR: "no"@USE_BAD_BEHAVIOR: "yes"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@BAD_BEHAVIOR_STATUS_CODES: "400 401 404 405 429 444"@BAD_BEHAVIOR_STATUS_CODES: "400 401 403 404 405 429 444"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@BAD_BEHAVIOR_BAN_TIME: "60"@BAD_BEHAVIOR_BAN_TIME: "86400"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@BAD_BEHAVIOR_THRESHOLD: "20"@BAD_BEHAVIOR_THRESHOLD: "10"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@BAD_BEHAVIOR_COUNT_TIME: "30"@BAD_BEHAVIOR_COUNT_TIME: "60"@' {} \;
if [ "$integration" == "docker" ] ; then
find . -type f -name 'docker-compose.*' -exec sed -i 's@USE_BAD_BEHAVIOR: "no"@USE_BAD_BEHAVIOR: "yes"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@BAD_BEHAVIOR_STATUS_CODES: "400 401 404 405 429 444"@BAD_BEHAVIOR_STATUS_CODES: "400 401 403 404 405 429 444"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@BAD_BEHAVIOR_BAN_TIME: "60"@BAD_BEHAVIOR_BAN_TIME: "86400"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@BAD_BEHAVIOR_THRESHOLD: "20"@BAD_BEHAVIOR_THRESHOLD: "10"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@BAD_BEHAVIOR_COUNT_TIME: "30"@BAD_BEHAVIOR_COUNT_TIME: "60"@' {} \;
else
sudo sed -i 's@USE_BAD_BEHAVIOR=.*$@USE_BAD_BEHAVIOR=yes@' /etc/bunkerweb/variables.env
sudo sed -i 's@BAD_BEHAVIOR_STATUS_CODES=.*$@BAD_BEHAVIOR_STATUS_CODES=400 401 403 404 405 429 444@' /etc/bunkerweb/variables.env
sudo sed -i 's@BAD_BEHAVIOR_BAN_TIME=.*$@BAD_BEHAVIOR_BAN_TIME=86400@' /etc/bunkerweb/variables.env
sudo sed -i 's@BAD_BEHAVIOR_THRESHOLD=.*$@BAD_BEHAVIOR_THRESHOLD=10@' /etc/bunkerweb/variables.env
sudo sed -i 's@BAD_BEHAVIOR_COUNT_TIME=.*$@BAD_BEHAVIOR_COUNT_TIME=60@' /etc/bunkerweb/variables.env
unset USE_BAD_BEHAVIOR
unset BAD_BEHAVIOR_STATUS_CODES
unset BAD_BEHAVIOR_BAN_TIME
unset BAD_BEHAVIOR_THRESHOLD
unset BAD_BEHAVIOR_COUNT_TIME
fi
if [[ $end -eq 1 && $exit_code = 0 ]] ; then
return
fi
@ -31,10 +64,15 @@ cleanup_stack () {
echo "📟 Cleaning up current stack ..."
docker compose down -v --remove-orphans
if [ "$integration" == "docker" ] ; then
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
echo "📟 Down failed ❌"
echo "📟 Cleanup failed ❌"
exit 1
fi
@ -50,33 +88,74 @@ do
echo "📟 Running tests with badbehavior activated ..."
elif [ "$test" = "deactivated" ] ; then
echo "📟 Running tests without badbehavior ..."
find . -type f -name 'docker-compose.*' -exec sed -i 's@USE_BAD_BEHAVIOR: "yes"@USE_BAD_BEHAVIOR: "no"@' {} \;
if [ "$integration" == "docker" ] ; then
find . -type f -name 'docker-compose.*' -exec sed -i 's@USE_BAD_BEHAVIOR: "yes"@USE_BAD_BEHAVIOR: "no"@' {} \;
else
sudo sed -i 's@USE_BAD_BEHAVIOR=.*$@USE_BAD_BEHAVIOR=no@' /etc/bunkerweb/variables.env
unset USE_BAD_BEHAVIOR
fi
elif [ "$test" = "status_codes" ] ; then
echo "📟 Running tests with badbehavior's 403 status code removed from the list ..."
find . -type f -name 'docker-compose.*' -exec sed -i 's@USE_BAD_BEHAVIOR: "no"@USE_BAD_BEHAVIOR: "yes"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@BAD_BEHAVIOR_STATUS_CODES: "400 401 403 404 405 429 444"@BAD_BEHAVIOR_STATUS_CODES: "400 401 404 405 429 444"@' {} \;
if [ "$integration" == "docker" ] ; then
find . -type f -name 'docker-compose.*' -exec sed -i 's@USE_BAD_BEHAVIOR: "no"@USE_BAD_BEHAVIOR: "yes"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@BAD_BEHAVIOR_STATUS_CODES: "400 401 403 404 405 429 444"@BAD_BEHAVIOR_STATUS_CODES: "400 401 404 405 429 444"@' {} \;
else
sudo sed -i 's@USE_BAD_BEHAVIOR=.*$@USE_BAD_BEHAVIOR=yes@' /etc/bunkerweb/variables.env
sudo sed -i 's@BAD_BEHAVIOR_STATUS_CODES=.*$@BAD_BEHAVIOR_STATUS_CODES=400 401 404 405 429 444@' /etc/bunkerweb/variables.env
unset USE_BAD_BEHAVIOR
unset BAD_BEHAVIOR_STATUS_CODES
fi
elif [ "$test" = "ban_time" ] ; then
echo "📟 Running tests with badbehavior's ban time changed to 60 seconds ..."
find . -type f -name 'docker-compose.*' -exec sed -i 's@BAD_BEHAVIOR_STATUS_CODES: "400 401 404 405 429 444"@BAD_BEHAVIOR_STATUS_CODES: "400 401 403 404 405 429 444"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@BAD_BEHAVIOR_BAN_TIME: "86400"@BAD_BEHAVIOR_BAN_TIME: "60"@' {} \;
if [ "$integration" == "docker" ] ; then
find . -type f -name 'docker-compose.*' -exec sed -i 's@BAD_BEHAVIOR_STATUS_CODES: "400 401 404 405 429 444"@BAD_BEHAVIOR_STATUS_CODES: "400 401 403 404 405 429 444"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@BAD_BEHAVIOR_BAN_TIME: "86400"@BAD_BEHAVIOR_BAN_TIME: "60"@' {} \;
else
sudo sed -i 's@BAD_BEHAVIOR_STATUS_CODES=.*$@BAD_BEHAVIOR_STATUS_CODES=400 401 403 404 405 429 444@' /etc/bunkerweb/variables.env
sudo sed -i 's@BAD_BEHAVIOR_BAN_TIME=.*$@BAD_BEHAVIOR_BAN_TIME=60@' /etc/bunkerweb/variables.env
unset BAD_BEHAVIOR_STATUS_CODES
unset BAD_BEHAVIOR_BAN_TIME
fi
elif [ "$test" = "threshold" ] ; then
echo "📟 Running tests with badbehavior's threshold set to 20 ..."
find . -type f -name 'docker-compose.*' -exec sed -i 's@BAD_BEHAVIOR_BAN_TIME: "60"@BAD_BEHAVIOR_BAN_TIME: "86400"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@BAD_BEHAVIOR_THRESHOLD: "10"@BAD_BEHAVIOR_THRESHOLD: "20"@' {} \;
if [ "$integration" == "docker" ] ; then
find . -type f -name 'docker-compose.*' -exec sed -i 's@BAD_BEHAVIOR_BAN_TIME: "60"@BAD_BEHAVIOR_BAN_TIME: "86400"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@BAD_BEHAVIOR_THRESHOLD: "10"@BAD_BEHAVIOR_THRESHOLD: "20"@' {} \;
else
sudo sed -i 's@BAD_BEHAVIOR_BAN_TIME=.*$@BAD_BEHAVIOR_BAN_TIME=86400@' /etc/bunkerweb/variables.env
sudo sed -i 's@BAD_BEHAVIOR_THRESHOLD=.*$@BAD_BEHAVIOR_THRESHOLD=20@' /etc/bunkerweb/variables.env
unset BAD_BEHAVIOR_BAN_TIME
unset BAD_BEHAVIOR_THRESHOLD
fi
elif [ "$test" = "count_time" ] ; then
echo "📟 Running tests with badbehavior's count time set to 30 seconds ..."
find . -type f -name 'docker-compose.*' -exec sed -i 's@BAD_BEHAVIOR_THRESHOLD: "20"@BAD_BEHAVIOR_THRESHOLD: "10"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@BAD_BEHAVIOR_COUNT_TIME: "60"@BAD_BEHAVIOR_COUNT_TIME: "30"@' {} \;
if [ "$integration" == "docker" ] ; then
find . -type f -name 'docker-compose.*' -exec sed -i 's@BAD_BEHAVIOR_THRESHOLD: "20"@BAD_BEHAVIOR_THRESHOLD: "10"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@BAD_BEHAVIOR_COUNT_TIME: "60"@BAD_BEHAVIOR_COUNT_TIME: "30"@' {} \;
else
sudo sed -i 's@BAD_BEHAVIOR_THRESHOLD=.*$@BAD_BEHAVIOR_THRESHOLD=10@' /etc/bunkerweb/variables.env
sudo sed -i 's@BAD_BEHAVIOR_COUNT_TIME=.*$@BAD_BEHAVIOR_COUNT_TIME=30@' /etc/bunkerweb/variables.env
unset BAD_BEHAVIOR_THRESHOLD
unset BAD_BEHAVIOR_COUNT_TIME
fi
fi
echo "📟 Starting stack ..."
docker compose up -d
if [ $? -ne 0 ] ; then
echo "📟 Up failed, retrying ... ⚠️"
manual=1
cleanup_stack
manual=0
if [ "$integration" == "docker" ] ; then
docker compose up -d
if [ $? -ne 0 ] ; then
echo "📟 Up failed, retrying ... ⚠️"
manual=1
cleanup_stack
manual=0
docker compose up -d
if [ $? -ne 0 ] ; then
echo "📟 Up failed ❌"
exit 1
fi
fi
else
sudo systemctl start bunkerweb
if [ $? -ne 0 ] ; then
echo "📟 Up failed ❌"
exit 1
@ -86,37 +165,72 @@ do
# Check if stack is healthy
echo "📟 Waiting for stack to be healthy ..."
i=0
while [ $i -lt 120 ] ; do
containers=("badbehavior-bw-1" "badbehavior-bw-scheduler-1")
healthy="true"
for container in "${containers[@]}" ; do
check="$(docker inspect --format "{{json .State.Health }}" $container | grep "healthy")"
if [ "$check" = "" ] ; then
healthy="false"
if [ "$integration" == "docker" ] ; then
while [ $i -lt 120 ] ; do
containers=("badbehavior-bw-1" "badbehavior-bw-scheduler-1")
healthy="true"
for container in "${containers[@]}" ; do
check="$(docker inspect --format "{{json .State.Health }}" $container | grep "healthy")"
if [ "$check" = "" ] ; then
healthy="false"
break
fi
done
if [ "$healthy" = "true" ] ; then
echo "📟 Docker stack is healthy ✅"
break
fi
sleep 1
i=$((i+1))
done
if [ "$healthy" = "true" ] ; then
echo "📟 Docker stack is healthy ✅"
break
if [ $i -ge 120 ] ; then
docker compose logs
echo "📟 Docker stack is not healthy ❌"
exit 1
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
sleep 1
i=$((i+1))
done
if [ $i -ge 120 ] ; then
docker compose logs
echo "📟 Docker stack is not healthy ❌"
exit 1
fi
# Start tests
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests
if [ "$integration" == "docker" ] ; then
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests
else
python3 main.py
fi
if [ $? -ne 0 ] ; then
echo "📟 Test \"$test\" failed ❌"
echo "🛡️ Showing BunkerWeb and BunkerWeb Scheduler logs ..."
docker compose logs bw bw-scheduler
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 ✅"

View file

@ -1,17 +1,33 @@
#!/bin/bash
echo "📦 Building brotli stack ..."
integration=$1
# Starting stack
docker compose pull bw-docker app1
if [ $? -ne 0 ] ; then
echo "📦 Pull failed ❌"
if [ -z "$integration" ] ; then
echo "📦 Please provide an integration name as argument ❌"
exit 1
elif [ "$integration" != "docker" ] && [ "$integration" != "linux" ] ; then
echo "📦 Integration \"$integration\" is not supported ❌"
exit 1
fi
docker compose -f docker-compose.test.yml build
if [ $? -ne 0 ] ; then
echo "📦 Build failed ❌"
exit 1
echo "📦 Building brotli stack for integration \"$integration\" ..."
# Starting stack
if [ "$integration" = "docker" ] ; then
docker compose pull bw-docker app1
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 ❌"
exit 1
fi
else
sudo systemctl stop bunkerweb
echo "USE_BROTLI=no" | sudo tee -a /etc/bunkerweb/variables.env
sudo touch /var/www/html/index.html
fi
manual=0
@ -19,7 +35,12 @@ end=0
cleanup_stack () {
exit_code=$?
if [[ $end -eq 1 || $exit_code = 1 ]] || [[ $end -eq 0 && $exit_code = 0 ]] && [ $manual = 0 ] ; then
find . -type f -name 'docker-compose.*' -exec sed -i 's@USE_BROTLI: "yes"@USE_BROTLI: "no"@' {} \;
if [ "$integration" == "docker" ] ; then
find . -type f -name 'docker-compose.*' -exec sed -i 's@USE_BROTLI: "yes"@USE_BROTLI: "no"@' {} \;
else
sudo sed -i 's@USE_BROTLI=.*$@USE_BROTLI=no@' /etc/bunkerweb/variables.env
unset USE_BROTLI
fi
if [[ $end -eq 1 && $exit_code = 0 ]] ; then
return
fi
@ -27,10 +48,15 @@ cleanup_stack () {
echo "📦 Cleaning up current stack ..."
docker compose down -v --remove-orphans
if [ "$integration" == "docker" ] ; then
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
echo "📦 Down failed ❌"
echo "📦 Cleanup failed ❌"
exit 1
fi
@ -46,17 +72,30 @@ do
echo "📦 Running tests without brotli ..."
elif [ "$test" = "activated" ] ; then
echo "📦 Running tests with brotli ..."
find . -type f -name 'docker-compose.*' -exec sed -i 's@USE_BROTLI: "no"@USE_BROTLI: "yes"@' {} \;
if [ "$integration" == "docker" ] ; then
find . -type f -name 'docker-compose.*' -exec sed -i 's@USE_BROTLI: "no"@USE_BROTLI: "yes"@' {} \;
else
sudo sed -i 's@USE_BROTLI=.*$@USE_BROTLI=yes@' /etc/bunkerweb/variables.env
export USE_BROTLI="yes"
fi
fi
echo "📦 Starting stack ..."
docker compose up -d
if [ $? -ne 0 ] ; then
echo "📦 Up failed, retrying ... ⚠️"
manual=1
cleanup_stack
manual=0
if [ "$integration" == "docker" ] ; then
docker compose up -d
if [ $? -ne 0 ] ; then
echo "📦 Up failed, retrying ... ⚠️"
manual=1
cleanup_stack
manual=0
docker compose up -d
if [ $? -ne 0 ] ; then
echo "📦 Up failed ❌"
exit 1
fi
fi
else
sudo systemctl start bunkerweb
if [ $? -ne 0 ] ; then
echo "📦 Up failed ❌"
exit 1
@ -66,37 +105,72 @@ do
# Check if stack is healthy
echo "📦 Waiting for stack to be healthy ..."
i=0
while [ $i -lt 120 ] ; do
containers=("brotli-bw-1" "brotli-bw-scheduler-1")
healthy="true"
for container in "${containers[@]}" ; do
check="$(docker inspect --format "{{json .State.Health }}" $container | grep "healthy")"
if [ "$check" = "" ] ; then
healthy="false"
if [ "$integration" == "docker" ] ; then
while [ $i -lt 120 ] ; do
containers=("brotli-bw-1" "brotli-bw-scheduler-1")
healthy="true"
for container in "${containers[@]}" ; do
check="$(docker inspect --format "{{json .State.Health }}" $container | grep "healthy")"
if [ "$check" = "" ] ; then
healthy="false"
break
fi
done
if [ "$healthy" = "true" ] ; then
echo "📦 Docker stack is healthy ✅"
break
fi
sleep 1
i=$((i+1))
done
if [ "$healthy" = "true" ] ; then
echo "📦 Docker stack is healthy ✅"
break
if [ $i -ge 120 ] ; then
docker compose logs
echo "📦 Docker stack is not healthy ❌"
exit 1
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
sleep 1
i=$((i+1))
done
if [ $i -ge 120 ] ; then
docker compose logs
echo "📦 Docker stack is not healthy ❌"
exit 1
fi
# Start tests
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests
if [ "$integration" == "docker" ] ; then
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests
else
python3 main.py
fi
if [ $? -ne 0 ] ; then
echo "📦 Test \"$test\" failed ❌"
echo "🛡️ Showing BunkerWeb and BunkerWeb Scheduler logs ..."
docker compose logs bw bw-scheduler
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 ✅"

View file

@ -1,26 +1,58 @@
#!/bin/bash
echo "⌨️ Building bunkernet stack ..."
integration=$1
# Starting stack
docker compose pull bw-docker
if [ $? -ne 0 ] ; then
echo "⌨️ Pull failed ❌"
if [ -z "$integration" ] ; then
echo "⌨️ Please provide an integration name as argument ❌"
exit 1
elif [ "$integration" != "docker" ] && [ "$integration" != "linux" ] ; then
echo "⌨️ Integration \"$integration\" is not supported ❌"
exit 1
fi
docker compose -f docker-compose.test.yml build
if [ $? -ne 0 ] ; then
echo "⌨️ Build failed ❌"
exit 1
echo "⌨️ Building bwcli 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 ❌"
exit 1
fi
else
sudo systemctl stop bunkerweb
echo "⌨️ Installing Redis ..."
sudo apt install -y redis
redis-server --daemonize yes
if [ $? -ne 0 ] ; then
echo "⌨️ Redis start failed ❌"
exit 1
fi
echo "⌨️ Redis installed ✅"
echo "USE_REDIS=yes" | sudo tee -a /etc/bunkerweb/variables.env
echo "REDIS_HOST=127.0.0.1" | sudo tee -a /etc/bunkerweb/variables.env
sudo touch /var/www/html/index.html
fi
cleanup_stack () {
echo "⌨️ Cleaning up current stack ..."
docker compose down -v --remove-orphans
if [ "$integration" == "docker" ] ; then
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
echo "⌨️ Down failed ❌"
echo "⌨️ Cleanup failed ❌"
exit 1
fi
@ -33,13 +65,21 @@ trap cleanup_stack EXIT
echo "⌨️ Running bwcli tests ..."
echo "⌨️ Starting stack ..."
docker compose up -d
if [ $? -ne 0 ] ; then
echo "⌨️ Up failed, retrying ... ⚠️"
manual=1
cleanup_stack
manual=0
if [ "$integration" == "docker" ] ; then
docker compose up -d
if [ $? -ne 0 ] ; then
echo "⌨️ Up failed, retrying ... ⚠️"
manual=1
cleanup_stack
manual=0
docker compose up -d
if [ $? -ne 0 ] ; then
echo "⌨️ Up failed ❌"
exit 1
fi
fi
else
sudo systemctl start bunkerweb
if [ $? -ne 0 ] ; then
echo "⌨️ Up failed ❌"
exit 1
@ -49,37 +89,72 @@ fi
# Check if stack is healthy
echo "⌨️ Waiting for stack to be healthy ..."
i=0
while [ $i -lt 120 ] ; do
containers=("bwcli-bw-1" "bwcli-bw-scheduler-1")
healthy="true"
for container in "${containers[@]}" ; do
check="$(docker inspect --format "{{json .State.Health }}" $container | grep "healthy")"
if [ "$check" = "" ] ; then
healthy="false"
if [ "$integration" == "docker" ] ; then
while [ $i -lt 120 ] ; do
containers=("bwcli-bw-1" "bwcli-bw-scheduler-1")
healthy="true"
for container in "${containers[@]}" ; do
check="$(docker inspect --format "{{json .State.Health }}" $container | grep "healthy")"
if [ "$check" = "" ] ; then
healthy="false"
break
fi
done
if [ "$healthy" = "true" ] ; then
echo "⌨️ Docker stack is healthy ✅"
break
fi
sleep 1
i=$((i+1))
done
if [ "$healthy" = "true" ] ; then
echo "⌨️ Docker stack is healthy ✅"
break
if [ $i -ge 120 ] ; then
docker compose logs
echo "⌨️ Docker stack is not healthy ❌"
exit 1
fi
sleep 1
i=$((i+1))
done
if [ $i -ge 120 ] ; then
docker compose logs
echo "⌨️ Docker stack is not healthy ❌"
exit 1
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
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests
if [ "$integration" == "docker" ] ; then
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests
else
python3 main.py
fi
if [ $? -ne 0 ] ; then
echo "⌨️ Test bwcli failed ❌"
echo "🛡️ Showing BunkerWeb and BunkerWeb Scheduler logs ..."
docker compose logs bw bw-scheduler
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 bwcli succeeded ✅"

View file

@ -1,17 +1,36 @@
#!/bin/bash
echo "📝 Building clientcache stack ..."
integration=$1
# Starting stack
docker compose pull bw-docker
if [ $? -ne 0 ] ; then
echo "📝 Pull failed ❌"
if [ -z "$integration" ] ; then
echo "📝 Please provide an integration name as argument ❌"
exit 1
elif [ "$integration" != "docker" ] && [ "$integration" != "linux" ] ; then
echo "📝 Integration \"$integration\" is not supported ❌"
exit 1
fi
docker compose -f docker-compose.test.yml build
if [ $? -ne 0 ] ; then
echo "📝 Build failed ❌"
exit 1
echo "📝 Building clientcache 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 ❌"
exit 1
fi
else
sudo systemctl stop bunkerweb
echo "USE_CLIENT_CACHE=no" | sudo tee -a /etc/bunkerweb/variables.env
echo "CLIENT_CACHE_EXTENSIONS=jpg|jpeg|png|bmp|ico|svg|tif|css|js|otf|ttf|eot|woff|woff2" | sudo tee -a /etc/bunkerweb/variables.env
echo "CLIENT_CACHE_ETAG=yes" | sudo tee -a /etc/bunkerweb/variables.env
echo "CLIENT_CACHE_CONTROL=public, max-age=15552000" | sudo tee -a /etc/bunkerweb/variables.env
sudo touch /var/www/html/index.html
fi
manual=0
@ -19,10 +38,21 @@ end=0
cleanup_stack () {
exit_code=$?
if [[ $end -eq 1 || $exit_code = 1 ]] || [[ $end -eq 0 && $exit_code = 0 ]] && [ $manual = 0 ] ; then
find . -type f -name 'docker-compose.*' -exec sed -i 's@USE_CLIENT_CACHE: "yes"@USE_CLIENT_CACHE: "no"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@CLIENT_CACHE_EXTENSIONS: "jpg|jpeg|bmp|ico|svg|tif|css|js|otf|ttf|eot|woff|woff2"@CLIENT_CACHE_EXTENSIONS: "jpg|jpeg|png|bmp|ico|svg|tif|css|js|otf|ttf|eot|woff|woff2"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@CLIENT_CACHE_ETAG: "no"@CLIENT_CACHE_ETAG: "yes"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@CLIENT_CACHE_CONTROL: "public, max-age=3600"@CLIENT_CACHE_CONTROL: "public, max-age=15552000"@' {} \;
if [ "$integration" == "docker" ] ; then
find . -type f -name 'docker-compose.*' -exec sed -i 's@USE_CLIENT_CACHE: "yes"@USE_CLIENT_CACHE: "no"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@CLIENT_CACHE_EXTENSIONS: "jpg|jpeg|bmp|ico|svg|tif|css|js|otf|ttf|eot|woff|woff2"@CLIENT_CACHE_EXTENSIONS: "jpg|jpeg|png|bmp|ico|svg|tif|css|js|otf|ttf|eot|woff|woff2"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@CLIENT_CACHE_ETAG: "no"@CLIENT_CACHE_ETAG: "yes"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@CLIENT_CACHE_CONTROL: "public, max-age=3600"@CLIENT_CACHE_CONTROL: "public, max-age=15552000"@' {} \;
else
sudo sed -i 's@USE_CLIENT_CACHE=.*$@USE_CLIENT_CACHE=no@' /etc/bunkerweb/variables.env
sudo sed -i 's@CLIENT_CACHE_EXTENSIONS=.*$@CLIENT_CACHE_EXTENSIONS=jpg|jpeg|bmp|ico|svg|tif|css|js|otf|ttf|eot|woff|woff2@' /etc/bunkerweb/variables.env
sudo sed -i 's@CLIENT_CACHE_ETAG=.*$@CLIENT_CACHE_ETAG=yes@' /etc/bunkerweb/variables.env
sudo sed -i 's@CLIENT_CACHE_CONTROL=.*$@CLIENT_CACHE_CONTROL=public, max-age=15552000@' /etc/bunkerweb/variables.env
unset USE_CLIENT_CACHE
unset CLIENT_CACHE_EXTENSIONS
unset CLIENT_CACHE_ETAG
unset CLIENT_CACHE_CONTROL
fi
if [[ $end -eq 1 && $exit_code = 0 ]] ; then
return
fi
@ -30,10 +60,15 @@ cleanup_stack () {
echo "📝 Cleaning up current stack ..."
docker compose down -v --remove-orphans
if [ "$integration" == "docker" ] ; then
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
echo "📝 Down failed ❌"
echo "📝 Cleanup failed ❌"
exit 1
fi
@ -49,28 +84,60 @@ do
echo "📝 Running tests without clientcache ..."
elif [ "$test" = "activated" ] ; then
echo "📝 Running tests with clientcache ..."
find . -type f -name 'docker-compose.*' -exec sed -i 's@USE_CLIENT_CACHE: "no"@USE_CLIENT_CACHE: "yes"@' {} \;
if [ "$integration" == "docker" ] ; then
find . -type f -name 'docker-compose.*' -exec sed -i 's@USE_CLIENT_CACHE: "no"@USE_CLIENT_CACHE: "yes"@' {} \;
else
sudo sed -i 's@USE_CLIENT_CACHE=.*$@USE_CLIENT_CACHE=yes@' /etc/bunkerweb/variables.env
export USE_CLIENT_CACHE="yes"
fi
elif [ "$test" = "cache_extensions" ] ; then
echo "📝 Running tests when removing png from the cache extensions ..."
find . -type f -name 'docker-compose.*' -exec sed -i 's@CLIENT_CACHE_EXTENSIONS: "jpg|jpeg|png|bmp|ico|svg|tif|css|js|otf|ttf|eot|woff|woff2"@CLIENT_CACHE_EXTENSIONS: "jpg|jpeg|bmp|ico|svg|tif|css|js|otf|ttf|eot|woff|woff2"@' {} \;
if [ "$integration" == "docker" ] ; then
find . -type f -name 'docker-compose.*' -exec sed -i 's@CLIENT_CACHE_EXTENSIONS: "jpg|jpeg|png|bmp|ico|svg|tif|css|js|otf|ttf|eot|woff|woff2"@CLIENT_CACHE_EXTENSIONS: "jpg|jpeg|bmp|ico|svg|tif|css|js|otf|ttf|eot|woff|woff2"@' {} \;
else
sudo sed -i 's@CLIENT_CACHE_EXTENSIONS=.*$@CLIENT_CACHE_EXTENSIONS=jpg|jpeg|bmp|ico|svg|tif|css|js|otf|ttf|eot|woff|woff2@' /etc/bunkerweb/variables.env
export CLIENT_CACHE_EXTENSIONS="jpg|jpeg|bmp|ico|svg|tif|css|js|otf|ttf|eot|woff|woff2"
fi
elif [ "$test" = "cache_etag" ] ; then
echo "📝 Running tests when deactivating the etag ..."
find . -type f -name 'docker-compose.*' -exec sed -i 's@CLIENT_CACHE_EXTENSIONS: "jpg|jpeg|bmp|ico|svg|tif|css|js|otf|ttf|eot|woff|woff2"@CLIENT_CACHE_EXTENSIONS: "jpg|jpeg|png|bmp|ico|svg|tif|css|js|otf|ttf|eot|woff|woff2"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@CLIENT_CACHE_ETAG: "yes"@CLIENT_CACHE_ETAG: "no"@' {} \;
if [ "$integration" == "docker" ] ; then
find . -type f -name 'docker-compose.*' -exec sed -i 's@CLIENT_CACHE_EXTENSIONS: "jpg|jpeg|bmp|ico|svg|tif|css|js|otf|ttf|eot|woff|woff2"@CLIENT_CACHE_EXTENSIONS: "jpg|jpeg|png|bmp|ico|svg|tif|css|js|otf|ttf|eot|woff|woff2"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@CLIENT_CACHE_ETAG: "yes"@CLIENT_CACHE_ETAG: "no"@' {} \;
else
sudo sed -i 's@CLIENT_CACHE_EXTENSIONS=.*$@CLIENT_CACHE_EXTENSIONS=jpg|jpeg|png|bmp|ico|svg|tif|css|js|otf|ttf|eot|woff|woff2@' /etc/bunkerweb/variables.env
sudo sed -i 's@CLIENT_CACHE_ETAG=.*$@CLIENT_CACHE_ETAG=no@' /etc/bunkerweb/variables.env
export CLIENT_CACHE_EXTENSIONS="jpg|jpeg|png|bmp|ico|svg|tif|css|js|otf|ttf|eot|woff|woff2"
export CLIENT_CACHE_ETAG="no"
fi
elif [ "$test" = "cache_control" ] ; then
echo "📝 Running tests whith clientcache control set to public, max-age=3600 ..."
find . -type f -name 'docker-compose.*' -exec sed -i 's@CLIENT_CACHE_ETAG: "no"@CLIENT_CACHE_ETAG: "yes"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@CLIENT_CACHE_CONTROL: "public, max-age=15552000"@CLIENT_CACHE_CONTROL: "public, max-age=3600"@' {} \;
if [ "$integration" == "docker" ] ; then
find . -type f -name 'docker-compose.*' -exec sed -i 's@CLIENT_CACHE_ETAG: "no"@CLIENT_CACHE_ETAG: "yes"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@CLIENT_CACHE_CONTROL: "public, max-age=15552000"@CLIENT_CACHE_CONTROL: "public, max-age=3600"@' {} \;
else
sudo sed -i 's@CLIENT_CACHE_ETAG=.*$@CLIENT_CACHE_ETAG=yes@' /etc/bunkerweb/variables.env
sudo sed -i 's@CLIENT_CACHE_CONTROL=.*$@CLIENT_CACHE_CONTROL=public, max-age=3600@' /etc/bunkerweb/variables.env
export CLIENT_CACHE_ETAG="yes"
export CLIENT_CACHE_CONTROL="public, max-age=3600"
fi
fi
echo "📝 Starting stack ..."
docker compose up -d
if [ $? -ne 0 ] ; then
echo "📝 Up failed, retrying ... ⚠️"
manual=1
cleanup_stack
manual=0
if [ "$integration" == "docker" ] ; then
docker compose up -d
if [ $? -ne 0 ] ; then
echo "📝 Up failed, retrying ... ⚠️"
manual=1
cleanup_stack
manual=0
docker compose up -d
if [ $? -ne 0 ] ; then
echo "📝 Up failed ❌"
exit 1
fi
fi
else
sudo systemctl start bunkerweb
if [ $? -ne 0 ] ; then
echo "📝 Up failed ❌"
exit 1
@ -80,37 +147,72 @@ do
# Check if stack is healthy
echo "📝 Waiting for stack to be healthy ..."
i=0
while [ $i -lt 120 ] ; do
containers=("clientcache-bw-1" "clientcache-bw-scheduler-1")
healthy="true"
for container in "${containers[@]}" ; do
check="$(docker inspect --format "{{json .State.Health }}" $container | grep "healthy")"
if [ "$check" = "" ] ; then
healthy="false"
if [ "$integration" == "docker" ] ; then
while [ $i -lt 120 ] ; do
containers=("clientcache-bw-1" "clientcache-bw-scheduler-1")
healthy="true"
for container in "${containers[@]}" ; do
check="$(docker inspect --format "{{json .State.Health }}" $container | grep "healthy")"
if [ "$check" = "" ] ; then
healthy="false"
break
fi
done
if [ "$healthy" = "true" ] ; then
echo "📝 Docker stack is healthy ✅"
break
fi
sleep 1
i=$((i+1))
done
if [ "$healthy" = "true" ] ; then
echo "📝 Docker stack is healthy ✅"
break
if [ $i -ge 120 ] ; then
docker compose logs
echo "📝 Docker stack is not healthy ❌"
exit 1
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
sleep 1
i=$((i+1))
done
if [ $i -ge 120 ] ; then
docker compose logs
echo "📝 Docker stack is not healthy ❌"
exit 1
fi
# Start tests
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests
if [ "$integration" == "docker" ] ; then
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests
else
python3 main.py
fi
if [ $? -ne 0 ] ; then
echo "📝 Test \"$test\" failed ❌"
echo "🛡️ Showing BunkerWeb and BunkerWeb Scheduler logs ..."
docker compose logs bw bw-scheduler
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 ✅"

View file

@ -1,17 +1,46 @@
#!/bin/bash
echo "🛰️ Building cors stack ..."
integration=$1
# Starting stack
docker compose pull bw-docker app1
if [ $? -ne 0 ] ; then
echo "🛰️ Pull failed ❌"
if [ -z "$integration" ] ; then
echo "🛰️ Please provide an integration name as argument ❌"
exit 1
elif [ "$integration" != "docker" ] && [ "$integration" != "linux" ] ; then
echo "🛰️ Integration \"$integration\" is not supported ❌"
exit 1
fi
docker compose -f docker-compose.test.yml build
if [ $? -ne 0 ] ; then
echo "🛰️ Build failed ❌"
exit 1
echo "🛰️ Building cors stack for integration \"$integration\" ..."
# Starting stack
if [ "$integration" = "docker" ] ; then
docker compose pull bw-docker app1
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 ❌"
exit 1
fi
else
sudo systemctl stop bunkerweb
sudo cp -r www/* /var/www/html/
sudo chown -R www-data:nginx /var/www/html
sudo find /var/www/html -type f -exec chmod 0640 {} \;
sudo find /var/www/html -type d -exec chmod 0750 {} \;
echo "LOCAL_PHP=/run/php/php-fpm.sock" | sudo tee -a /etc/bunkerweb/variables.env
echo "LOCAL_PHP_PATH=/var/www/html" | sudo tee -a /etc/bunkerweb/variables.env
echo "ALLOWED_METHODS=GET|POST|HEAD|OPTIONS" | sudo tee -a /etc/bunkerweb/variables.env
echo "GENERATE_SELF_SIGNED_SSL=no" | sudo tee -a /etc/bunkerweb/variables.env
echo "USE_CORS=no" | sudo tee -a /etc/bunkerweb/variables.env
echo "CORS_ALLOW_ORIGIN=*" | sudo tee -a /etc/bunkerweb/variables.env
echo "CORS_EXPOSE_HEADERS=Content-Length,Content-Range" | sudo tee -a /etc/bunkerweb/variables.env
echo "CORS_MAX_AGE=86400" | sudo tee -a /etc/bunkerweb/variables.env
echo "CORS_ALLOW_CREDENTIALS=no" | sudo tee -a /etc/bunkerweb/variables.env
echo "CORS_ALLOW_METHODS=GET, POST, OPTIONS" | sudo tee -a /etc/bunkerweb/variables.env
echo "CORS_ALLOW_HEADERS=DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range" | sudo tee -a /etc/bunkerweb/variables.env
fi
manual=0
@ -19,14 +48,33 @@ end=0
cleanup_stack () {
exit_code=$?
if [[ $end -eq 1 || $exit_code = 1 ]] || [[ $end -eq 0 && $exit_code = 0 ]] && [ $manual = 0 ] ; then
find . -type f -name 'docker-compose.*' -exec sed -i 's@USE_CORS: "yes"@USE_CORS: "no"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@GENERATE_SELF_SIGNED_SSL: "yes"@GENERATE_SELF_SIGNED_SSL: "no"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@CORS_ALLOW_ORIGIN: ".*"$@CORS_ALLOW_ORIGIN: "\*"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@CORS_EXPOSE_HEADERS: "X-Test"@CORS_EXPOSE_HEADERS: "Content-Length,Content-Range"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@CORS_MAX_AGE: "3600"@CORS_MAX_AGE: "86400"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@CORS_ALLOW_CREDENTIALS: "yes"@CORS_ALLOW_CREDENTIALS: "no"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@CORS_ALLOW_METHODS: "GET, HEAD, POST, OPTIONS"@CORS_ALLOW_METHODS: "GET, POST, OPTIONS"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@CORS_ALLOW_HEADERS: "X-Test"@CORS_ALLOW_HEADERS: "DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range"@' {} \;
if [ "$integration" == "docker" ] ; then
find . -type f -name 'docker-compose.*' -exec sed -i 's@USE_CORS: "yes"@USE_CORS: "no"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@GENERATE_SELF_SIGNED_SSL: "yes"@GENERATE_SELF_SIGNED_SSL: "no"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@CORS_ALLOW_ORIGIN: ".*"$@CORS_ALLOW_ORIGIN: "\*"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@CORS_EXPOSE_HEADERS: "X-Test"@CORS_EXPOSE_HEADERS: "Content-Length,Content-Range"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@CORS_MAX_AGE: "3600"@CORS_MAX_AGE: "86400"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@CORS_ALLOW_CREDENTIALS: "yes"@CORS_ALLOW_CREDENTIALS: "no"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@CORS_ALLOW_METHODS: "GET, HEAD, POST, OPTIONS"@CORS_ALLOW_METHODS: "GET, POST, OPTIONS"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@CORS_ALLOW_HEADERS: "X-Test"@CORS_ALLOW_HEADERS: "DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range"@' {} \;
else
sed -i 's@USE_CORS=.*$@USE_CORS=no@' /etc/bunkerweb/variables.env
sed -i 's@GENERATE_SELF_SIGNED_SSL=.*$@GENERATE_SELF_SIGNED_SSL=no@' /etc/bunkerweb/variables.env
sed -i 's@CORS_ALLOW_ORIGIN=.*$@CORS_ALLOW_ORIGIN=*@' /etc/bunkerweb/variables.env
sed -i 's@CORS_EXPOSE_HEADERS=.*$@CORS_EXPOSE_HEADERS=Content-Length,Content-Range@' /etc/bunkerweb/variables.env
sed -i 's@CORS_MAX_AGE=.*$@CORS_MAX_AGE=86400@' /etc/bunkerweb/variables.env
sed -i 's@CORS_ALLOW_CREDENTIALS=.*$@CORS_ALLOW_CREDENTIALS=no@' /etc/bunkerweb/variables.env
sed -i 's@CORS_ALLOW_METHODS=.*$@CORS_ALLOW_METHODS=GET, POST, OPTIONS@' /etc/bunkerweb/variables.env
sed -i 's@CORS_ALLOW_HEADERS=.*$@CORS_ALLOW_HEADERS=DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range@' /etc/bunkerweb/variables.env
unset USE_CORS
unset GENERATE_SELF_SIGNED_SSL
unset CORS_ALLOW_ORIGIN
unset CORS_EXPOSE_HEADERS
unset CORS_MAX_AGE
unset CORS_ALLOW_CREDENTIALS
unset CORS_ALLOW_METHODS
unset CORS_ALLOW_HEADERS
fi
if [[ $end -eq 1 && $exit_code = 0 ]] ; then
return
fi
@ -34,10 +82,15 @@ cleanup_stack () {
echo "🛰️ Cleaning up current stack ..."
docker compose down -v --remove-orphans
if [ "$integration" == "docker" ] ; then
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
echo "🛰️ Down failed ❌"
echo "🛰️ Cleanup failed ❌"
exit 1
fi
@ -47,14 +100,16 @@ cleanup_stack () {
# Cleanup stack on exit
trap cleanup_stack EXIT
echo "🛰️ Initializing workspace ..."
docker compose -f docker-compose.init.yml up --build
if [ $? -ne 0 ] ; then
echo "🛰️ Build failed ❌"
exit 1
elif [[ $(stat -L -c "%a %g %u" www/app1.example.com/index.php) != "655 101 33" ]] ; then
echo "🛰️ Init failed, permissions are not correct ❌"
exit 1
if [ "$integration" == "docker" ] ; then
echo "🛰️ Initializing workspace ..."
docker compose -f docker-compose.init.yml up --build
if [ $? -ne 0 ] ; then
echo "🛰️ Build failed ❌"
exit 1
elif [[ $(stat -L -c "%a %g %u" www/app1.example.com/index.php) != "655 101 33" ]] ; then
echo "🛰️ Init failed, permissions are not correct ❌"
exit 1
fi
fi
for test in "deactivated" "activated" "allow_origin" "tweaked_settings"
@ -63,29 +118,64 @@ do
echo "🛰️ Running tests without cors ..."
elif [ "$test" = "activated" ] ; then
echo "🛰️ Running tests with cors ..."
find . -type f -name 'docker-compose.*' -exec sed -i 's@USE_CORS: "no"@USE_CORS: "yes"@' {} \;
if [ "$integration" == "docker" ] ; then
find . -type f -name 'docker-compose.*' -exec sed -i 's@USE_CORS: "no"@USE_CORS: "yes"@' {} \;
else
sed -i 's@USE_CORS=.*$@USE_CORS=yes@' /etc/bunkerweb/variables.env
export USE_CORS="yes"
fi
elif [ "$test" = "allow_origin" ] ; then
echo "🛰️ Running tests with a specific origin allowed only ..."
find . -type f -name 'docker-compose.*' -exec sed -i 's@CORS_ALLOW_ORIGIN: "\*"@CORS_ALLOW_ORIGIN: "^http://app1\\\\.example\\\\.com$$"@' {} \;
if [ "$integration" == "docker" ] ; then
find . -type f -name 'docker-compose.*' -exec sed -i 's@CORS_ALLOW_ORIGIN: "\*"@CORS_ALLOW_ORIGIN: "^http://app1\\\\.example\\\\.com$$"@' {} \;
else
sed -i 's@CORS_ALLOW_ORIGIN=.*$@CORS_ALLOW_ORIGIN=^http://app1\\.example\\.com$$@' /etc/bunkerweb/variables.env
export CORS_ALLOW_ORIGIN="^http://app1\\.example\\.com\$"
fi
elif [ "$test" = "tweaked_settings" ] ; then
echo "🛰️ Running tests with tweaked cors settings ..."
find . -type f -name 'docker-compose.*' -exec sed -i 's@GENERATE_SELF_SIGNED_SSL: "no"@GENERATE_SELF_SIGNED_SSL: "yes"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@CORS_ALLOW_ORIGIN: ".*"$@CORS_ALLOW_ORIGIN: "^https://app1\\\\.example\\\\.com$$"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@CORS_EXPOSE_HEADERS: "Content-Length,Content-Range"@CORS_EXPOSE_HEADERS: "X-Test"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@CORS_MAX_AGE: "86400"@CORS_MAX_AGE: "3600"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@CORS_ALLOW_CREDENTIALS: "no"@CORS_ALLOW_CREDENTIALS: "yes"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@CORS_ALLOW_METHODS: "GET, POST, OPTIONS"@CORS_ALLOW_METHODS: "GET, HEAD, POST, OPTIONS"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@CORS_ALLOW_HEADERS: "DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range"@CORS_ALLOW_HEADERS: "X-Test"@' {} \;
if [ "$integration" == "docker" ] ; then
find . -type f -name 'docker-compose.*' -exec sed -i 's@GENERATE_SELF_SIGNED_SSL: "no"@GENERATE_SELF_SIGNED_SSL: "yes"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@CORS_ALLOW_ORIGIN: ".*"$@CORS_ALLOW_ORIGIN: "^https://app1\\\\.example\\\\.com$$"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@CORS_EXPOSE_HEADERS: "Content-Length,Content-Range"@CORS_EXPOSE_HEADERS: "X-Test"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@CORS_MAX_AGE: "86400"@CORS_MAX_AGE: "3600"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@CORS_ALLOW_CREDENTIALS: "no"@CORS_ALLOW_CREDENTIALS: "yes"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@CORS_ALLOW_METHODS: "GET, POST, OPTIONS"@CORS_ALLOW_METHODS: "GET, HEAD, POST, OPTIONS"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@CORS_ALLOW_HEADERS: "DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range"@CORS_ALLOW_HEADERS: "X-Test"@' {} \;
else
sed -i 's@GENERATE_SELF_SIGNED_SSL=.*$@GENERATE_SELF_SIGNED_SSL=yes@' /etc/bunkerweb/variables.env
sed -i 's@CORS_ALLOW_ORIGIN=.*$@CORS_ALLOW_ORIGIN=^https://app1\\.example\\.com\$@' /etc/bunkerweb/variables.env
sed -i 's@CORS_EXPOSE_HEADERS=.*$@CORS_EXPOSE_HEADERS=X-Test@' /etc/bunkerweb/variables.env
sed -i 's@CORS_MAX_AGE=.*$@CORS_MAX_AGE=3600@' /etc/bunkerweb/variables.env
sed -i 's@CORS_ALLOW_CREDENTIALS=.*$@CORS_ALLOW_CREDENTIALS=yes@' /etc/bunkerweb/variables.env
sed -i 's@CORS_ALLOW_METHODS=.*$@CORS_ALLOW_METHODS=GET, HEAD, POST, OPTIONS@' /etc/bunkerweb/variables.env
sed -i 's@CORS_ALLOW_HEADERS=.*$@CORS_ALLOW_HEADERS=X-Test@' /etc/bunkerweb/variables.env
export GENERATE_SELF_SIGNED_SSL="yes"
export CORS_ALLOW_ORIGIN="^https://app1\\.example\\.com\$"
export CORS_EXPOSE_HEADERS="X-Test"
export CORS_MAX_AGE="3600"
export CORS_ALLOW_CREDENTIALS="yes"
export CORS_ALLOW_METHODS="GET, HEAD, POST, OPTIONS"
export CORS_ALLOW_HEADERS="X-Test"
fi
fi
echo "🛰️ Starting stack ..."
docker compose up -d
if [ $? -ne 0 ] ; then
echo "🛰️ Up failed, retrying ... ⚠️"
manual=1
cleanup_stack
manual=0
if [ "$integration" == "docker" ] ; then
docker compose up -d
if [ $? -ne 0 ] ; then
echo "🛰️ Up failed, retrying ... ⚠️"
manual=1
cleanup_stack
manual=0
docker compose up -d
if [ $? -ne 0 ] ; then
echo "🛰️ Up failed ❌"
exit 1
fi
fi
else
sudo systemctl start bunkerweb
if [ $? -ne 0 ] ; then
echo "🛰️ Up failed ❌"
exit 1
@ -95,37 +185,72 @@ do
# Check if stack is healthy
echo "🛰️ Waiting for stack to be healthy ..."
i=0
while [ $i -lt 120 ] ; do
containers=("cors-bw-1" "cors-bw-scheduler-1")
healthy="true"
for container in "${containers[@]}" ; do
check="$(docker inspect --format "{{json .State.Health }}" $container | grep "healthy")"
if [ "$check" = "" ] ; then
healthy="false"
if [ "$integration" == "docker" ] ; then
while [ $i -lt 120 ] ; do
containers=("cors-bw-1" "cors-bw-scheduler-1")
healthy="true"
for container in "${containers[@]}" ; do
check="$(docker inspect --format "{{json .State.Health }}" $container | grep "healthy")"
if [ "$check" = "" ] ; then
healthy="false"
break
fi
done
if [ "$healthy" = "true" ] ; then
echo "🛰️ Docker stack is healthy ✅"
break
fi
sleep 1
i=$((i+1))
done
if [ "$healthy" = "true" ] ; then
echo "🛰️ Docker stack is healthy ✅"
break
if [ $i -ge 120 ] ; then
docker compose logs
echo "🛰️ Docker stack is not healthy ❌"
exit 1
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
sleep 1
i=$((i+1))
done
if [ $i -ge 120 ] ; then
docker compose logs
echo "🛰️ Docker stack is not healthy ❌"
exit 1
fi
# Start tests
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests
if [ "$integration" == "docker" ] ; then
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests
else
python3 main.py
fi
if [ $? -ne 0 ] ; then
echo "🛰️ Test \"$test\" failed ❌"
echo "🛡️ Showing BunkerWeb and BunkerWeb Scheduler logs ..."
docker compose logs bw bw-scheduler
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 ✅"

View file

@ -1,17 +1,47 @@
#!/bin/bash
echo "🔏 Building customcert stack ..."
integration=$1
# Starting stack
docker compose pull bw-docker
if [ $? -ne 0 ] ; then
echo "🔏 Pull failed ❌"
if [ -z "$integration" ] ; then
echo "🔏 Please provide an integration name as argument ❌"
exit 1
elif [ "$integration" != "docker" ] && [ "$integration" != "linux" ] ; then
echo "🔏 Integration \"$integration\" is not supported ❌"
exit 1
fi
docker compose -f docker-compose.test.yml build
if [ $? -ne 0 ] ; then
echo "🔏 Build failed ❌"
exit 1
echo "🔏 Building customcert 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 ❌"
exit 1
fi
else
sudo systemctl stop bunkerweb
echo "🔏 Installing openssl ..."
sudo apt-get install openssl -y
echo "🔏 Generating certificate for www.example.com ..."
openssl req -nodes -x509 -newkey rsa:4096 -keyout /tmp/privatekey.key -out /tmp/certificate.pem -days 365 -subj /CN=www.example.com/
if [ $? -ne 0 ] ; then
echo "🔏 Certificate generation failed ❌"
exit 1
fi
sudo chmod 777 /tmp/privatekey.key /tmp/certificate.pem
echo "USE_CUSTOM_SSL=no" | sudo tee -a /etc/bunkerweb/variables.env
echo "CUSTOM_SSL_CERT=/tmp/certificate.pem" | sudo tee -a /etc/bunkerweb/variables.env
echo "CUSTOM_SSL_KEY=/tmp/certificate.key" | sudo tee -a /etc/bunkerweb/variables.env
sudo touch /var/www/html/index.html
fi
manual=0
@ -19,8 +49,16 @@ end=0
cleanup_stack () {
exit_code=$?
if [[ $end -eq 1 || $exit_code = 1 ]] || [[ $end -eq 0 && $exit_code = 0 ]] && [ $manual = 0 ] ; then
rm -rf init/certs
find . -type f -name 'docker-compose.*' -exec sed -i 's@USE_CUSTOM_SSL: "yes"@USE_CUSTOM_SSL: "no"@' {} \;
if [ "$integration" == "docker" ] ; then
rm -rf init/certs
find . -type f -name 'docker-compose.*' -exec sed -i 's@USE_CUSTOM_SSL: "yes"@USE_CUSTOM_SSL: "no"@' {} \;
else
sudo rm -f /tmp/certificate.pem /tmp/privatekey.key
sudo sed -i 's@USE_CUSTOM_SSL=.*$@USE_CUSTOM_SSL=no@' /etc/bunkerweb/variables.env
unset USE_CUSTOM_SSL
unset CUSTOM_SSL_CERT
unset CUSTOM_SSL_KEY
fi
if [[ $end -eq 1 && $exit_code = 0 ]] ; then
return
fi
@ -28,10 +66,15 @@ cleanup_stack () {
echo "🔏 Cleaning up current stack ..."
docker compose down -v --remove-orphans
if [ "$integration" == "docker" ] ; then
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
echo "🔏 Down failed ❌"
echo "🔏 Cleanup failed ❌"
exit 1
fi
@ -41,19 +84,21 @@ cleanup_stack () {
# Cleanup stack on exit
trap cleanup_stack EXIT
echo "🔏 Initializing workspace ..."
rm -rf init/certs
mkdir -p init/certs
docker compose -f docker-compose.init.yml up --build
if [ $? -ne 0 ] ; then
echo "🔏 Build failed ❌"
exit 1
elif ! [[ -f "init/certs/certificate.pem" ]]; then
echo "🔏 certificate.pem not found ❌"
exit 1
elif ! [[ -f "init/certs/privatekey.key" ]]; then
echo "🔏 privatekey.key not found ❌"
exit 1
if [ "$integration" == "docker" ] ; then
echo "🔏 Initializing workspace ..."
rm -rf init/certs
mkdir -p init/certs
docker compose -f docker-compose.init.yml up --build
if [ $? -ne 0 ] ; then
echo "🔏 Build failed ❌"
exit 1
elif ! [[ -f "init/certs/certificate.pem" ]]; then
echo "🔏 certificate.pem not found ❌"
exit 1
elif ! [[ -f "init/certs/privatekey.key" ]]; then
echo "🔏 privatekey.key not found ❌"
exit 1
fi
fi
for test in "deactivated" "activated"
@ -62,17 +107,30 @@ do
echo "🔏 Running tests without the custom cert ..."
elif [ "$test" = "activated" ] ; then
echo "🔏 Running tests with the custom cert activated ..."
find . -type f -name 'docker-compose.*' -exec sed -i 's@USE_CUSTOM_SSL: "no"@USE_CUSTOM_SSL: "yes"@' {} \;
if [ "$integration" == "docker" ] ; then
find . -type f -name 'docker-compose.*' -exec sed -i 's@USE_CUSTOM_SSL: "no"@USE_CUSTOM_SSL: "yes"@' {} \;
else
sudo sed -i 's@USE_CUSTOM_SSL=.*$@USE_CUSTOM_SSL=yes@' /etc/bunkerweb/variables.env
export USE_CUSTOM_SSL="yes"
fi
fi
echo "🔏 Starting stack ..."
docker compose up -d
if [ $? -ne 0 ] ; then
echo "🔏 Up failed, retrying ... ⚠️"
manual=1
cleanup_stack
manual=0
if [ "$integration" == "docker" ] ; then
docker compose up -d
if [ $? -ne 0 ] ; then
echo "🔏 Up failed, retrying ... ⚠️"
manual=1
cleanup_stack
manual=0
docker compose up -d
if [ $? -ne 0 ] ; then
echo "🔏 Up failed ❌"
exit 1
fi
fi
else
sudo systemctl start bunkerweb
if [ $? -ne 0 ] ; then
echo "🔏 Up failed ❌"
exit 1
@ -82,37 +140,72 @@ do
# Check if stack is healthy
echo "🔏 Waiting for stack to be healthy ..."
i=0
while [ $i -lt 120 ] ; do
containers=("customcert-bw-1" "customcert-bw-scheduler-1")
healthy="true"
for container in "${containers[@]}" ; do
check="$(docker inspect --format "{{json .State.Health }}" $container | grep "healthy")"
if [ "$check" = "" ] ; then
healthy="false"
if [ "$integration" == "docker" ] ; then
while [ $i -lt 120 ] ; do
containers=("customcert-bw-1" "customcert-bw-scheduler-1")
healthy="true"
for container in "${containers[@]}" ; do
check="$(docker inspect --format "{{json .State.Health }}" $container | grep "healthy")"
if [ "$check" = "" ] ; then
healthy="false"
break
fi
done
if [ "$healthy" = "true" ] ; then
echo "🔏 Docker stack is healthy ✅"
break
fi
sleep 1
i=$((i+1))
done
if [ "$healthy" = "true" ] ; then
echo "🔏 Docker stack is healthy ✅"
break
if [ $i -ge 120 ] ; then
docker compose logs
echo "🔏 Docker stack is not healthy ❌"
exit 1
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
sleep 1
i=$((i+1))
done
if [ $i -ge 120 ] ; then
docker compose logs
echo "🔏 Docker stack is not healthy ❌"
exit 1
fi
# Start tests
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests
if [ "$integration" == "docker" ] ; then
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests
else
python3 main.py
fi
if [ $? -ne 0 ] ; then
echo "🔏 Test \"$test\" failed ❌"
echo "🛡️ Showing BunkerWeb and BunkerWeb Scheduler logs ..."
docker compose logs bw bw-scheduler
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 ✅"

View file

@ -17,7 +17,7 @@ services:
GLOBAL_REVERSE_PROXY_HOST: "http://app1:8080"
GLOBAL_REVERSE_PROXY_URL: "/"
GLOBAL_LOG_LEVEL: "info"
CUSTOM_CONF_MODSEC_test_custom_conf: 'SecRule REQUEST_FILENAME "@rx ^/db" "id:1,ctl:ruleRemoveByTag=attack-generic,ctl:ruleRemoveByTag=attack-protocol,nolog"'
CUSTOM_CONF_MODSEC_test_custom_conf: 'SecRule REQUEST_FILENAME "@rx ^/db" "id:10000,ctl:ruleRemoveByTag=attack-generic,ctl:ruleRemoveByTag=attack-protocol,nolog"'
GLOBAL_SERVER_NAME: "bwadm.example.com"
extra_hosts:
- "bwadm.example.com:192.168.0.2"

View file

@ -17,7 +17,7 @@ services:
REVERSE_PROXY_HOST: "http://app1:8080"
REVERSE_PROXY_URL: "/"
LOG_LEVEL: "info"
CUSTOM_CONF_MODSEC_test_custom_conf: 'SecRule REQUEST_FILENAME "@rx ^/db" "id:1,ctl:ruleRemoveByTag=attack-generic,ctl:ruleRemoveByTag=attack-protocol,nolog"'
CUSTOM_CONF_MODSEC_test_custom_conf: 'SecRule REQUEST_FILENAME "@rx ^/db" "id:10000,ctl:ruleRemoveByTag=attack-generic,ctl:ruleRemoveByTag=attack-protocol,nolog"'
networks:
bw-universe:
bw-services:

View file

@ -4,13 +4,9 @@ echo " Cloning BunkerWeb Plugins ..."
git clone https://github.com/bunkerity/bunkerweb-plugins.git
echo " Checking out to dev branch ..."
cd bunkerweb-plugins
echo " Extracting ClamAV plugin ..."
cp -r clamav /plugins/
cp -r bunkerweb-plugins/clamav /plugins/
cd ..

View file

@ -1,30 +1,62 @@
#!/bin/bash
echo "💾 Building db stack ..."
integration=$1
if [ -z "$integration" ] ; then
echo "💾 Please provide an integration name as argument ❌"
exit 1
elif [ "$integration" != "docker" ] && [ "$integration" != "linux" ] ; then
echo "💾 Integration \"$integration\" is not supported ❌"
exit 1
fi
echo "💾 Building db stack for integration \"$integration\" ..."
# Starting stack
docker compose pull bw-docker app1
if [ $? -ne 0 ] ; then
echo "💾 Pull failed ❌"
exit 1
fi
if [ "$integration" = "docker" ] ; then
docker compose pull bw-docker app1
if [ $? -ne 0 ] ; then
echo "💾 Pull failed ❌"
exit 1
fi
docker compose -f docker-compose.mariadb.yml pull bw-db
if [ $? -ne 0 ] ; then
echo "💾 Pull failed ❌"
exit 1
fi
docker compose -f docker-compose.mysql.yml pull bw-db
if [ $? -ne 0 ] ; then
echo "💾 Pull failed ❌"
exit 1
fi
docker compose -f docker-compose.postgres.yml pull bw-db
if [ $? -ne 0 ] ; then
echo "💾 Pull failed ❌"
exit 1
fi
else
sudo systemctl stop bunkerweb
echo "MULTISITE=no" | sudo tee -a /etc/bunkerweb/variables.env
echo "USE_REVERSE_PROXY=yes" | sudo tee -a /etc/bunkerweb/variables.env
echo "REVERSE_PROXY_HOST=http://app1:8080" | sudo tee -a /etc/bunkerweb/variables.env
echo "REVERSE_PROXY_URL=/" | sudo tee -a /etc/bunkerweb/variables.env
echo "DATABASE_URI=sqlite:////var/ib/bunkerweb/db.sqlite3" | sudo tee -a /etc/bunkerweb/variables.env
echo 'SecRule REQUEST_FILENAME "@rx ^/db" "id:10000,ctl:ruleRemoveByTag=attack-generic,ctl:ruleRemoveByTag=attack-protocol,nolog"' | sudo tee /etc/bunkerweb/configs/modsec/test_custom_conf.conf
sudo chown -R nginx:nginx /etc/bunkerweb
sudo touch /var/www/html/index.html
docker compose -f docker-compose.mariadb.yml pull bw-db
if [ $? -ne 0 ] ; then
echo "💾 Pull failed ❌"
exit 1
fi
docker compose -f docker-compose.mysql.yml pull bw-db
if [ $? -ne 0 ] ; then
echo "💾 Pull failed ❌"
exit 1
fi
docker compose -f docker-compose.postgres.yml pull bw-db
if [ $? -ne 0 ] ; then
echo "💾 Pull failed ❌"
exit 1
export GLOBAL_SERVER_NAME="bwadm.example.com"
export GLOBAL_API_WHITELIST_IP="127.0.0.0/8"
export GLOBAL_HTTP_PORT="80"
export GLOBAL_HTTPS_PORT="433"
export GLOBAL_DNS_RESOLVERS="9.9.9.9 8.8.8.8 8.8.4.4"
export GLOBAL_LOG_LEVEL="info"
export GLOBAL_USE_BUNKERNET="no"
export GLOBAL_USE_BLACKLIST="no"
export GLOBAL_USE_REVERSE_PROXY="yes"
export GLOBAL_REVERSE_PROXY_HOST="http://app1:8080"
export GLOBAL_REVERSE_PROXY_URL="/"
export CUSTOM_CONF_MODSEC_test_custom_conf='SecRule REQUEST_FILENAME "@rx ^/db" "id:10000,ctl:ruleRemoveByTag=attack-generic,ctl:ruleRemoveByTag=attack-protocol,nolog"'
fi
manual=0
@ -32,33 +64,53 @@ end=0
cleanup_stack () {
exit_code=$?
if [[ $end -eq 1 || $exit_code = 1 ]] || [[ $end -eq 0 && $exit_code = 0 ]] && [ $manual = 0 ] ; then
rm -rf init/plugins
rm -rf init/bunkerweb
find . -type f -name 'docker-compose.*' -exec sed -i 's@DATABASE_URI: ".*"$@DATABASE_URI: "sqlite:////var/lib/bunkerweb/db.sqlite3"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@MULTISITE: "yes"$@MULTISITE: "no"@' {} \;
sed -i 's@bwadm.example.com_USE_REVERSE_PROXY@USE_REVERSE_PROXY@' docker-compose.yml
sed -i 's@bwadm.example.com_REVERSE_PROXY_HOST@REVERSE_PROXY_HOST@' docker-compose.yml
sed -i 's@bwadm.example.com_REVERSE_PROXY_URL@REVERSE_PROXY_URL@' docker-compose.yml
sed -i 's@SERVICE_USE_REVERSE_PROXY@GLOBAL_USE_REVERSE_PROXY@' docker-compose.test.yml
sed -i 's@SERVICE_REVERSE_PROXY_HOST@GLOBAL_REVERSE_PROXY_HOST@' docker-compose.test.yml
sed -i 's@SERVICE_REVERSE_PROXY_URL@GLOBAL_REVERSE_PROXY_URL@' docker-compose.test.yml
if [ "$integration" == "docker" ] ; then
rm -rf init/plugins
rm -rf init/bunkerweb
find . -type f -name 'docker-compose.*' -exec sed -i 's@DATABASE_URI: ".*"$@DATABASE_URI: "sqlite:////var/lib/bunkerweb/db.sqlite3"@' {} \;
find . -type f -name 'docker-compose.*' -exec sed -i 's@MULTISITE: "yes"$@MULTISITE: "no"@' {} \;
sed -i 's@bwadm.example.com_USE_REVERSE_PROXY@USE_REVERSE_PROXY@' docker-compose.yml
sed -i 's@bwadm.example.com_REVERSE_PROXY_HOST@REVERSE_PROXY_HOST@' docker-compose.yml
sed -i 's@bwadm.example.com_REVERSE_PROXY_URL@REVERSE_PROXY_URL@' docker-compose.yml
sed -i 's@SERVICE_USE_REVERSE_PROXY@GLOBAL_USE_REVERSE_PROXY@' docker-compose.test.yml
sed -i 's@SERVICE_REVERSE_PROXY_HOST@GLOBAL_REVERSE_PROXY_HOST@' docker-compose.test.yml
sed -i 's@SERVICE_REVERSE_PROXY_URL@GLOBAL_REVERSE_PROXY_URL@' docker-compose.test.yml
if [[ $(sed '16!d' docker-compose.yml) = ' bwadm.example.com_SERVER_NAME: "bwadm.example.com"' ]] ; then
sed -i '16d' docker-compose.yml
if [[ $(sed '16!d' docker-compose.yml) = ' bwadm.example.com_SERVER_NAME: "bwadm.example.com"' ]] ; then
sed -i '16d' docker-compose.yml
fi
if [[ $(sed '20!d' docker-compose.yml) = " bwadm.example.com_CUSTOM_CONF_MODSEC_CRS_test_service_conf: 'SecRule REQUEST_FILENAME \"@rx ^/test\" \"id:10001,ctl:ruleRemoveByTag=attack-generic,ctl:ruleRemoveByTag=attack-protocol,nolog\"'" ]] ; then
sed -i '20d' docker-compose.yml
fi
if [[ $(sed '16!d' docker-compose.test.yml) = ' SERVICE_SERVER_NAME: "bwadm.example.com"' ]] ; then
sed -i '16d' docker-compose.test.yml
fi
if [[ $(sed '20!d' docker-compose.test.yml) = " CUSTOM_CONF_SERVICE_MODSEC_CRS_test_service_conf: 'SecRule REQUEST_FILENAME \"@rx ^/test\" \"id:10001,ctl:ruleRemoveByTag=attack-generic,ctl:ruleRemoveByTag=attack-protocol,nolog\"'" ]] ; then
sed -i '20d' docker-compose.test.yml
fi
else
sudo rm -rf /etc/bunkerweb/plugins
sed -i 's@MULTISITE=.*$@MULTISITE=no@' /etc/bunkerweb/variables.env
sed -i 's@DATABASE_URI=.*$@DATABASE_URI=sqlite:////var/lib/bunkerweb/db.sqlite3@' /etc/bunkerweb/variables.env
sed -i 's@bwadm.example.com_@@g' /etc/bunkerweb/variables.env
if [[ $(sudo tail -n 1 /etc/bunkerweb/variables.env) = "SERVER_NAME=bwadm.example.com" ]] ; then
sudo sed -i '$ d' /etc/bunkerweb/variables.env
fi
unset SERVICE_USE_REVERSE_PROXY
unset SERVICE_REVERSE_PROXY_HOST
unset SERVICE_REVERSE_PROXY_URL
unset CUSTOM_CONF_SERVICE_MODSEC_CRS_test_service_conf
export GLOBAL_SERVER_NAME="bwadm.example.com"
export GLOBAL_USE_REVERSE_PROXY="yes"
export GLOBAL_REVERSE_PROXY_HOST="http://app1:8080"
export GLOBAL_REVERSE_PROXY_URL="/"
sudo rm -f /etc/bunkerweb/configs/modsec-crs/test_service_conf.conf
fi
if [[ $(sed '20!d' docker-compose.yml) = " bwadm.example.com_CUSTOM_CONF_MODSEC_CRS_test_service_conf: 'SecRule REQUEST_FILENAME \"@rx ^/test\" \"id:2,ctl:ruleRemoveByTag=attack-generic,ctl:ruleRemoveByTag=attack-protocol,nolog\"'" ]] ; then
sed -i '20d' docker-compose.yml
fi
if [[ $(sed '16!d' docker-compose.test.yml) = ' SERVICE_SERVER_NAME: "bwadm.example.com"' ]] ; then
sed -i '16d' docker-compose.test.yml
fi
if [[ $(sed '20!d' docker-compose.test.yml) = " CUSTOM_CONF_SERVICE_MODSEC_CRS_test_service_conf: 'SecRule REQUEST_FILENAME \"@rx ^/test\" \"id:2,ctl:ruleRemoveByTag=attack-generic,ctl:ruleRemoveByTag=attack-protocol,nolog\"'" ]] ; then
sed -i '20d' docker-compose.test.yml
fi
if [[ $end -eq 1 && $exit_code = 0 ]] ; then
return
fi
@ -66,10 +118,15 @@ cleanup_stack () {
echo "💾 Cleaning up current stack ..."
docker compose down -v --remove-orphans
if [ "$integration" == "docker" ] ; then
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
echo "💾 Down failed ❌"
echo "💾 Cleanup failed ❌"
exit 1
fi
@ -79,55 +136,84 @@ cleanup_stack () {
# Cleanup stack on exit
trap cleanup_stack EXIT
echo "💾 Creating the bw-docker network ..."
docker network create bw-docker
if [ "$integration" == "docker" ] ; then
echo "💾 Creating the bw-docker network ..."
docker network create bw-docker
echo "💾 Starting stack ..."
docker compose up -d
if [ $? -ne 0 ] ; then
echo "💾 Up failed, retrying ... ⚠️"
manual=1
cleanup_stack
manual=0
echo "💾 Starting stack ..."
docker compose up -d
if [ $? -ne 0 ] ; then
echo "💾 Up failed ❌"
exit 1
echo "💾 Up failed, retrying ... ⚠️"
manual=1
cleanup_stack
manual=0
docker compose up -d
if [ $? -ne 0 ] ; then
echo "💾 Up failed ❌"
exit 1
fi
fi
fi
echo "💾 Initializing workspace ..."
rm -rf init/plugins init/bunkerweb
mkdir -p init/plugins init/bunkerweb
docker compose -f docker-compose.init.yml up --build
if [ $? -ne 0 ] ; then
echo "💾 Build failed ❌"
exit 1
elif ! [[ -d "init/plugins/clamav" ]]; then
echo "💾 ClamAV plugin not found ❌"
exit 1
elif ! [[ -d "init/bunkerweb/core" ]]; then
echo "💾 BunkerWeb's core plugins directory not found ❌"
exit 1
elif ! [[ -d "init/bunkerweb/db" ]]; then
echo "💾 BunkerWeb's database directory not found ❌"
exit 1
elif ! [[ -f "init/bunkerweb/settings.json" ]]; then
echo "💾 BunkerWeb's settings file not found ❌"
exit 1
if [ "$integration" == "docker" ] ; then
rm -rf init/plugins init/bunkerweb
mkdir -p init/plugins init/bunkerweb
docker compose -f docker-compose.init.yml up --build
if [ $? -ne 0 ] ; then
echo "💾 Build failed ❌"
exit 1
elif ! [[ -d "init/plugins/clamav" ]]; then
echo "💾 ClamAV plugin not found ❌"
exit 1
elif ! [[ -d "init/bunkerweb/core" ]]; then
echo "💾 BunkerWeb's core plugins directory not found ❌"
exit 1
elif ! [[ -d "init/bunkerweb/db" ]]; then
echo "💾 BunkerWeb's database directory not found ❌"
exit 1
elif ! [[ -f "init/bunkerweb/settings.json" ]]; then
echo "💾 BunkerWeb's settings file not found ❌"
exit 1
fi
manual=1
cleanup_stack
manual=0
docker compose -f docker-compose.test.yml build
if [ $? -ne 0 ] ; then
echo "💾 Build failed ❌"
exit 1
fi
else
sudo rm -rf external bunkerweb bunkerweb-plugins
echo "💾 Cloning BunkerWeb Plugins ..."
git clone https://github.com/bunkerity/bunkerweb-plugins.git
echo "💾 Extracting ClamAV plugin ..."
mkdir external
sudo cp -r bunkerweb-plugins/clamav external/
sudo cp -r external/clamav /etc/bunkerweb/plugins/
rm -rf bunkerweb-plugins
echo "💾 Extracting settings.json file, db and core directory ..."
mkdir bunkerweb
sudo cp /usr/share/bunkerweb/settings.json bunkerweb/
sudo cp -r /usr/share/bunkerweb/core bunkerweb/
sudo cp -r /usr/share/bunkerweb/db bunkerweb/
sudo chown -R nginx:nginx /etc/bunkerweb
sudo chmod -R 777 /etc/bunkerweb/plugins external bunkerweb
fi
manual=1
cleanup_stack
manual=0
tests="local multisite"
docker compose -f docker-compose.test.yml build
if [ $? -ne 0 ] ; then
echo "💾 Build failed ❌"
exit 1
if [ "$integration" == "docker" ] ; then
tests="$tests mariadb mysql postgres"
fi
for test in "local" "multisite" "mariadb" "mysql" "postgres"
for test in $tests
do
echo "💾 Creating the bw-docker network ..."
docker network create bw-docker
@ -136,17 +222,36 @@ do
echo "💾 Running tests with a local database ..."
elif [ "$test" = "multisite" ] ; then
echo "💾 Running tests with MULTISITE set to yes and with multisite settings ..."
find . -type f -name 'docker-compose.*' -exec sed -i 's@MULTISITE: "no"$@MULTISITE: "yes"@' {} \;
sed -i '16i \ bwadm.example.com_SERVER_NAME: "bwadm.example.com"' docker-compose.yml
sed -i "21i \ bwadm.example.com_CUSTOM_CONF_MODSEC_CRS_test_service_conf: 'SecRule REQUEST_FILENAME \"@rx ^/test\" \"id:2,ctl:ruleRemoveByTag=attack-generic,ctl:ruleRemoveByTag=attack-protocol,nolog\"'" docker-compose.yml
sed -i 's@USE_REVERSE_PROXY@bwadm.example.com_USE_REVERSE_PROXY@' docker-compose.yml
sed -i 's@REVERSE_PROXY_HOST@bwadm.example.com_REVERSE_PROXY_HOST@' docker-compose.yml
sed -i 's@REVERSE_PROXY_URL@bwadm.example.com_REVERSE_PROXY_URL@' docker-compose.yml
sed -i "21i \ CUSTOM_CONF_SERVICE_MODSEC_CRS_test_service_conf: 'SecRule REQUEST_FILENAME \"@rx ^/test\" \"id:2,ctl:ruleRemoveByTag=attack-generic,ctl:ruleRemoveByTag=attack-protocol,nolog\"'" docker-compose.test.yml
sed -i 's@GLOBAL_USE_REVERSE_PROXY@SERVICE_USE_REVERSE_PROXY@' docker-compose.test.yml
sed -i 's@GLOBAL_REVERSE_PROXY_HOST@SERVICE_REVERSE_PROXY_HOST@' docker-compose.test.yml
sed -i 's@GLOBAL_REVERSE_PROXY_URL@SERVICE_REVERSE_PROXY_URL@' docker-compose.test.yml
sed -i 's@GLOBAL_SERVER_NAME@SERVICE_SERVER_NAME@' docker-compose.test.yml
if [ "$integration" == "docker" ] ; then
find . -type f -name 'docker-compose.*' -exec sed -i 's@MULTISITE: "no"$@MULTISITE: "yes"@' {} \;
sed -i '16i \ bwadm.example.com_SERVER_NAME: "bwadm.example.com"' docker-compose.yml
sed -i "21i \ bwadm.example.com_CUSTOM_CONF_MODSEC_CRS_test_service_conf: 'SecRule REQUEST_FILENAME \"@rx ^/test\" \"id:10001,ctl:ruleRemoveByTag=attack-generic,ctl:ruleRemoveByTag=attack-protocol,nolog\"'" docker-compose.yml
sed -i 's@USE_REVERSE_PROXY@bwadm.example.com_USE_REVERSE_PROXY@' docker-compose.yml
sed -i 's@REVERSE_PROXY_HOST@bwadm.example.com_REVERSE_PROXY_HOST@' docker-compose.yml
sed -i 's@REVERSE_PROXY_URL@bwadm.example.com_REVERSE_PROXY_URL@' docker-compose.yml
sed -i "21i \ CUSTOM_CONF_SERVICE_MODSEC_CRS_test_service_conf: 'SecRule REQUEST_FILENAME \"@rx ^/test\" \"id:10001,ctl:ruleRemoveByTag=attack-generic,ctl:ruleRemoveByTag=attack-protocol,nolog\"'" docker-compose.test.yml
sed -i 's@GLOBAL_USE_REVERSE_PROXY@SERVICE_USE_REVERSE_PROXY@' docker-compose.test.yml
sed -i 's@GLOBAL_REVERSE_PROXY_HOST@SERVICE_REVERSE_PROXY_HOST@' docker-compose.test.yml
sed -i 's@GLOBAL_REVERSE_PROXY_URL@SERVICE_REVERSE_PROXY_URL@' docker-compose.test.yml
sed -i 's@GLOBAL_SERVER_NAME@SERVICE_SERVER_NAME@' docker-compose.test.yml
else
sed -i 's@MULTISITE=.*$@MULTISITE=yes@' /etc/bunkerweb/variables.env
echo "bwadm.example.com_SERVER_NAME=bwadm.example.com" | sudo tee -a /etc/bunkerweb/variables.env
echo 'SecRule REQUEST_FILENAME "@rx ^/test" "id:10001,ctl:ruleRemoveByTag=attack-generic,ctl:ruleRemoveByTag=attack-protocol,nolog"' | sudo tee /etc/bunkerweb/configs/modsec-crs/test_service_conf.conf
sed -i 's@USE_REVERSE_PROXY@bwadm.example.com_USE_REVERSE_PROXY@' /etc/bunkerweb/variables.env
sed -i 's@REVERSE_PROXY_HOST@bwadm.example.com_REVERSE_PROXY_HOST@' /etc/bunkerweb/variables.env
sed -i 's@REVERSE_PROXY_URL@bwadm.example.com_REVERSE_PROXY_URL@' /etc/bunkerweb/variables.env
export CUSTOM_CONF_SERVICE_MODSEC_CRS_test_service_conf='SecRule REQUEST_FILENAME "@rx ^/test" "id:10001,ctl:ruleRemoveByTag=attack-generic,ctl:ruleRemoveByTag=attack-protocol,nolog"'
export SERVICE_USE_REVERSE_PROXY=$GLOBAL_USE_REVERSE_PROXY
export SERVICE_REVERSE_PROXY_HOST=$GLOBAL_REVERSE_PROXY_HOST
export SERVICE_REVERSE_PROXY_URL=$GLOBAL_REVERSE_PROXY_URL
export SERVICE_SERVER_NAME=$GLOBAL_SERVER_NAME
unset GLOBAL_USE_REVERSE_PROXY
unset GLOBAL_REVERSE_PROXY_HOST
unset GLOBAL_REVERSE_PROXY_URL
unset GLOBAL_SERVER_NAME
fi
elif [ "$test" = "mariadb" ] ; then
echo "💾 Running tests with MariaDB database ..."
echo " Keeping the MULTISITE variable to yes and multisite settings ..."
@ -204,32 +309,40 @@ do
fi
echo "💾 Starting stack ..."
docker compose up -d
if [ $? -ne 0 ] ; then
echo "💾 Up failed, retrying ... ⚠️"
manual=1
cleanup_stack
if [ "$test" = "mariadb" ] ; then
docker compose -f docker-compose.mariadb.yml up -d
if [ $? -ne 0 ] ; then
echo "💾 Up failed ❌"
exit 1
if [ "$integration" == "docker" ] ; then
docker compose up -d
if [ $? -ne 0 ] ; then
echo "💾 Up failed, retrying ... ⚠️"
manual=1
cleanup_stack
if [ "$test" = "mariadb" ] ; then
docker compose -f docker-compose.mariadb.yml up -d
if [ $? -ne 0 ] ; then
echo "💾 Up failed ❌"
exit 1
fi
elif [ "$test" = "mysql" ] ; then
docker compose -f docker-compose.mysql.yml up -d
if [ $? -ne 0 ] ; then
echo "💾 Up failed ❌"
exit 1
fi
elif [ "$test" = "postgres" ] ; then
docker compose -f docker-compose.postgres.yml up -d
if [ $? -ne 0 ] ; then
echo "💾 Up failed ❌"
exit 1
fi
fi
elif [ "$test" = "mysql" ] ; then
docker compose -f docker-compose.mysql.yml up -d
if [ $? -ne 0 ] ; then
echo "💾 Up failed ❌"
exit 1
fi
elif [ "$test" = "postgres" ] ; then
docker compose -f docker-compose.postgres.yml up -d
manual=0
docker compose up -d
if [ $? -ne 0 ] ; then
echo "💾 Up failed ❌"
exit 1
fi
fi
manual=0
docker compose up -d
else
sudo systemctl start bunkerweb
if [ $? -ne 0 ] ; then
echo "💾 Up failed ❌"
exit 1
@ -239,39 +352,74 @@ do
# Check if stack is healthy
echo "💾 Waiting for stack to be healthy ..."
i=0
while [ $i -lt 120 ] ; do
containers=("db-bw-1" "db-bw-scheduler-1")
healthy="true"
for container in "${containers[@]}" ; do
check="$(docker inspect --format "{{json .State.Health }}" $container | grep "healthy")"
if [ "$check" = "" ] ; then
healthy="false"
if [ "$integration" == "docker" ] ; then
while [ $i -lt 120 ] ; do
containers=("db-bw-1" "db-bw-scheduler-1")
healthy="true"
for container in "${containers[@]}" ; do
check="$(docker inspect --format "{{json .State.Health }}" $container | grep "healthy")"
if [ "$check" = "" ] ; then
healthy="false"
break
fi
done
if [ "$healthy" = "true" ] ; then
echo "💾 Docker stack is healthy ✅"
break
fi
sleep 1
i=$((i+1))
done
if [ "$healthy" = "true" ] ; then
echo "💾 Docker stack is healthy ✅"
break
if [ $i -ge 120 ] ; then
docker compose logs
echo "💾 Docker stack is not healthy ❌"
echo "🛡️ Showing BunkerWeb and BunkerWeb Scheduler logs ..."
docker compose logs bw bw-scheduler
exit 1
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
sleep 1
i=$((i+1))
done
if [ $i -ge 120 ] ; then
docker compose logs
echo "💾 Docker stack is not healthy ❌"
echo "🛡️ Showing BunkerWeb and BunkerWeb Scheduler logs ..."
docker compose logs bw bw-scheduler
exit 1
fi
# Start tests
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests
if [ "$integration" == "docker" ] ; then
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests
else
python3 main.py
fi
if [ $? -ne 0 ] ; then
echo "💾 Test \"$test\" failed ❌"
echo "🛡️ Showing BunkerWeb and BunkerWeb Scheduler logs ..."
docker compose logs bw bw-scheduler
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 ✅"
@ -283,13 +431,15 @@ do
echo " "
echo "💾 Removing bw-docker network ..."
if [ "$integration" == "docker" ] ; then
echo "💾 Removing bw-docker network ..."
docker network rm bw-docker
docker network rm bw-docker
if [ $? -ne 0 ] ; then
echo "💾 Network removal failed ❌"
exit 1
if [ $? -ne 0 ] ; then
echo "💾 Network removal failed ❌"
exit 1
fi
fi
done