feat: enforce alphabetical server block ordering
Test nginx configuration / Static Analysis (pull_request) Failing after 6s
Test nginx configuration / nginx Syntax Check (pull_request) Successful in 24s
Security Scan and Upload / Security & DefectDojo Upload (pull_request) Successful in 1m59s

Adds test 13 to test.sh to verify that server blocks within each
sites-available file are sorted alphabetically by server_name
(LC_ALL=C; regex and wildcard entries excluded).

Fixes aria.conf and mommy.conf to conform: hyphenated names sort
before the bare domain in C locale ('-' < '.'), so trans-bot now
precedes trans, and mommy-slack now precedes mommy.
This commit is contained in:
2026-03-03 16:16:18 -08:00
committed by Naomi Carrigan
parent 493d758df8
commit 7085845234
3 changed files with 53 additions and 24 deletions
+29
View File
@@ -221,6 +221,35 @@ else
fi
echo ""
# ──────────────────────────────────────────────────────────────────
# 13. Server blocks within each sites-available file are sorted
# alphabetically by server_name (LC_ALL=C; regex/wildcard excluded)
# ──────────────────────────────────────────────────────────────────
echo "--- Alphabetical server_name order check ---"
sort_errors=0
for conf in "$NGINX_DIR/sites-available/"*.conf; do
[ "$(basename "$conf")" = "default" ] && continue
mapfile -t actual < <(grep -P '^\s*server_name\s' "$conf" \
| grep -v '^\s*#' \
| sed 's/.*server_name\s*//' \
| sed 's/\s*;//' \
| awk '{print $1}' \
| grep -vP '^~|^\*\.|^_$')
mapfile -t expected < <(printf '%s\n' "${actual[@]}" | LC_ALL=C sort)
for ((i = 0; i < ${#actual[@]}; i++)); do
if [ "${actual[$i]}" != "${expected[$i]}" ]; then
fail "$(basename "$conf"): not sorted — found '${actual[$i]}', expected '${expected[$i]}'"
sort_errors=1
break
fi
done
done
[ "$sort_errors" -eq 0 ] && pass "All sites-available files have alphabetically sorted server blocks"
echo ""
# ──────────────────────────────────────────────────────────────────
# Summary
# ──────────────────────────────────────────────────────────────────