feat: Add authentication debug and test scripts

- Add debug-auth.sh to diagnose authentication issues
  - Checks .env file content
  - Verifies environment variables in container
  - Tests bcrypt password verification
  - Shows config loading status
  - Displays recent auth logs

- Add test-auth-api.sh to test API endpoints directly
  - Tests login endpoint with curl
  - Shows raw API responses
  - Tests auth status endpoint

These scripts help troubleshoot authentication problems by showing
exactly what's happening at each step of the auth process.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-07-23 15:34:02 +02:00
parent d31f783c13
commit 6fda151dae
2 changed files with 101 additions and 0 deletions
+71
View File
@@ -0,0 +1,71 @@
#!/bin/bash
echo "======================================"
echo "MinIO WebUI - Auth Debug"
echo "======================================"
echo ""
# Check container
if docker ps | grep -q minio-webui-backend-dev; then
CONTAINER="minio-webui-backend-dev"
else
CONTAINER="minio-webui-backend"
fi
echo "1. Checking .env file on host:"
echo "------------------------------"
grep "ADMIN_PASSWORD_HASH\|JWT_SECRET" .env | head -20
echo ""
echo "2. Checking environment in container:"
echo "------------------------------------"
docker exec $CONTAINER sh -c 'echo "ADMIN_PASSWORD_HASH=$ADMIN_PASSWORD_HASH" | head -c 80'
echo ""
docker exec $CONTAINER sh -c 'echo "JWT_SECRET=$JWT_SECRET" | head -c 40'
echo ""
echo "3. Testing password directly in container:"
echo "-----------------------------------------"
docker exec $CONTAINER node -e "
const bcrypt = require('bcrypt');
const testHash = '$2b$12$LQv7c3SijBJLhSHPDOLkDe7YfPzFaXhJNXLKqFsFC37GA9xc1wSNi';
const envHash = process.env.ADMIN_PASSWORD_HASH;
console.log('Test hash (admin123):', testHash);
console.log('Env hash:', envHash ? envHash.substring(0, 20) + '...' : 'NOT SET');
console.log('Hashes match:', testHash === envHash);
bcrypt.compare('admin123', testHash).then(result => {
console.log('Test password "admin123" with hardcoded hash:', result);
});
if (envHash) {
bcrypt.compare('admin123', envHash).then(result => {
console.log('Test password "admin123" with env hash:', result);
}).catch(err => {
console.log('Error testing with env hash:', err.message);
});
}
"
echo ""
echo "4. Checking config loading:"
echo "--------------------------"
docker exec $CONTAINER node -e "
const config = require('./src/config');
console.log('Config auth:', {
hasPasswordHash: !!config.auth.adminPasswordHash,
hashLength: config.auth.adminPasswordHash ? config.auth.adminPasswordHash.length : 0,
hashPrefix: config.auth.adminPasswordHash ? config.auth.adminPasswordHash.substring(0, 7) : 'NOT SET',
hasJwtSecret: !!config.auth.jwtSecret,
env: config.app.env
});
"
echo ""
echo "5. Recent backend logs:"
echo "----------------------"
docker logs --tail 20 $CONTAINER 2>&1 | grep -E "(Password|AUTH|Login|401)"
echo ""
echo "======================================"
+30
View File
@@ -0,0 +1,30 @@
#!/bin/bash
echo "======================================"
echo "MinIO WebUI - Test Auth API"
echo "======================================"
echo ""
# Test with curl
echo "Testing login with curl..."
echo "--------------------------"
RESPONSE=$(curl -s -X POST http://localhost:7510/api/auth/login \
-H "Content-Type: application/json" \
-d '{"password":"admin123"}' \
-w "\nHTTP_STATUS:%{http_code}")
HTTP_STATUS=$(echo "$RESPONSE" | grep "HTTP_STATUS:" | cut -d: -f2)
BODY=$(echo "$RESPONSE" | sed '/HTTP_STATUS:/d')
echo "Response Status: $HTTP_STATUS"
echo "Response Body:"
echo "$BODY" | jq . 2>/dev/null || echo "$BODY"
echo ""
echo "Testing auth status..."
echo "---------------------"
curl -s http://localhost:7510/api/auth/status | jq . 2>/dev/null || curl -s http://localhost:7510/api/auth/status
echo ""
echo "======================================"