diff --git a/tests/README.md b/tests/README.md new file mode 100644 index 0000000..a4628a6 --- /dev/null +++ b/tests/README.md @@ -0,0 +1,27 @@ +# Bootstrap Server Tests + +## Running All Tests + +```bash +# Run all tests +./tests/run_all.sh + +# Run individual test suites +bash tests/test_setup.sh +bash tests/test_tor_config.sh +bash tests/test_caddy_config.sh +bash tests/test_generate_bootstrap.sh +``` + +## Test Suites + +| Test | Purpose | +|------|---------| +| `test_setup.sh` | Validates setup.sh structure, package installation, directory creation | +| `test_tor_config.sh` | Validates Tor hidden service configuration | +| `test_caddy_config.sh` | Validates Caddy web server configuration | +| `test_generate_bootstrap.sh` | Validates bootstrap archive generation and security | + +## Expected Results + +All tests should pass (0 failures). If any test fails, the exit code will be non-zero. diff --git a/tests/run_all.sh b/tests/run_all.sh new file mode 100755 index 0000000..bf114e2 --- /dev/null +++ b/tests/run_all.sh @@ -0,0 +1,41 @@ +#!/bin/bash +# Run all bootstrap server tests +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +cd "$SCRIPT_DIR/.." + +PASS=0 +FAIL=0 + +run_test() { + local name="$1"; shift + echo "" + echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" + echo " $name" + echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" + if bash "$@" 2>&1; then + echo " ✓ $name PASSED" + else + echo " ✗ $name FAILED" + ((FAIL++)) || true + fi +} + +echo "Running all Bootstrap Server tests..." +run_test "setup.sh" tests/test_setup.sh +run_test "Tor config" tests/test_tor_config.sh +run_test "Caddy config" tests/test_caddy_config.sh +run_test "Generate bootstrap" tests/test_generate_bootstrap.sh + +echo "" +echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" +echo " Summary" +echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" +if [ "$FAIL" -eq 0 ]; then + echo " ✓ All tests passed!" + exit 0 +else + echo " ✗ $FAIL test suite(s) failed" + exit 1 +fi diff --git a/tests/test_caddy_config.sh b/tests/test_caddy_config.sh new file mode 100755 index 0000000..327d06f --- /dev/null +++ b/tests/test_caddy_config.sh @@ -0,0 +1,36 @@ +#!/bin/bash +# Bootstrap server Caddy configuration tests +set -euo pipefail + +PASS=0 +FAIL=0 + +pass() { echo " ✓ $*"; ((PASS++)) || true; } +fail() { echo " ✗ $*"; ((FAIL++)) || true; } + +CADDY="/root/tri-bootstrap-server/caddy/Caddyfile.template" + +# Test 1: Caddyfile.template exists +echo "=== Test: Caddyfile.template exists ===" +[ -f "$CADDY" ] && pass "Caddyfile.template exists" || fail "Caddyfile.template missing" + +# Test 2: Has required Caddy settings +echo "=== Test: Caddy configuration ===" +grep -q "email" "$CADDY" && pass "Has email directive" || fail "Missing email directive" +grep -q "auto_https off" "$CADDY" && pass "Has auto_https off" || fail "Missing auto_https off" +grep -q "file_server" "$CADDY" && pass "Has file_server" || fail "Missing file_server" +grep -q "encode gzip" "$CADDY" && pass "Has gzip encoding" || fail "Missing gzip encoding" +grep -q "download true" "$CADDY" && pass "Has download directive" || fail "Missing download directive" + +# Test 3: Has Cache-Control headers for bootstrap files +echo "=== Test: Cache-Control headers ===" +grep -q "Cache-Control" "$CADDY" && pass "Has Cache-Control headers" || fail "Missing Cache-Control headers" + +# Test 4: Caddyfile has site block structure +echo "=== Test: Site block structure ===" +grep -qE "^\{" "$CADDY" && pass "Has global options block" || fail "Missing global options block" +grep -qE ":443|:80" "$CADDY" && pass "Has port binding" || fail "Missing port binding" + +echo "" +echo "Results: $PASS passed, $FAIL failed" +[ "$FAIL" -eq 0 ] diff --git a/tests/test_generate_bootstrap.sh b/tests/test_generate_bootstrap.sh new file mode 100755 index 0000000..7825c24 --- /dev/null +++ b/tests/test_generate_bootstrap.sh @@ -0,0 +1,34 @@ +#!/bin/bash +# Bootstrap server generate-bootstrap.sh tests +set -euo pipefail + +PASS=0 +FAIL=0 + +pass() { echo " ✓ $*"; ((PASS++)) || true; } +fail() { echo " ✗ $*"; ((FAIL++)) || true; } + +SCRIPT="/root/tri-bootstrap-server/scripts/generate-bootstrap.sh" + +# Test 1: generate-bootstrap.sh exists +echo "=== Test: generate-bootstrap.sh exists ===" +[ -f "$SCRIPT" ] && pass "generate-bootstrap.sh exists" || fail "generate-bootstrap.sh missing" + +# Test 2: Checks for required files before archiving +echo "=== Test: Bootstrap generation ===" +grep -qE "blk0001|blocks" "$SCRIPT" && pass "Checks blockchain data files" || fail "Missing blockchain data check" +grep -qE "txleveldb|database" "$SCRIPT" && pass "Checks database files" || fail "Missing database check" +grep -qE "tar|gzip|compress" "$SCRIPT" && pass "Uses compression/archiving" || fail "Missing compression" + +# Test 3: Excludes wallet and private data +echo "=== Test: Security - excludes private data ===" +grep -qE "exclude.*wallet|wallet.*exclude" "$SCRIPT" && pass "Excludes wallet data" || fail "Wallet data exclusion missing" +grep -qE "exclude.*onion|exclude.*tor_data|exclude.*debug" "$SCRIPT" && pass "Excludes private runtime data" || fail "Private runtime data exclusion missing" + +# Test 4: verify-bootstrap.sh exists and functional +echo "=== Test: verify-bootstrap.sh exists ===" +[ -f "/root/tri-bootstrap-server/scripts/verify-bootstrap.sh" ] && pass "verify-bootstrap.sh exists" || fail "verify-bootstrap.sh missing" + +echo "" +echo "Results: $PASS passed, $FAIL failed" +[ "$FAIL" -eq 0 ] diff --git a/tests/test_setup.sh b/tests/test_setup.sh new file mode 100755 index 0000000..7ff3cc0 --- /dev/null +++ b/tests/test_setup.sh @@ -0,0 +1,50 @@ +#!/bin/bash +# Bootstrap server setup.sh tests +set -euo pipefail + +PASS=0 +FAIL=0 + +pass() { echo " ✓ $*"; ((PASS++)) || true; } +fail() { echo " ✗ $*"; ((FAIL++)) || true; } + +SCRIPT="/root/tri-bootstrap-server/scripts/setup.sh" + +# Test 1: setup.sh exists and is executable +echo "=== Test: setup.sh exists ===" +[ -f "$SCRIPT" ] && pass "setup.sh exists" || fail "setup.sh missing" +[ -x "$SCRIPT" ] 2>/dev/null && pass "setup.sh is executable" || pass "setup.sh not executable (ok)" + +# Test 2: setup.sh has required functions/sections +echo "=== Test: setup.sh structure ===" +# Use case-insensitive grep +grep -qi "detect os\|operating system" "$SCRIPT" && pass "Has OS detection" || fail "Missing OS detection" +grep -qi "install" "$SCRIPT" && pass "Has install section" || fail "Missing install section" +grep -qi "directory" "$SCRIPT" && pass "Has directory creation" || fail "Missing directory creation" +grep -qi "tor" "$SCRIPT" && pass "Has Tor configuration" || fail "Missing Tor configuration" +grep -qi "caddy" "$SCRIPT" && pass "Has Caddy configuration" || fail "Missing Caddy configuration" +grep -qi "systemctl\|service" "$SCRIPT" && pass "Has service management" || fail "Missing service management" + +# Test 3: setup.sh installs required packages +echo "=== Test: Required packages ===" +for pkg in "tor" "caddy" "wget" "curl" "jq"; do + grep -qi "install.*$pkg" "$SCRIPT" 2>/dev/null && pass "Installs $pkg" || fail "Missing $pkg install" +done + +# Test 4: setup.sh creates required directories +echo "=== Test: Directory creation ===" +for dir in "/var/www/triangles-bootstrap" "/etc/tor/tri-bootstrap" "/var/lib/tor/tri-bootstrap" "/var/log/tri-bootstrap"; do + grep -q "$dir" "$SCRIPT" 2>/dev/null && pass "Creates $dir" || fail "Missing $dir" +done + +# Test 5: setup.sh copies torrc from template +echo "=== Test: Tor config from template ===" +grep -q "tor/torrc.template" "$SCRIPT" 2>/dev/null && pass "Copies torrc from template" || fail "Missing torrc template copy" + +# Test 6: setup.sh has systemd service setup +echo "=== Test: Systemd services ===" +grep -qi "systemctl enable" "$SCRIPT" && pass "Enables services with systemctl" || fail "Missing systemctl enable" + +echo "" +echo "Results: $PASS passed, $FAIL failed" +[ "$FAIL" -eq 0 ] diff --git a/tests/test_tor_config.sh b/tests/test_tor_config.sh new file mode 100755 index 0000000..9b2753d --- /dev/null +++ b/tests/test_tor_config.sh @@ -0,0 +1,30 @@ +#!/bin/bash +# Bootstrap server Tor configuration tests +set -euo pipefail + +PASS=0 +FAIL=0 + +pass() { echo " ✓ $*"; ((PASS++)) || true; } +fail() { echo " ✗ $*"; ((FAIL++)) || true; } + +TORRC="/root/tri-bootstrap-server/tor/torrc.template" + +# Test 1: torrc.template exists +echo "=== Test: torrc.template exists ===" +[ -f "$TORRC" ] && pass "torrc.template exists" || fail "torrc.template missing" + +# Test 2: Has required Tor settings +echo "=== Test: Tor configuration ===" +grep -q "HiddenServiceDir" "$TORRC" && pass "Has HiddenServiceDir" || fail "Missing HiddenServiceDir" +grep -q "HiddenServiceVersion 3" "$TORRC" && pass "Uses V3 onion service" || fail "Missing V3 onion config" +grep -q "HiddenServicePort" "$TORRC" && pass "Has HiddenServicePort" || fail "Missing HiddenServicePort" +grep -q "ExcludeSingleHopRelays" "$TORRC" && pass "Has ExcludeSingleHopRelays" || fail "Missing ExcludeSingleHopRelays" + +# Test 3: Has correct Tor port mappings +echo "=== Test: Port mappings ===" +grep -q "HiddenServicePort 80" "$TORRC" && pass "Maps HS port 80" || fail "Missing HS port 80" + +echo "" +echo "Results: $PASS passed, $FAIL failed" +[ "$FAIL" -eq 0 ]