This commit is contained in:
Waylon Walker 2025-11-21 13:13:57 -06:00
parent 13b6d1b78a
commit 298d3223f0
4 changed files with 64 additions and 7 deletions

View file

@ -1,3 +1,6 @@
default:
@just --choose
start-auth:
./main_auth.py &
@ -18,3 +21,60 @@ logs-nginx:
stop-nginx:
docker stop nginx
# JWT Authentication Tests
test-login-admin:
@echo "=== Testing admin login ==="
curl -c admin_cookies.txt -X POST \
-H "Authorization: Basic $(echo -n 'admin:admin' | base64)" \
http://localhost:8000/login 2>/dev/null
@echo "\n✅ Admin logged in, cookies saved to admin_cookies.txt"
test-login-reader:
@echo "=== Testing reader login ==="
curl -c reader_cookies.txt -X POST \
-H "Authorization: Basic $(echo -n 'reader:reader' | base64)" \
http://localhost:8000/login 2>/dev/null
@echo "\n✅ Reader logged in, cookies saved to reader_cookies.txt"
test-admin-access:
@echo "=== Testing admin access to /admin/ ==="
@curl -b admin_cookies.txt -w "Status: %{http_code}" \
http://localhost:8000/admin/ 2>/dev/null | tail -1
@echo "\n✅ Admin should have 200 status"
test-reader-blocked:
@echo "=== Testing reader blocked from /admin/ ==="
@curl -b reader_cookies.txt -w "Status: %{http_code}" \
http://localhost:8000/admin/ 2>/dev/null | tail -1
@echo "\n🚫 Reader should have 403 status"
test-whoami-admin:
@echo "=== Admin user info ==="
@curl -b admin_cookies.txt http://localhost:5115/me 2>/dev/null | jq .
test-whoami-reader:
@echo "=== Reader user info ==="
@curl -b reader_cookies.txt http://localhost:5115/me 2>/dev/null | jq .
test-logout:
@echo "=== Testing logout ==="
curl -b admin_cookies.txt http://localhost:8000/logout 2>/dev/null
@echo "✅ Logged out"
test-full-flow:
@echo "🔐 Running full JWT authentication test suite"
@echo "================================================="
just test-login-admin
just test-login-reader
just test-whoami-admin
just test-whoami-reader
just test-admin-access
just test-reader-blocked
@echo "================================================="
@echo "✅ All tests completed!"
clean-cookies:
@echo "🧹 Cleaning up cookie files"
rm -f admin_cookies.txt reader_cookies.txt cookies.txt
@echo "✅ Cookies cleaned"