authelia/tests/precommit-auth.sh

141 lines
4.5 KiB
Bash
Executable File

#!/bin/bash
# Authelia Authentication Test Script
# This script helps test the full authentication flow with LLDAP
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
echo -e "${BLUE}🔐 Authelia Authentication Test${NC}"
echo "========================================"
# Check if services are running
echo -e "${YELLOW}📋 Checking service status...${NC}"
if ! docker-compose -f docker-compose.dev.yml ps | grep -q "Up"; then
echo -e "${RED}❌ Services not running. Starting them now...${NC}"
docker-compose -f docker-compose.dev.yml up -d
echo "⏳ Waiting for services to start..."
sleep 20
fi
# Verify services are healthy
echo -e "${YELLOW}🔍 Verifying service health...${NC}"
# Check Authelia
if response=$(curl -s http://localhost:9091/api/health 2>/dev/null); then
if [ "$response" = '{"status":"OK"}' ]; then
echo -e " ${GREEN}✓ Authelia: HEALTHY${NC}"
else
echo -e " ${RED}❌ Authelia: UNHEALTHY${NC}"
exit 1
fi
else
echo -e " ${RED}❌ Authelia: NOT ACCESSIBLE${NC}"
exit 1
fi
# Check LLDAP
if curl -s http://localhost:17170/health >/dev/null 2>&1; then
echo -e " ${GREEN}✓ LLDAP: ACCESSIBLE${NC}"
else
echo -e " ${RED}❌ LLDAP: NOT ACCESSIBLE${NC}"
exit 1
fi
echo ""
echo -e "${CYAN}🌐 Authentication Testing URLs:${NC}"
echo "=================================="
echo -e " ${BLUE}• Authelia Login:${NC} http://localhost:9091"
echo -e " ${BLUE}• LLDAP Admin Panel:${NC} http://localhost:17170"
echo ""
echo -e "${CYAN}🔑 LLDAP Admin Credentials:${NC}"
echo "============================="
echo -e " ${BLUE}Username:${NC} admin"
echo -e " ${BLUE}Password:${NC} /ETAToLiZPWo6QK171abAUqsa3WDpd9IgneZnTA4zU0="
echo ""
echo -e "${YELLOW}📝 Manual Testing Instructions:${NC}"
echo "==============================="
echo ""
echo -e "${BLUE}Step 1: Create a Test User in LLDAP${NC}"
echo " 1. Open http://localhost:17170 in your browser"
echo " 2. Login with admin credentials above"
echo " 3. Go to 'Users' section"
echo " 4. Click 'Create User'"
echo " 5. Fill in details:"
echo " - Username: testuser"
echo " - Email: testuser@nixc.us"
echo " - Display Name: Test User"
echo " - Password: password123"
echo " 6. Click 'Create'"
echo ""
echo -e "${BLUE}Step 2: Add User to Groups (Optional)${NC}"
echo " 1. In LLDAP, go to 'Groups' section"
echo " 2. Create a group (e.g., 'dev') if needed"
echo " 3. Add the test user to appropriate groups"
echo ""
echo -e "${BLUE}Step 3: Test Authelia Authentication${NC}"
echo " 1. Open http://localhost:9091 in your browser"
echo " 2. You should see the Authelia login page"
echo " 3. Login with your test user credentials:"
echo " - Username: testuser"
echo " - Password: password123"
echo " 4. If successful, you should see the Authelia portal"
echo ""
echo -e "${YELLOW}🧪 Automated Basic Tests:${NC}"
echo "========================="
# Test 1: Check if Authelia login page loads
echo -n " • Testing Authelia login page... "
if curl -s http://localhost:9091/ | grep -q "Authelia"; then
echo -e "${GREEN}✓ PASS${NC}"
else
echo -e "${RED}❌ FAIL${NC}"
fi
# Test 2: Check LDAP connection via Authelia logs
echo -n " • Testing LDAP connection... "
if docker-compose -f docker-compose.dev.yml logs authelia 2>/dev/null | grep -q "LDAP Supported OIDs"; then
echo -e "${GREEN}✓ PASS (LDAP connection established)${NC}"
else
echo -e "${YELLOW}⚠ WARNING (Check logs for LDAP connection issues)${NC}"
fi
# Test 3: Test configuration endpoint (may require auth)
echo -n " • Testing API endpoints... "
if curl -s http://localhost:9091/api/configuration >/dev/null 2>&1; then
echo -e "${GREEN}✓ PASS${NC}"
else
echo -e "${YELLOW}⚠ RESTRICTED (Expected - requires authentication)${NC}"
fi
echo ""
echo -e "${GREEN}🎉 Basic Tests Complete!${NC}"
echo ""
echo -e "${CYAN}📊 Current Container Status:${NC}"
echo "============================="
docker-compose -f docker-compose.dev.yml ps
echo ""
echo -e "${BLUE}💡 Tips:${NC}"
echo "======="
echo "• If login fails, check LLDAP user exists and password is correct"
echo "• Check Authelia ACL rules in docker/authelia/config/configuration.acl.yml"
echo "• Use 'docker-compose -f docker-compose.dev.yml logs authelia' for debugging"
echo "• LLDAP users need to be in the correct Base DN: dc=nixc,dc=us"
echo ""
echo -e "${GREEN}✅ Authentication testing environment ready!${NC}"
echo -e "${YELLOW}💡 Open the URLs above in your browser to test manually${NC}"