The watcher only matched */public_html/.htaccess, so sites with a document-root folder (docRoot public_html/<sub>) never triggered a reload. Match .htaccess directly inside any docRoot taken from the rendered $SITES_ROOT/*/vhconf.conf (set refreshed only when httpd_config.conf changes); legacy match kept as fallback when the set is empty. Deep plugin .htaccess files still do not trigger. Adds a stubbed-lswsctrl test and CI wiring. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6
75 lines
3.7 KiB
Bash
Executable File
75 lines
3.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
## ols-htaccess-watcher.test.sh — runs scripts/ols-htaccess-watcher.sh against a
|
|
## temp tree with a stub lswsctrl (no OLS needed). Checks that a restart fires
|
|
## for .htaccess directly inside any vhost docRoot (including a document-root
|
|
## folder docRoot like public_html/public), and NOT for deeper plugin-style
|
|
## .htaccess files or an unrelated dir. Skips if inotifywait is unavailable.
|
|
set -euo pipefail
|
|
HERE=$(cd "$(dirname "$0")/.." && pwd)
|
|
W="$HERE/ols-htaccess-watcher.sh"
|
|
if ! command -v inotifywait >/dev/null 2>&1; then
|
|
echo "SKIP - inotifywait (inotify-tools) not installed; watcher test not run"; exit 0
|
|
fi
|
|
T=$(mktemp -d)
|
|
WPID=""
|
|
cleanup() { [ -n "$WPID" ] && kill "$WPID" 2>/dev/null || true; pkill -P "${WPID:-0}" 2>/dev/null || true; rm -rf "$T"; }
|
|
trap cleanup EXIT
|
|
fail=0
|
|
ok() { echo "ok - $1"; }
|
|
bad() { echo "FAIL - $1"; fail=1; }
|
|
|
|
U="$T/users"; CONF="$T/conf"; SITES="$CONF/shared-sites"
|
|
mkdir -p "$U/u1/a.example/public_html/wp-content/cache/x" "$U/u2/b.example/public_html/public" \
|
|
"$U/u2/b.example/public_html/web/app" "$U/u3/c.example/public_html" "$SITES/a" "$SITES/b" "$SITES/c" "$SITES/bad"
|
|
printf 'docRoot %s\n' "$U/u1/a.example/public_html" >"$SITES/a/vhconf.conf"
|
|
printf 'docRoot %s\n' "$U/u2/b.example/public_html/public" >"$SITES/b/vhconf.conf"
|
|
printf 'docRoot %s\n' "$U/u2/b.example/public_html/web/app/" >"$SITES/c/vhconf.conf"
|
|
printf 'docRoot $VH_ROOT/html\ndocRoot relative/path\ndocRoot /x/../etc\n' >"$SITES/bad/vhconf.conf"
|
|
echo '# cfg' >"$CONF/httpd_config.conf"
|
|
|
|
cat >"$T/lswsctrl" <<EOS
|
|
#!/bin/sh
|
|
echo x >>"$T/restarts"
|
|
EOS
|
|
chmod +x "$T/lswsctrl"
|
|
: >"$T/restarts"; : >"$T/log"
|
|
|
|
start() {
|
|
env OLS_WATCH_ROOT="$U" OLS_LSWS_CONF="$CONF" OLS_SITES_ROOT="$SITES" LSWSCTRL="$T/lswsctrl" \
|
|
OLS_HTACCESS_DEBOUNCE=1 OLS_HTACCESS_FLOOR=0 "$W" 2>"$T/log" &
|
|
WPID=$!
|
|
sleep 1.5
|
|
}
|
|
count() { wc -l <"$T/restarts" | tr -d ' '; }
|
|
## touch file, wait, expect restart count delta (want 1 or 0)
|
|
check() { # name want path
|
|
local before after; before=$(count)
|
|
echo "# $(date +%s%N)" >>"$3"
|
|
sleep 5
|
|
after=$(count)
|
|
if [ $((after - before)) -eq "$2" ]; then ok "$1"; else bad "$1 (restarts +$((after - before)), want +$2)"; fi
|
|
}
|
|
|
|
start
|
|
check "plain site docRoot .htaccess triggers" 1 "$U/u1/a.example/public_html/.htaccess"
|
|
check "folder docRoot (public_html/public) triggers" 1 "$U/u2/b.example/public_html/public/.htaccess"
|
|
check "trailing-slash docRoot (public_html/web/app) triggers" 1 "$U/u2/b.example/public_html/web/app/.htaccess"
|
|
check "plugin deep file (wp-content/cache) does NOT" 0 "$U/u1/a.example/public_html/wp-content/cache/x/.htaccess"
|
|
check "public_html/.htaccess of a site with folder docRoot does NOT (OLS ignores it)" 0 "$U/u2/b.example/public_html/.htaccess"
|
|
check "unregistered tenant public_html/.htaccess does NOT while set is non-empty" 0 "$U/u3/c.example/public_html/.htaccess"
|
|
|
|
## New site provisioned live + atomic re-render -> set refreshed
|
|
mkdir -p "$U/u4/d.example/public_html/pub"
|
|
mkdir -p "$SITES/d"; printf 'docRoot %s\n' "$U/u4/d.example/public_html/pub" >"$SITES/d/vhconf.conf"
|
|
echo '# cfg2' >"$CONF/.tmp" && mv "$CONF/.tmp" "$CONF/httpd_config.conf"
|
|
check "site added after start (re-render) triggers" 1 "$U/u4/d.example/public_html/pub/.htaccess"
|
|
kill "$WPID" 2>/dev/null || true; pkill -P "$WPID" 2>/dev/null || true; WPID=""
|
|
|
|
## Fallback: no vhconf files -> legacy */public_html/.htaccess match
|
|
rm -rf "$SITES"; mkdir -p "$SITES"
|
|
start
|
|
check "fallback (empty docRoot set): public_html/.htaccess triggers" 1 "$U/u3/c.example/public_html/.htaccess"
|
|
check "fallback: deep plugin file still does NOT" 0 "$U/u1/a.example/public_html/wp-content/cache/x/.htaccess"
|
|
|
|
[ "$fail" -eq 0 ] && echo "ALL PASS" || { echo "FAILURES"; cat "$T/log"; exit 1; }
|