From 9b47588a81ddaf9fac62ea725fc3542dca301d31 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 4 Jun 2025 16:19:55 -0400 Subject: [PATCH] Reorganize tests into ./tests directory with precommit naming convention --- tests/precommit-auth.sh | 141 +++++++++++++++++++++++++++ tests/precommit.sh | 211 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 352 insertions(+) create mode 100755 tests/precommit-auth.sh create mode 100755 tests/precommit.sh diff --git a/tests/precommit-auth.sh b/tests/precommit-auth.sh new file mode 100755 index 0000000..ddf2853 --- /dev/null +++ b/tests/precommit-auth.sh @@ -0,0 +1,141 @@ +#!/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}" \ No newline at end of file diff --git a/tests/precommit.sh b/tests/precommit.sh new file mode 100755 index 0000000..d30036f --- /dev/null +++ b/tests/precommit.sh @@ -0,0 +1,211 @@ +#!/bin/bash + +# Manual test script for Authelia +# Run this to test your setup manually: ./test.sh + +set -e + +echo "๐Ÿงช Running Authelia test suite..." + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + +# Parse command line arguments +CLEANUP=true +VERBOSE=false + +for arg in "$@"; do + case $arg in + --no-cleanup) + CLEANUP=false + shift + ;; + --verbose) + VERBOSE=true + shift + ;; + *) + echo "Usage: $0 [--no-cleanup] [--verbose]" + echo " --no-cleanup: Keep containers running after tests" + echo " --verbose: Show detailed output" + exit 1 + ;; + esac +done + +# Function to log messages +log() { + if [ "$VERBOSE" = true ]; then + echo -e "${BLUE}[DEBUG]${NC} $1" + fi +} + +echo -e "${BLUE}๐Ÿš€ Starting Authelia Development Environment Tests${NC}" +echo "======================================================" + +# Step 1: Build all images +echo -e "${YELLOW}๐Ÿ“ฆ Building Docker images...${NC}" +if [ "$VERBOSE" = true ]; then + docker-compose -f docker-compose.dev.yml build +else + docker-compose -f docker-compose.dev.yml build > /dev/null 2>&1 +fi + +if [ $? -ne 0 ]; then + echo -e "${RED}โŒ Failed to build Docker images!${NC}" + exit 1 +fi +echo -e "${GREEN}โœ“ Docker images built successfully${NC}" + +# Step 2: Start services +echo -e "${YELLOW}๐Ÿƒ Starting services...${NC}" +if [ "$VERBOSE" = true ]; then + docker-compose -f docker-compose.dev.yml up -d +else + docker-compose -f docker-compose.dev.yml up -d > /dev/null 2>&1 +fi + +if [ $? -ne 0 ]; then + echo -e "${RED}โŒ Failed to start services!${NC}" + exit 1 +fi +echo -e "${GREEN}โœ“ Services started${NC}" + +# Step 3: Wait for services to be healthy +echo -e "${YELLOW}โณ Waiting for services to be ready...${NC}" +sleep 15 + +# Primary Focus: Comprehensive Authelia Testing +echo -e "${BLUE}๐Ÿ” Testing Authelia Service (Primary Focus)${NC}" +echo "==============================================" + +# Test Authelia health endpoint (most important) +echo " โ€ข Testing Authelia health endpoint..." +max_attempts=30 +attempt=0 +authelia_healthy=false +while [ $attempt -lt $max_attempts ]; do + if response=$(curl -f http://localhost:9091/api/health 2>/dev/null); then + if [ "$response" = '{"status":"OK"}' ]; then + authelia_healthy=true + break + fi + fi + attempt=$((attempt + 1)) + sleep 2 +done + +if [ "$authelia_healthy" = false ]; then + echo -e "${RED}โŒ Authelia health endpoint not responding after 60 seconds!${NC}" + echo "Authelia logs:" + docker-compose -f docker-compose.dev.yml logs authelia --tail 20 + exit 1 +fi +echo -e " ${GREEN}โœ“ Authelia health check: PASSED${NC}" + +# Test Authelia web interface +echo " โ€ข Testing Authelia web interface..." +if curl -f http://localhost:9091/ >/dev/null 2>&1; then + echo -e " ${GREEN}โœ“ Authelia Web UI: ACCESSIBLE${NC}" +else + echo -e "${RED}โŒ Authelia Web UI: NOT ACCESSIBLE${NC}" + exit 1 +fi + +# Test Authelia API endpoints +echo " โ€ข Testing Authelia API endpoints..." +if curl -f http://localhost:9091/api/configuration >/dev/null 2>&1; then + echo -e " ${GREEN}โœ“ Authelia API configuration endpoint: WORKING${NC}" +else + echo -e "${YELLOW}โš  Authelia API configuration endpoint: LIMITED ACCESS (normal)${NC}" +fi + +# Test Authelia service logs for errors +echo " โ€ข Checking Authelia service logs for errors..." +error_count=$(docker-compose -f docker-compose.dev.yml logs authelia | grep -i "error\|fatal\|panic" | grep -v "SMTP\|ntp" | wc -l) +if [ "$error_count" -eq 0 ]; then + echo -e " ${GREEN}โœ“ No critical errors in Authelia logs${NC}" +else + echo -e "${YELLOW}โš  Found $error_count potential errors in logs (excluding SMTP/NTP)${NC}" + if [ "$VERBOSE" = true ]; then + echo "Recent errors:" + docker-compose -f docker-compose.dev.yml logs authelia | grep -i "error\|fatal\|panic" | grep -v "SMTP\|ntp" | tail -5 + fi +fi + +# Test Authelia container status +echo " โ€ข Checking Authelia container status..." +container_status=$(docker inspect authelia_dev_main --format='{{.State.Status}}' 2>/dev/null || echo "not_found") +if [ "$container_status" = "running" ]; then + echo -e " ${GREEN}โœ“ Authelia container: RUNNING${NC}" +else + echo -e "${RED}โŒ Authelia container status: $container_status${NC}" + exit 1 +fi + +# Secondary: Test supporting infrastructure +echo "" +echo -e "${BLUE}๐Ÿ”ง Testing Supporting Infrastructure${NC}" +echo "=====================================" + +# Test LLDAP web interface (important for authentication) +echo " โ€ข Testing LLDAP web interface (authentication backend)..." +max_attempts=15 +attempt=0 +lldap_healthy=false +while [ $attempt -lt $max_attempts ]; do + if curl -f http://localhost:17170/health >/dev/null 2>&1; then + lldap_healthy=true + break + fi + attempt=$((attempt + 1)) + sleep 2 +done + +if [ "$lldap_healthy" = true ]; then + echo -e " ${GREEN}โœ“ LLDAP Web UI: ACCESSIBLE${NC}" +else + echo -e "${YELLOW}โš  LLDAP not accessible after 30 seconds (may affect auth)${NC}" +fi + +# Display service status +echo "" +echo -e "${BLUE}๐Ÿ“Š Service Status Overview:${NC}" +docker-compose -f docker-compose.dev.yml ps + +echo "" +if [ "$authelia_healthy" = true ]; then + echo -e "${GREEN}๐ŸŽ‰ Authelia Development Environment: FULLY FUNCTIONAL!${NC}" +else + echo -e "${RED}โŒ Authelia Development Environment: ISSUES DETECTED${NC}" + exit 1 +fi + +echo "" +echo -e "${BLUE}๐Ÿ”— Access URLs:${NC}" +echo " โ€ข Authelia: http://localhost:9091" +echo " โ€ข LLDAP Admin: http://localhost:17170" +echo " - Username: admin" +echo " - Password: /ETAToLiZPWo6QK171abAUqsa3WDpd9IgneZnTA4zU0=" +echo "" + +# Cleanup +if [ "$CLEANUP" = true ]; then + echo -e "${YELLOW}๐Ÿงน Cleaning up containers...${NC}" + if [ "$VERBOSE" = true ]; then + docker-compose -f docker-compose.dev.yml down + else + docker-compose -f docker-compose.dev.yml down > /dev/null 2>&1 + fi + echo -e "${GREEN}โœ“ Cleanup completed${NC}" +else + echo -e "${YELLOW}๐Ÿ”ง Containers left running for inspection${NC}" + echo "To stop: docker-compose -f docker-compose.dev.yml down" +fi + +echo -e "${GREEN}โœ… Authelia functionality test completed successfully!${NC}" +exit 0 \ No newline at end of file