mirror of
https://github.com/selfhosters-cc/container-census.git
synced 2026-01-04 12:59:43 -06:00
Prevent regression of the "authUsername is not defined" error by adding comprehensive tests and pre-commit hooks. New test files: - scripts/test-auth-migration.sh: Full test suite (8 test cases) * Checks for obsolete auth variable references * Validates session management implementation * Verifies vulnerability functions use correct auth * Tests logout button and documentation - scripts/pre-commit-hook.sh: Git pre-commit hook * Blocks commits containing authUsername/authPassword * Provides helpful error messages * Can be installed with symlink - scripts/TESTING.md: Testing documentation * How to run tests * How to install pre-commit hook * Correct vs incorrect auth patterns * Troubleshooting guide All tests currently passing (8/8). Pre-commit hook validated. These tests ensure the session-based authentication migration remains complete and prevent accidental reintroduction of removed Basic Auth variables. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
26 lines
975 B
Bash
Executable File
26 lines
975 B
Bash
Executable File
#!/bin/bash
|
|
# Git pre-commit hook to prevent authentication regressions
|
|
#
|
|
# To install: ln -s ../../scripts/pre-commit-hook.sh .git/hooks/pre-commit
|
|
|
|
# Quick check for authUsername/authPassword in staged JS/HTML files
|
|
if git diff --cached --name-only | grep -E '\.(js|html)$' | xargs grep -n "authUsername\|authPassword" 2>/dev/null; then
|
|
echo ""
|
|
echo "❌ COMMIT BLOCKED: Found references to authUsername or authPassword"
|
|
echo ""
|
|
echo "These variables were removed during session-based auth migration."
|
|
echo "Use session cookies for authentication (they're sent automatically)."
|
|
echo ""
|
|
echo "If you need to add authentication to a fetch call, simply use:"
|
|
echo " fetch('/api/endpoint') // Session cookie is sent automatically"
|
|
echo ""
|
|
echo "NOT:"
|
|
echo " fetch('/api/endpoint', {"
|
|
echo " headers: { 'Authorization': 'Basic ' + btoa(authUsername + ':' + authPassword) }"
|
|
echo " })"
|
|
echo ""
|
|
exit 1
|
|
fi
|
|
|
|
exit 0
|