Revise tests. Use docker-compose.yml where possible

This commit is contained in:
Adam Outler
2025-10-31 22:24:08 +00:00
parent d29700acf8
commit 1e63cec37c
31 changed files with 1311 additions and 526 deletions

View File

@@ -0,0 +1,49 @@
services:
netalertx:
# Missing capabilities configuration for testing
network_mode: ${NETALERTX_NETWORK_MODE:-host}
build:
context: ../../../
dockerfile: Dockerfile
image: netalertx-test
container_name: netalertx-test-missing-caps
read_only: true
cap_drop:
- ALL # Drop all capabilities to test missing capabilities scenario
volumes:
- type: volume
source: netalertx_config
target: /app/config
read_only: false
- type: volume
source: netalertx_db
target: /app/db
read_only: false
- type: bind
source: /etc/localtime
target: /etc/localtime
read_only: true
environment:
LISTEN_ADDR: ${LISTEN_ADDR:-0.0.0.0}
PORT: ${PORT:-20211}
APP_CONF_OVERRIDE: ${GRAPHQL_PORT:-20212}
ALWAYS_FRESH_INSTALL: ${ALWAYS_FRESH_INSTALL:-false}
NETALERTX_DEBUG: ${NETALERTX_DEBUG:-0}
mem_limit: 2048m
mem_reservation: 1024m
cpu_shares: 512
pids_limit: 512
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
volumes:
netalertx_config:
netalertx_db:

View File

@@ -1,3 +1,7 @@
# Expected outcome: Container starts successfully with proper nginx config mount
# - SYSTEM_SERVICES_ACTIVE_CONFIG shows as writable and mounted
# - No configuration warnings for nginx config path
# - Custom PORT configuration should work when nginx config is writable
services:
netalertx:
network_mode: host

View File

@@ -1,3 +1,7 @@
# Expected outcome: Container shows warning about missing nginx config mount
# - SYSTEM_SERVICES_ACTIVE_CONFIG shows as not mounted
# - Warning message about nginx configuration mount being missing
# - Custom PORT configuration may not work properly
services:
netalertx:
network_mode: host

View File

@@ -1,3 +1,7 @@
# Expected outcome: Container shows performance warning for nginx config on RAM disk
# - SYSTEM_SERVICES_ACTIVE_CONFIG shows as mounted on tmpfs (RAM disk)
# - Performance issue warning since nginx config should be persistent
# - Custom PORT configuration may have performance implications
services:
netalertx:
network_mode: host

View File

@@ -1,3 +1,7 @@
# Expected outcome: Container fails to start due to unwritable nginx config partition
# - SYSTEM_SERVICES_ACTIVE_CONFIG shows as mounted but unwritable (❌ in Writeable column)
# - 35-nginx-config.sh detects permission error and exits with code 1
# - Container startup fails because nginx configuration cannot be written for custom ports
services:
netalertx:
network_mode: host

View File

@@ -1,3 +1,7 @@
# Expected outcome: Container starts successfully with proper API mount
# - NETALERTX_API shows as writable and mounted
# - No configuration warnings for API path
# - API data persistence works correctly
services:
netalertx:
network_mode: host

View File

@@ -1,3 +1,7 @@
# Expected outcome: Container shows mount error for API directory
# - NETALERTX_API shows as not mounted
# - Mount error since API directory should be mounted for proper operation
# - API functionality may be limited
services:
netalertx:
network_mode: host

View File

@@ -1,3 +1,7 @@
# Expected outcome: Container shows performance warning for API on RAM disk
# - NETALERTX_API shows as mounted on tmpfs (RAM disk)
# - Performance issue warning since API data should be on persistent storage
# - API data will be lost on container restart
services:
netalertx:
network_mode: host

View File

@@ -1,3 +1,7 @@
# Expected outcome: Container fails to start due to unwritable API partition
# - NETALERTX_API shows as mounted but unwritable (❌ in Writeable column)
# - API directory must be writable for proper operation
# - Container startup fails because API functionality cannot work without write access
services:
netalertx:
network_mode: host

View File

@@ -1,3 +1,7 @@
# Expected outcome: Container starts successfully with proper config mount
# - NETALERTX_CONFIG shows as writable and mounted
# - No configuration warnings for config path
# - Configuration persistence works correctly
services:
netalertx:
network_mode: host

View File

@@ -1,3 +1,7 @@
# Expected outcome: Container shows mount error for config directory
# - NETALERTX_CONFIG shows as not mounted
# - Mount error since config directory should be mounted for proper operation
# - Configuration may not persist across restarts
services:
netalertx:
network_mode: host

View File

@@ -1,3 +1,7 @@
# Expected outcome: Container shows dataloss risk warning for config on RAM disk
# - NETALERTX_CONFIG shows as mounted on tmpfs (RAM disk)
# - Dataloss risk warning since config data should be persistent
# - Configuration will be lost on container restart
services:
netalertx:
network_mode: host

View File

@@ -1,3 +1,7 @@
# Expected outcome: Container fails to start due to unwritable config partition
# - NETALERTX_CONFIG shows as mounted but unwritable (❌ in Writeable column)
# - 30-writable-config.sh detects permission error and exits with code 1
# - Container startup fails because config files cannot be written to
services:
netalertx:
network_mode: host

View File

@@ -1,3 +1,7 @@
# Expected outcome: Container starts successfully with proper database mount
# - NETALERTX_DB shows as writable and mounted
# - No configuration warnings for database path
# - Database persistence works correctly
services:
netalertx:
network_mode: host

View File

@@ -1,3 +1,7 @@
# Expected outcome: Container shows mount error warning but continues running
# - NETALERTX_DB shows as not mounted (❌ in Mount column) but path gets created
# - Warning message displayed about configuration issues
# - Container continues because database directory can be created in writable filesystem
services:
netalertx:
network_mode: host

View File

@@ -1,3 +1,7 @@
# Expected outcome: Container shows dataloss risk warning for database on RAM disk
# - NETALERTX_DB shows as mounted on tmpfs (RAM disk)
# - Dataloss risk warning since database should be persistent
# - Database will be lost on container restart
services:
netalertx:
network_mode: host

View File

@@ -1,3 +1,7 @@
# Expected outcome: Container fails to start due to unwritable database partition
# - NETALERTX_DB shows as mounted but unwritable (❌ in Writeable column)
# - 30-writable-config.sh detects permission error and exits with code 1
# - Container startup fails because database files cannot be written to
services:
netalertx:
network_mode: host

View File

@@ -1,3 +1,7 @@
# Expected outcome: Container starts successfully with proper log mount
# - NETALERTX_LOG shows as mounted and writable
# - No mount warnings since logs can be non-persistent
# - Container starts normally with logging enabled
services:
netalertx:
network_mode: host

View File

@@ -1,3 +1,7 @@
# Expected outcome: Container shows mount error warning but continues running
# - NETALERTX_LOG shows as not mounted (❌ in Mount column)
# - Warning message displayed about configuration issues
# - Container continues to run despite the mount error
services:
netalertx:
network_mode: host

View File

@@ -1,3 +1,7 @@
# Expected outcome: Container shows dataloss risk warning for logs on RAM disk
# - NETALERTX_LOG shows as mounted on tmpfs (RAM disk)
# - Dataloss risk warning since logs may be lost on restart
# - Container starts but logs may not persist
services:
netalertx:
network_mode: host

View File

@@ -1,3 +1,7 @@
# Expected outcome: Container fails to start due to unwritable log partition
# - NETALERTX_LOG shows as mounted but unwritable (❌ in Writeable column)
# - 25-mandatory-folders.sh cannot create required log files and fails
# - Container startup fails because logging infrastructure cannot be initialized
services:
netalertx:
network_mode: host

View File

@@ -1,3 +1,7 @@
# Expected outcome: Container starts successfully with proper run mount
# - NETALERTX_RUN shows as mounted and writable
# - No mount warnings since run directory can be non-persistent
# - Container starts normally with runtime files enabled
services:
netalertx:
network_mode: host

View File

@@ -1,3 +1,7 @@
# Expected outcome: Container shows mount error warning but continues running
# - NETALERTX_RUN shows as not mounted (❌ in Mount column)
# - Warning message displayed about configuration issues
# - Container continues to run despite the mount error
services:
netalertx:
network_mode: host

View File

@@ -1,3 +1,7 @@
# Expected outcome: Container shows dataloss risk warning for run on RAM disk
# - NETALERTX_RUN shows as mounted on tmpfs (RAM disk)
# - Dataloss risk warning since runtime files may be lost on restart
# - Container starts but runtime state may not persist
services:
netalertx:
network_mode: host

View File

@@ -1,3 +1,7 @@
# Expected outcome: Container fails to start due to unwritable run partition
# - NETALERTX_RUN shows as mounted but unwritable (❌ in Writeable column)
# - 25-mandatory-folders.sh cannot create required runtime files and fails
# - Container startup fails because runtime infrastructure cannot be initialized
services:
netalertx:
network_mode: host

View File

@@ -0,0 +1,69 @@
#!/bin/bash
# test_all_docker_composes.sh - Test all docker-compose configurations
# Extracts comments from each file and runs the container for 10 seconds
LOG_FILE="/workspaces/NetAlertX/test/docker_tests/configurations/test_results.log"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
echo "Starting Docker Compose Tests - $(date)" > "$LOG_FILE"
echo "==========================================" >> "$LOG_FILE"
# Function to extract comments from docker-compose file
extract_comments() {
local file="$1"
echo "File: $(basename "$file")" >> "$LOG_FILE"
echo "----------------------------------------" >> "$LOG_FILE"
# Extract lines starting with # until we hit a non-comment line
awk '
/^#/ {
# Remove the # and any leading/trailing whitespace
comment = substr($0, 2)
sub(/^ */, "", comment)
sub(/ *$/, "", comment)
if (comment != "") {
print comment
}
}
/^[^#]/ && !/^$/ {
exit
}
' "$file" >> "$LOG_FILE"
echo "" >> "$LOG_FILE"
}
# Function to run docker-compose test
run_test() {
local file="$1"
local dirname=$(dirname "$file")
local basename=$(basename "$file")
echo "Testing: $basename" >> "$LOG_FILE"
echo "Directory: $dirname" >> "$LOG_FILE"
echo "" >> "$LOG_FILE"
# Change to the directory containing the docker-compose file
cd "$dirname"
# Run docker-compose up with timeout
echo "Running docker-compose up..." >> "$LOG_FILE"
timeout 10s docker-compose -f "$basename" up 2>&1 >> "$LOG_FILE"
# Clean up
docker-compose -f "$basename" down -v 2>/dev/null || true
docker volume prune -f 2>/dev/null || true
echo "" >> "$LOG_FILE"
echo "==========================================" >> "$LOG_FILE"
echo "" >> "$LOG_FILE"
}
# Find all docker-compose files
find "$SCRIPT_DIR" -name "docker-compose*.yml" -type f | sort | while read -r file; do
extract_comments "$file"
run_test "$file"
done
echo "All tests completed - $(date)" >> "$LOG_FILE"
echo "Results saved to: $LOG_FILE"

View File

@@ -0,0 +1,150 @@
Starting Docker Compose Tests - Fri Oct 31 20:00:39 UTC 2025
==========================================
File: docker-compose.missing-caps.yml
----------------------------------------
Testing: docker-compose.missing-caps.yml
Directory: /workspaces/NetAlertX/test/docker_tests/configurations
Running docker-compose up...
Attaching to netalertx-test-missing-caps
netalertx-test-missing-caps exited with code 255
==========================================
File: docker-compose.readonly.yml
----------------------------------------
Testing: docker-compose.readonly.yml
Directory: /workspaces/NetAlertX/test/docker_tests/configurations
Running docker-compose up...
Attaching to netalertx-test-readonly
netalertx-test-readonly | 
netalertx-test-readonly | _ _ _ ___ _ _ __ __
netalertx-test-readonly | | \ | | | | / _ \| | | | \ \ / /
netalertx-test-readonly | | \| | ___| |_/ /_\ \ | ___ _ __| |_ \ V /
netalertx-test-readonly | | . |/ _ \ __| _ | |/ _ \ __| __|/ \
netalertx-test-readonly | | |\ | __/ |_| | | | | __/ | | |_/ /^\ \
netalertx-test-readonly | \_| \_/\___|\__\_| |_/_|\___|_| \__\/ \/
netalertx-test-readonly |
netalertx-test-readonly |  Network intruder and presence detector.
netalertx-test-readonly | https://netalertx.com
netalertx-test-readonly |
netalertx-test-readonly |
netalertx-test-readonly | Startup pre-checks
netalertx-test-readonly | --> storage permission
netalertx-test-readonly | --> mounts.py
netalertx-test-readonly | --> first run config
netalertx-test-readonly | --> first run db
netalertx-test-readonly | --> mandatory folders
netalertx-test-readonly | --> writable config
netalertx-test-readonly | --> nginx config
netalertx-test-readonly | nginx config: FAILED with 1
netalertx-test-readonly | Failure detected in: /entrypoint.d/35-nginx-config.sh
netalertx-test-readonly | --> user netalertx
netalertx-test-readonly | --> host mode network
netalertx-test-readonly | --> layer 2 capabilities
netalertx-test-readonly | --> excessive capabilities
netalertx-test-readonly | excessive capabilities: FAILED with 2
netalertx-test-readonly | Failure detected in: /entrypoint.d/90-excessive-capabilities.sh
netalertx-test-readonly | --> appliance integrity
netalertx-test-readonly | --> ports available
netalertx-test-readonly | ══════════════════════════════════════════════════════════════════════════════
netalertx-test-readonly | ⚠️ Port Warning: Application port 20211 is already in use.
netalertx-test-readonly |
netalertx-test-readonly | The main application (defined by $PORT) may fail to start.
netalertx-test-readonly |
netalertx-test-readonly | https://github.com/jokob-sk/NetAlertX/blob/main/docs/docker-troubleshooting/port-conflicts.md
netalertx-test-readonly | ══════════════════════════════════════════════════════════════════════════════
netalertx-test-readonly | ══════════════════════════════════════════════════════════════════════════════
netalertx-test-readonly | ⚠️ Port Warning: GraphQL API port 20212 is already in use.
netalertx-test-readonly |
netalertx-test-readonly | The GraphQL API (defined by $APP_CONF_OVERRIDE or $GRAPHQL_PORT)
netalertx-test-readonly | may fail to start.
netalertx-test-readonly |
netalertx-test-readonly | https://github.com/jokob-sk/NetAlertX/blob/main/docs/docker-troubleshooting/port-conflicts.md
netalertx-test-readonly | ══════════════════════════════════════════════════════════════════════════════
netalertx-test-readonly | Container startup checks failed with exit code 2.
netalertx-test-readonly | NETALERTX_DEBUG is set to 1, will not shut down other services if one fails.
netalertx-test-readonly | Starting /usr/sbin/crond -c "/services/config/crond" -f -L "/app/log/crond.log" >>"/app/log/crond.log" 2>&1 &
netalertx-test-readonly | Starting /usr/sbin/php-fpm83 -y "/services/config/php/php-fpm.conf" -F >>"/app/log/app.php_errors.log" 2>/dev/stderr &
netalertx-test-readonly | Crond stopped! (exit 1)
netalertx-test-readonly | php-fpm stopped! (exit 1)
netalertx-test-readonly | Starting python3 -m server > /app/log/stdout.log 2> >(tee /app/log/stderr.log >&2)
netalertx-test-readonly exited with code 0
netalertx-test-readonly | --> first run config
netalertx-test-readonly | --> first run db
netalertx-test-readonly | --> mandatory folders
netalertx-test-readonly | --> writable config
netalertx-test-readonly | --> nginx config
netalertx-test-readonly | nginx config: FAILED with 1
netalertx-test-readonly | Failure detected in: /entrypoint.d/35-nginx-config.sh
netalertx-test-readonly | --> user netalertx
netalertx-test-readonly | --> host mode network
netalertx-test-readonly | --> layer 2 capabilities
netalertx-test-readonly | --> excessive capabilities
netalertx-test-readonly | excessive capabilities: FAILED with 2
netalertx-test-readonly | Failure detected in: /entrypoint.d/90-excessive-capabilities.sh
netalertx-test-readonly | --> appliance integrity
netalertx-test-readonly | --> ports available
netalertx-test-readonly | ══════════════════════════════════════════════════════════════════════════════
netalertx-test-readonly | ⚠️ Port Warning: Application port 20211 is already in use.
netalertx-test-readonly |
netalertx-test-readonly | The main application (defined by $PORT) may fail to start.
netalertx-test-readonly |
netalertx-test-readonly | https://github.com/jokob-sk/NetAlertX/blob/main/docs/docker-troubleshooting/port-conflicts.md
netalertx-test-readonly | ══════════════════════════════════════════════════════════════════════════════
netalertx-test-readonly | ══════════════════════════════════════════════════════════════════════════════
netalertx-test-readonly | ⚠️ Port Warning: GraphQL API port 20212 is already in use.
netalertx-test-readonly |
netalertx-test-readonly | The GraphQL API (defined by $APP_CONF_OVERRIDE or $GRAPHQL_PORT)
netalertx-test-readonly | may fail to start.
netalertx-test-readonly |
netalertx-test-readonly | https://github.com/jokob-sk/NetAlertX/blob/main/docs/docker-troubleshooting/port-conflicts.md
netalertx-test-readonly | ══════════════════════════════════════════════════════════════════════════════
netalertx-test-readonly | Container startup checks failed with exit code 2.
netalertx-test-readonly | NETALERTX_DEBUG is set to 1, will not shut down other services if one fails.
netalertx-test-readonly | Starting /usr/sbin/crond -c "/services/config/crond" -f -L "/app/log/crond.log" >>"/app/log/crond.log" 2>&1 &
netalertx-test-readonly | Starting /usr/sbin/php-fpm83 -y "/services/config/php/php-fpm.conf" -F >>"/app/log/app.php_errors.log" 2>/dev/stderr &
netalertx-test-readonly | php-fpm stopped! (exit 1)
netalertx-test-readonly | Crond stopped! (exit 1)
netalertx-test-readonly | Starting python3 -m server > /app/log/stdout.log 2> >(tee /app/log/stderr.log >&2)
==========================================
File: docker-compose.writable.yml
----------------------------------------
Testing: docker-compose.writable.yml
Directory: /workspaces/NetAlertX/test/docker_tests/configurations
Running docker-compose up...
==========================================
File: docker-compose.mount-test.active_config_mounted.yml
----------------------------------------
Expected outcome: Container starts successfully with proper nginx config mount
- SYSTEM_SERVICES_ACTIVE_CONFIG shows as writable and mounted
- No configuration warnings for nginx config path
- Custom PORT configuration should work when nginx config is writable
Testing: docker-compose.mount-test.active_config_mounted.yml
Directory: /workspaces/NetAlertX/test/docker_tests/configurations/mount-tests
Running docker-compose up...
==========================================
File: docker-compose.mount-test.active_config_no-mount.yml
----------------------------------------
Expected outcome: Container shows warning about missing nginx config mount
- SYSTEM_SERVICES_ACTIVE_CONFIG shows as not mounted
- Warning message about nginx configuration mount being missing
- Custom PORT configuration may not work properly
Testing: docker-compose.mount-test.active_config_no-mount.yml
Directory: /workspaces/NetAlertX/test/docker_tests/configurations/mount-tests