From 6fda151daececcbfab6a10087742f52bc654059d Mon Sep 17 00:00:00 2001 From: paul Date: Wed, 23 Jul 2025 15:34:02 +0200 Subject: [PATCH] feat: Add authentication debug and test scripts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- scripts/debug-auth.sh | 71 ++++++++++++++++++++++++++++++++++++++++ scripts/test-auth-api.sh | 30 +++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100755 scripts/debug-auth.sh create mode 100755 scripts/test-auth-api.sh diff --git a/scripts/debug-auth.sh b/scripts/debug-auth.sh new file mode 100755 index 0000000..e8dfea7 --- /dev/null +++ b/scripts/debug-auth.sh @@ -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 "======================================" \ No newline at end of file diff --git a/scripts/test-auth-api.sh b/scripts/test-auth-api.sh new file mode 100755 index 0000000..fb09a20 --- /dev/null +++ b/scripts/test-auth-api.sh @@ -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 "======================================" \ No newline at end of file