diff --git a/exampleYmlFiles/docker-compose-latest-lite-security.yml b/exampleYmlFiles/docker-compose-latest-lite-security.yml new file mode 100644 index 00000000..98b95058 --- /dev/null +++ b/exampleYmlFiles/docker-compose-latest-lite-security.yml @@ -0,0 +1,31 @@ +version: '3.3' +services: + stirling-pdf: + container_name: Stirling-PDF-Lite-Security + image: frooodle/s-pdf:latest-lite-local + deploy: + resources: + limits: + memory: 1G + healthcheck: + test: ["CMD-SHELL", "curl -f http://localhost:8080/api/v1/info/status | grep -q 'UP' && curl -fL http://localhost:8080/ | grep -q 'Please sign in'"] + interval: 30s + timeout: 10s + retries: 3 + ports: + - 8080:8080 + volumes: + - /stirling/latest/data:/usr/share/tesseract-ocr/5/tessdata:rw + - /stirling/latest/config:/configs:rw + - /stirling/latest/logs:/logs:rw + environment: + DOCKER_ENABLE_SECURITY: "true" + SECURITY_ENABLELOGIN: "true" + SYSTEM_DEFAULTLOCALE: en_US + UI_APPNAME: Stirling-PDF + UI_HOMEDESCRIPTION: Demo site for Stirling-PDF Latest + UI_APPNAMENAVBAR: Stirling-PDF Latest + SYSTEM_MAXFILESIZE: "100" + METRICS_ENABLED: "true" + SYSTEM_GOOGLEVISIBILITY: "true" + restart: on-failure:5 diff --git a/exampleYmlFiles/docker-compose-latest-lite.yml b/exampleYmlFiles/docker-compose-latest-lite.yml new file mode 100644 index 00000000..c2f18efe --- /dev/null +++ b/exampleYmlFiles/docker-compose-latest-lite.yml @@ -0,0 +1,30 @@ +version: '3.3' +services: + stirling-pdf: + container_name: Stirling-PDF-Lite + image: frooodle/s-pdf:latest-lite-local + deploy: + resources: + limits: + memory: 1G + healthcheck: + test: ["CMD-SHELL", "curl -f http://localhost:8080/api/v1/info/status | grep -q 'UP' && curl -fL http://localhost:8080/ | grep -qv 'Please sign in'"] + interval: 20s + timeout: 10s + retries: 3 + ports: + - 8080:8080 + volumes: + - /stirling/latest/config:/configs:rw + - /stirling/latest/logs:/logs:rw + environment: + DOCKER_ENABLE_SECURITY: "false" + SECURITY_ENABLELOGIN: "false" + SYSTEM_DEFAULTLOCALE: en_US + UI_APPNAME: Stirling-PDF + UI_HOMEDESCRIPTION: Demo site for Stirling-PDF Latest + UI_APPNAMENAVBAR: Stirling-PDF Latest + SYSTEM_MAXFILESIZE: "100" + METRICS_ENABLED: "true" + SYSTEM_GOOGLEVISIBILITY: "true" + restart: on-failure:5 diff --git a/exampleYmlFiles/docker-compose-latest-security.yml b/exampleYmlFiles/docker-compose-latest-security.yml new file mode 100644 index 00000000..b36a08a3 --- /dev/null +++ b/exampleYmlFiles/docker-compose-latest-security.yml @@ -0,0 +1,31 @@ +version: '3.3' +services: + stirling-pdf: + container_name: Stirling-PDF-Security + image: frooodle/s-pdf:latest-local + deploy: + resources: + limits: + memory: 1G + healthcheck: + test: ["CMD-SHELL", "curl -f http://localhost:8080/api/v1/info/status | grep -q 'UP' && curl -fL http://localhost:8080/ | grep -q 'Please sign in'"] + interval: 20s + timeout: 10s + retries: 3 + ports: + - 8080:8080 + volumes: + - /stirling/latest/data:/usr/share/tesseract-ocr/5/tessdata:rw + - /stirling/latest/config:/configs:rw + - /stirling/latest/logs:/logs:rw + environment: + DOCKER_ENABLE_SECURITY: "true" + SECURITY_ENABLELOGIN: "true" + SYSTEM_DEFAULTLOCALE: en_US + UI_APPNAME: Stirling-PDF + UI_HOMEDESCRIPTION: Demo site for Stirling-PDF Latest + UI_APPNAMENAVBAR: Stirling-PDF Latest + SYSTEM_MAXFILESIZE: "100" + METRICS_ENABLED: "true" + SYSTEM_GOOGLEVISIBILITY: "true" + restart: on-failure:5 diff --git a/exampleYmlFiles/docker-compose-latest-ultra-lite-security.yml b/exampleYmlFiles/docker-compose-latest-ultra-lite-security.yml new file mode 100644 index 00000000..7b0d6c43 --- /dev/null +++ b/exampleYmlFiles/docker-compose-latest-ultra-lite-security.yml @@ -0,0 +1,31 @@ +version: '3.3' +services: + stirling-pdf: + container_name: Stirling-PDF-Ultra-Lite-Security + image: frooodle/s-pdf:latest-ultra-lite-local + deploy: + resources: + limits: + memory: 1G + healthcheck: + test: ["CMD-SHELL", "curl -f http://localhost:8080/api/v1/info/status | grep -q 'UP' && curl -fL http://localhost:8080/ | grep -q 'Please sign in'"] + interval: 30s + timeout: 10s + retries: 3 + ports: + - 8080:8080 + volumes: + - /stirling/latest/data:/usr/share/tesseract-ocr/5/tessdata:rw + - /stirling/latest/config:/configs:rw + - /stirling/latest/logs:/logs:rw + environment: + DOCKER_ENABLE_SECURITY: "true" + SECURITY_ENABLELOGIN: "true" + SYSTEM_DEFAULTLOCALE: en_US + UI_APPNAME: Stirling-PDF + UI_HOMEDESCRIPTION: Demo site for Stirling-PDF Latest + UI_APPNAMENAVBAR: Stirling-PDF Latest + SYSTEM_MAXFILESIZE: "100" + METRICS_ENABLED: "true" + SYSTEM_GOOGLEVISIBILITY: "true" + restart: on-failure:5 diff --git a/exampleYmlFiles/docker-compose-latest-ultra-lite.yml b/exampleYmlFiles/docker-compose-latest-ultra-lite.yml new file mode 100644 index 00000000..5848873d --- /dev/null +++ b/exampleYmlFiles/docker-compose-latest-ultra-lite.yml @@ -0,0 +1,30 @@ +version: '3.3' +services: + stirling-pdf: + container_name: Stirling-PDF-Ultra-Lite + image: frooodle/s-pdf:latest-ultra-lite-local + deploy: + resources: + limits: + memory: 1G + healthcheck: + test: ["CMD-SHELL", "curl -f http://localhost:8080/api/v1/info/status | grep -q 'UP' && curl -fL http://localhost:8080/ | grep -qv 'Please sign in'"] + interval: 20s + timeout: 10s + retries: 3 + ports: + - 8080:8080 + volumes: + - /stirling/latest/config:/configs:rw + - /stirling/latest/logs:/logs:rw + environment: + DOCKER_ENABLE_SECURITY: "false" + SECURITY_ENABLELOGIN: "false" + SYSTEM_DEFAULTLOCALE: en_US + UI_APPNAME: Stirling-PDF + UI_HOMEDESCRIPTION: Demo site for Stirling-PDF Latest + UI_APPNAMENAVBAR: Stirling-PDF Latest + SYSTEM_MAXFILESIZE: "100" + METRICS_ENABLED: "true" + SYSTEM_GOOGLEVISIBILITY: "true" + restart: on-failure:5 diff --git a/exampleYmlFiles/docker-compose-latest.yml b/exampleYmlFiles/docker-compose-latest.yml new file mode 100644 index 00000000..e319695f --- /dev/null +++ b/exampleYmlFiles/docker-compose-latest.yml @@ -0,0 +1,31 @@ +version: '3.3' +services: + stirling-pdf: + container_name: Stirling-PDF + image: frooodle/s-pdf:latest-local + deploy: + resources: + limits: + memory: 1G + healthcheck: + test: ["CMD-SHELL", "curl -f http://localhost:8080/api/v1/info/status | grep -q 'UP' && curl -fL http://localhost:8080/ | grep -qv 'Please sign in'"] + interval: 30s + timeout: 10s + retries: 3 + ports: + - 8080:8080 + volumes: + - /stirling/latest/data:/usr/share/tesseract-ocr/5/tessdata:rw + - /stirling/latest/config:/configs:rw + - /stirling/latest/logs:/logs:rw + environment: + DOCKER_ENABLE_SECURITY: "false" + SECURITY_ENABLELOGIN: "false" + SYSTEM_DEFAULTLOCALE: en_US + UI_APPNAME: Stirling-PDF + UI_HOMEDESCRIPTION: Demo site for Stirling-PDF Latest + UI_APPNAMENAVBAR: Stirling-PDF Latest + SYSTEM_MAXFILESIZE: "100" + METRICS_ENABLED: "true" + SYSTEM_GOOGLEVISIBILITY: "true" + restart: on-failure:5 diff --git a/src/main/java/stirling/software/SPDF/config/security/SecurityConfiguration.java b/src/main/java/stirling/software/SPDF/config/security/SecurityConfiguration.java index 71394b09..18fad46b 100644 --- a/src/main/java/stirling/software/SPDF/config/security/SecurityConfiguration.java +++ b/src/main/java/stirling/software/SPDF/config/security/SecurityConfiguration.java @@ -91,7 +91,7 @@ public class SecurityConfiguration { trimmedUri.startsWith("/register") || trimmedUri.startsWith("/error") || trimmedUri.startsWith("/images/") || trimmedUri.startsWith("/public/") || trimmedUri.startsWith("/css/") || trimmedUri.startsWith("/js/") || - trimmedUri.startsWith("api/v1/info/status"); + trimmedUri.startsWith("/api/v1/info/status"); } ).permitAll() .anyRequest().authenticated() diff --git a/src/main/java/stirling/software/SPDF/config/security/UserAuthenticationFilter.java b/src/main/java/stirling/software/SPDF/config/security/UserAuthenticationFilter.java index ce77e5a4..2b98a9e5 100644 --- a/src/main/java/stirling/software/SPDF/config/security/UserAuthenticationFilter.java +++ b/src/main/java/stirling/software/SPDF/config/security/UserAuthenticationFilter.java @@ -102,6 +102,7 @@ public class UserAuthenticationFilter extends OncePerRequestFilter { contextPath + "/css/", contextPath + "/js/", contextPath + "/pdfjs/", + contextPath + "/api/v1/info/status", contextPath + "/site.webmanifest" }; diff --git a/src/main/java/stirling/software/SPDF/utils/RequestUriUtils.java b/src/main/java/stirling/software/SPDF/utils/RequestUriUtils.java index 0046ee9f..6f07b573 100644 --- a/src/main/java/stirling/software/SPDF/utils/RequestUriUtils.java +++ b/src/main/java/stirling/software/SPDF/utils/RequestUriUtils.java @@ -9,7 +9,8 @@ public class RequestUriUtils { || requestURI.startsWith("/images/") || requestURI.startsWith("/public/") || requestURI.startsWith("/pdfjs/") - || requestURI.endsWith(".svg"); + || requestURI.endsWith(".svg") + || requestURI.startsWith("/api/v1/info/status"); } diff --git a/test.sh b/test.sh new file mode 100644 index 00000000..3b84ef42 --- /dev/null +++ b/test.sh @@ -0,0 +1,122 @@ +#!/bin/bash + +# Function to check the health of the service with a timeout of 80 seconds +check_health() { + local service_name=$1 + local compose_file=$2 + local end=$((SECONDS+60)) + + echo "Waiting for $service_name to become healthy..." + until [ "$(docker inspect --format='{{json .State.Health.Status}}' "$service_name")" == '"healthy"' ] || [ $SECONDS -ge $end ]; do + sleep 10 + echo "Waiting..." + if [ $SECONDS -ge $end ]; then + echo "$service_name health check timed out after 80 seconds." + return 1 + fi + done + echo "$service_name is healthy!" + return 0 +} + +# Function to test a Docker Compose configuration +test_compose() { + local compose_file=$1 + local service_name=$2 + local status=0 + + echo "Testing $compose_file configuration..." + + # Start up the Docker Compose service + docker-compose -f "$compose_file" up -d + + # Wait for the service to become healthy + if check_health "$service_name" "$compose_file"; then + echo "$service_name test passed." + else + echo "$service_name test failed." + status=1 + fi + + # Perform additional tests if needed + + # Tear down the service + docker-compose -f "$compose_file" down + + return $status +} + +# Keep track of which tests passed and failed +declare -a passed_tests +declare -a failed_tests + +run_tests() { + local test_name=$1 + local compose_file=$2 + + if test_compose "$compose_file" "$test_name"; then + passed_tests+=("$test_name") + else + failed_tests+=("$test_name") + fi +} + +# Main testing routine +main() { + export DOCKER_ENABLE_SECURITY=false + ./gradlew clean build + + # Building Docker images + docker build --build-arg VERSION_TAG=alpha -t frooodle/s-pdf:latest-local -f ./Dockerfile . + docker build --build-arg VERSION_TAG=alpha -t frooodle/s-pdf:latest-lite-local -f ./Dockerfile-lite . + docker build --build-arg VERSION_TAG=alpha -t frooodle/s-pdf:latest-ultra-lite-local -f ./Dockerfile-ultra-lite . + + # Test each configuration + run_tests "Stirling-PDF-Ultra-Lite" "./exampleYmlFiles/docker-compose-latest-ultra-lite.yml" + run_tests "Stirling-PDF-Lite" "./exampleYmlFiles/docker-compose-latest-lite.yml" + run_tests "Stirling-PDF" "./exampleYmlFiles/docker-compose-latest.yml" + + export DOCKER_ENABLE_SECURITY=true + ./gradlew clean build + + # Building Docker images with security enabled + docker build --build-arg VERSION_TAG=alpha -t frooodle/s-pdf:latest-local -f ./Dockerfile . + docker build --build-arg VERSION_TAG=alpha -t frooodle/s-pdf:latest-lite-local -f ./Dockerfile-lite . + docker build --build-arg VERSION_TAG=alpha -t frooodle/s-pdf:latest-ultra-lite-local -f ./Dockerfile-ultra-lite . + + # Test each configuration with security + run_tests "Stirling-PDF-Ultra-Lite-Security" "./exampleYmlFiles/docker-compose-latest-ultra-lite-security.yml" + run_tests "Stirling-PDF-Lite-Security" "./exampleYmlFiles/docker-compose-latest-lite-security.yml" + run_tests "Stirling-PDF-Security" "./exampleYmlFiles/docker-compose-latest-security.yml" + + # Report results + echo "All tests completed." + + + + if [ ${#passed_tests[@]} -ne 0 ]; then + echo "Passed tests:" + fi + for test in "${passed_tests[@]}"; do + echo -e "\e[32m$test\e[0m" # Green color for passed tests + done + + if [ ${#failed_tests[@]} -ne 0 ]; then + echo "Failed tests:" + fi + for test in "${failed_tests[@]}"; do + echo -e "\e[31m$test\e[0m" # Red color for failed tests + done + + # Check if there are any failed tests and exit with an error code if so + if [ ${#failed_tests[@]} -ne 0 ]; then + echo "Some tests failed." + exit 1 + else + echo "All tests passed successfully." + exit 0 + fi + +} + +main