learn-nginx-auth/justfile
2025-11-21 13:47:16 -06:00

80 lines
2.4 KiB
Makefile

default:
@just --choose
start-auth:
./main_auth.py
stop-auth:
pkill -f main_auth.py || true
start-nginx:
docker run \
--rm \
--name nginx \
--network host \
-v "$PWD/site":/usr/share/nginx/html:ro \
-v "$PWD/nginx.conf":/etc/nginx/nginx.conf:ro \
docker.io/library/nginx
logs-nginx:
docker logs -f 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"